Nand-flash AM29f040

Software e Hardware para ATMEL

Moderadores: 51, guest2003, brasilma

Nand-flash AM29f040

Mensagempor Alirio926 » 08 Ago 2013 21:40

Boa noite!

Estou tentando ler e gravar um chip AM29F040 sem sucesso a algum tempo com arduino e ontem acabei por comprar uma plataforma STM32F4 para começar com 32b ^^.
Enquanto não chega continuo tentando ler a memoria flash ainda sem sucesso.
Bem, sei que o arduino e suas routinas ( digitalWrite ) são bem demoradas de executar, será esse meu problema,.. segue abaixo trecho do código, agradeço muito quem poder dar uma mãozinha. Pretendo apos ler, remover os digitalWrite por acesso direto a porta.:
Código: Selecionar todos
unsigned int adr[] = {47,48,49,50,52,35,34,33,24,23,37,22,32,25,26,31,30,27,29};
unsigned int dat[] = {46,45,44,43,42,41,40,39};
unsigned int WE = 28;
unsigned int CE = 37;
unsigned int OE = 36;


Código: Selecionar todos
int FLASH::FlashProgram( unsigned long ulOff, unsigned long NumBytes, void *Array )
{
   unsigned char *ucArrayPointer; /* Use an unsigned char to access the array */
   unsigned long LastOff; /* Holds the last offset to be programmed */
   /* Step 1: Check for correct flash type */
   if( !(FlashAutoSelect( FLASH_READ_MANUFACTURER ) == MANUFACTURER_ST)
   || !(FlashAutoSelect( FLASH_READ_DEVICE_CODE ) == EXPECTED_DEVICE ) )
      return FLASH_WRONG_TYPE;
   /* Step 2: Check the offset and range are valid */
   LastOff = ulOff+NumBytes-1;
   if( LastOff >= FLASH_SIZE )
      return FLASH_ADDRESS_OUT_OF_RANGE;
   /* Step 3: While there is more to be programmed */
   ucArrayPointer = (unsigned char *)Array;
   while( ulOff <= LastOff )
   {
      /* Step 4: Program the next byte */
      FlashWrite( 0x5555L, 0xAA ); /* 1st cycle */
      FlashWrite( 0x2AAAL, 0x55 ); /* 2nd cycle */
      FlashWrite( 0x5555L, 0xA0 ); /* Program command */
      FlashWrite( ulOff, *ucArrayPointer ); /* Program value */
      /* Step 5: Perform data polling until P/E.C. has completed. */
      /* See Data Polling Flowchart of the Data Sheet */
      if( FlashDataPoll( ulOff, *ucArrayPointer ) == FLASH_POLL_FAIL )
      {
         FlashReadReset();
         return FLASH_PROGRAM_FAIL;
      }
      /* Step 6: Update pointers */
      ulOff++;
      ucArrayPointer++;
      /* Step 7: End while loop */
   }
   /* Step 8: Return to Read Array mode */
   FlashWrite( 0x0000L, 0xF0 ); /* Use single instruction cycle method */
   return FLASH_SUCCESS;
}


Código: Selecionar todos
unsigned char FLASH::FlashRead( unsigned long ulOff )
{
   for(char a = 0; a < 8; a++)
   {
      pinMode(dat[a],INPUT);
   }
   unsigned char ret;
   digitalWrite(WE,HIGH);
   digitalWrite(CE,HIGH);
   digitalWrite(OE,LOW);
   for(unsigned long ad = 0; ad < 19; ad++)
   {
      if(bitRead(ulOff,ad))
         digitalWrite(adr[ad],HIGH);
      else
         digitalWrite(adr[ad],LOW);     
   }   
   digitalWrite(WE,LOW);
   digitalWrite(CE,LOW);
   bitWrite(ret,0,digitalRead(46));
   bitWrite(ret,1,digitalRead(45));
   bitWrite(ret,2,digitalRead(44));
   bitWrite(ret,3,digitalRead(43));
   bitWrite(ret,4,digitalRead(42));
   bitWrite(ret,5,digitalRead(41));
   bitWrite(ret,6,digitalRead(40));
   bitWrite(ret,7,digitalRead(39)); 
   digitalWrite(CE,HIGH);
   digitalWrite(WE,HIGH);
   return ret;
}


Código: Selecionar todos
void FlashWrite( unsigned long ulOff, unsigned char ucVal )
{
   digitalWrite(CE,HIGH);
   digitalWrite(WE,HIGH);   
   for(char a = 0; a < 8; a++)
   {
      pinMode(dat[a],OUTPUT);
   }   
   for(unsigned long ad = 0; ad < 19; ad++) // cycle #01
   {
      if(bitRead(ulOff,ad))
         digitalWrite(adr[ad],HIGH);
      else
         digitalWrite(adr[ad],LOW);     
   }   
   digitalWrite(WE,LOW);
   digitalWrite(CE,LOW);
   for(unsigned long ad = 0; ad < 8; ad++)
   {
      if(bitRead(ucVal,ad))
         digitalWrite(dat[ad],HIGH);
      else
         digitalWrite(dat[ad],LOW);     
   } 
   digitalWrite(CE,HIGH);
   digitalWrite(WE,HIGH);      
}


Não sei se removendo o digitalWrite resolve ou se tem algo errado com o código. O cod acima não consegue ler nem o ID.
Alirio926
Bit
 
Mensagens: 23
Registrado em: 23 Dez 2009 21:02

Re: Nand-flash AM29f040

Mensagempor Alirio926 » 09 Ago 2013 22:06

Boa noite!
Melhorei um pouco o codigo mas ainda não funciona:
Grava
Código: Selecionar todos
void FlashWrite( unsigned long ulOff, unsigned char ucVal )
{
   DDRL = 0b11111111;   // DATA OUT
   PORTL = 0b00000000; // DATA OUT
   DDRG = 0b11111111;   // DATA OUT
   PORTG = 0b00000000;   // DATA OUT
   DDRA = (1<<WE);
   PORTA |= (1<<WE); // WE HIGH
   DDRC = (1<<CE) | (1<<OE);
   PORTC |= (1<<CE) | (1<<OE); // CE E OE HIGH
   
   for(unsigned long ad = 0; ad < 19; ad++) // cycle #01
   {
      if((ulOff & ad) == 1)
         digitalWrite(adr[ad],HIGH);
      else
         digitalWrite(adr[ad],LOW);     
   }   
      
   PORTA &= ~(1<<WE); // WE LOW
   PORTC &= ~(1<<CE); // CE LOW
   
   //L3,L4,L5,L6,L7,G0,G1,G2
   PORTL |= ucVal & 0xF8/*0b11111000*/;
   PORTG |= ucVal & 0x7/*0b00000111*/;
   
   PORTC |= (1<<CE); // CE HIGH
   PORTA |= (1<<WE); // WE HIGH   
}


Código: Selecionar todos
unsigned char FlashRead( unsigned long ulOff )
{
//ADDRESS   L2,L1,L0,B3,B1,C2,C3,C4,A2,A1,C0,A0,C5,A3,A4,C6,C7,A5,A7
//DATA      L3,L4,L5,L6,L7,G0,G1,G2
//PA6      WE
//PC0      CE
//PC1      OE
   DDRL = 0b00000111;   // DATA IN
   PORTL = 0b00000000; // DATA IN
   DDRG = 0b00000000;   // DATA IN
   PORTG = 0b00000000;   // DATA IN
   DDRA = (1<<WE);
   PORTA |= (1<<WE);   // WE HIGH
   DDRC = (1<<CE) | (1<<OE);
   
   PORTC |= (1<<CE) | (1<<OE); // CE E OE HIGH
   PORTC &= ~((1<<CE) | (1<<OE)); // CE E OE LOW
   for(unsigned long ad = 0; ad < 19; ad++)
   {
      if((ulOff & ad) == 1)
         digitalWrite(adr[ad],HIGH);
      else
         digitalWrite(adr[ad],LOW);     
   }   
   unsigned char ret;
   ret = (PINL & 0b11111000) | (PING & 0b00000111);
   
   PORTC |= (1<<CE) | (1<<OE); // CE E OE HIGH
   return ret;
}

Obs.: defino os pinos de endereço como saida em outra parte do programa.

Arduino Mega 2560
Alguem pode me ajudar com esse chip AM28F040 e meu codigo.
Alirio926
Bit
 
Mensagens: 23
Registrado em: 23 Dez 2009 21:02


Voltar para AVR

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x