EstoyusandoelsiguienteeepromFM25CL64
Intento escribir datos, leer datos mediante sondeo, pero permanece en un bucle infinito y el registro de estado siempre es 0, y es por eso que permanezco en un bucle infinito cuando leo el registro.
aquí está mi controlador y aquí es cómo lo uso
// extract a low byte from a 2 byte word.
#define Lo(X) (unsigned char)(X&0x00ff)
// extract a high byte from a 2 byte word.
#define Hi(X) (unsigned char)((X>>8)&0x00ff)
#define SPI_EEPROM_SELECT 0xFBFF /* select EEPROM value */
#define SPI_EEPROM_DESELECT 0x0400 /* deselect EEPROM value */
#define EEPROM_CMD_WRSR 0x01 /* Write Status Register */
#define EEPROM_CMD_WRITE 0x02 /* Write Memory Data */
#define EEPROM_CMD_READ 0x03 /* Read Memory Data */
#define EEPROM_CMD_WRDI 0x04 /* Write Disable */
#define EEPROM_CMD_RDSR 0x05 /* Read Status Register */
#define EEPROM_CMD_WREN 0x06 /* Set Write Enable Latch */
struct STATREG{
unsigned WIP:1;
unsigned WEL:1;
unsigned BP0:1;
unsigned BP1:1;
unsigned RESERVED:3;
unsigned WPEN:1;
};
union _EEPROMStatus_{
struct STATREG Bits;
unsigned char Char;
};
Lo estoy usando con blackfin 533
void spi_eeprom_select_new(void) /* select EEPROM */
{
*pSPI_FLG = (*pSPI_FLG & SPI_EEPROM_SELECT );
ssync();
}
void spi_eeprom_deselect_new(void) /* deselect EEPROM */
{
*pSPI_FLG = (*pSPI_FLG | SPI_EEPROM_DESELECT);
ssync();
}
///////////////////////////////////////////////////////////////////////
unsigned char spi_trans_byte_bw_new(const unsigned char tx)
{
*pSPI_TDBR = tx;
int i;
while ((*pSPI_STAT & 0x0001) == 0) ;
for( i = 0 ; i < 100; i++)
{
}
unsigned char d = *pSPI_RDBR;
return d;
}
// enable writeing to EEPROM
void EEPROMWriteEnable(void)
{
unsigned char Local_8;
spi_eeprom_select_new();
Local_8 = spi_trans_byte_bw_new(EEPROM_CMD_WREN);
spi_eeprom_deselect_new();
}
void EEPROMWriteDisable(void)
{
unsigned char Local_8;
spi_eeprom_select_new();
Local_8 = spi_trans_byte_bw_new(EEPROM_CMD_WRDI);
spi_eeprom_deselect_new();
}
// read status register
union _EEPROMStatus_ FM33256readStatus(void)
{
unsigned char Local_8;
spi_eeprom_select_new();
Local_8 = spi_trans_byte_bw_new(EEPROM_CMD_RDSR);
Local_8 = spi_trans_byte_bw_new(0);
spi_eeprom_deselect_new();
//printf("status %x\n", Local_8);
return (union _EEPROMStatus_)Local_8;
}
// write a byte to address (16 bits)
void FM33256write8(unsigned char Data, unsigned int Address)
{
unsigned char Local_8;
EEPROMWriteEnable();
spi_eeprom_select_new();
Local_8 = spi_trans_byte_bw_new(EEPROM_CMD_WRITE);
Local_8 = spi_trans_byte_bw_new(Hi(Address));
Local_8 = spi_trans_byte_bw_new(Lo(Address));
Local_8 = spi_trans_byte_bw_new(Data);
spi_eeprom_deselect_new();
// wait for completion of previous write operation
while(FM33256readStatus().Bits.WIP); // it fails here
spi_eeprom_deselect_new();
}
// read a byte from address (16 bit)
unsigned char FM33256read8(unsigned int Address)
{
unsigned char Local_8;
spi_eeprom_select_new();
Local_8 = spi_trans_byte_bw_new(EEPROM_CMD_READ);
Local_8 = spi_trans_byte_bw_new(Hi(Address));
Local_8 = spi_trans_byte_bw_new(Lo(Address));
Local_8 = spi_trans_byte_bw_new(0);
spi_eeprom_deselect_new();
return Local_8;
}
aquí es cómo lo uso
unsigned char data = FM33256read8(15);
FM33256write8(10,15);