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.