我正在尝试将 M95M02-DR 256KB EEPROM 存储芯片与 MSP430 微控制器连接。作为示例测试,我尝试将以下字符串写入其中:
第一章 兔子洞。爱丽丝开始厌倦在岸边坐在姐姐身边,
当我尝试从芯片读回数据时,我得到的是:
第一章 兔子洞。爱丽丝开始厌倦了坐在她姐姐的旁边??????
? 是垃圾数据。问题是,如果我将字符串的大小减少几个字符,那么就没有问题。以前我曾尝试从 SD 卡上的文件中读取数据并以 256 字节块写入 EEPROM 芯片。在那种情况下什么都没有写。但是当我逐字节执行相同的操作时,就没有问题了。
这是我正在使用的代码
static uint32_t i=0x025698;
static unsigned char message[120] = "CHAPTER I. Down the Rabbit-Hole."\
"Alice was beginning to get very tired of sitting by her sister on the bank, ";
static int size ;
unsigned char input[120];
size = strlen(message);
eeprom_spi_init();
eeprom_write( i ,message,size);
__delay_cycles(2500);
eeprom_read( i, input,size);
input[size]='\0';
ax_log_msg(E_LOG_INFO,input); //print command
低级 SPI 功能如下:
void eeprom_write(uint32_t ui_addr, uint8_t *puc_wrData, uint8_t ui_dataLen)
{
uint8_t uac_wrBuf[260] = {0x00,};
uint8_t i = 0;
EEPROM_wrEnable();
uac_wrBuf[i++] = WRITE; /* Write Instruction */
uac_wrBuf[i++] = (uint8_t)((ui_addr >> 16) & 0xFF); /* First 8-bit MSB of 24-bit address */
uac_wrBuf[i++] = (uint8_t)((ui_addr >> 8) & 0xFF); /* Second 8-bit MSB of 24-bit address */
uac_wrBuf[i++] = (uint8_t)((ui_addr) & 0xFF); /* Third 8-bit MSB of 24-bit address */
while(ui_dataLen--) {
uac_wrBuf[i++] = *puc_wrData++;
}
uac_wrBuf[i++] = 0xFF;
EEPROM_ON();
EEPROM_sendFrame(uac_wrBuf, i);
EEPROM_OFF();
__delay_cycles(250000);
}
void eeprom_read(uint32_t ui_addr, uint8_t *puc_wrData, uint8_t ui_dataLen)
{
uint8_t uac_rdBuf[260] = {0x00,};
uint8_t uac_rdCmd[4];
uint8_t i = 0;
uac_rdCmd[i++] = READ;
uac_rdCmd[i++] = (uint8_t)((ui_addr >> 16) & 0xFF); /* First 8-bit MSB of 24-bit address */
uac_rdCmd[i++] = (uint8_t)((ui_addr >> 8) & 0xFF); /* Second 8-bit MSB of 24-bit address */
uac_rdCmd[i++] = (uint8_t)((ui_addr) & 0xFF); /* Third 8-bit MSB of 24-bit address */
EEPROM_ON();
EEPROM_sendFrame(uac_rdCmd, i);
EEPROM_readFrame(puc_wrData, ui_dataLen);
EEPROM_OFF();
}
和工作正常EEPROM_sendFrame
,EEPROM_readFrame
因为我也将它们用于 SD 卡。
任何帮助将不胜感激。如果有什么我忘记提及的信息,请告诉我,我会补充的。
谢谢