This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
赫尔洛
你好。
a、 Atmel (AT24c04)或 Microchip (93C46)需要哪种类型的 EEPROM?
此致
Dave
您好、Dave、
您需要编辑示例程序。 我建议查看 AT24C08数据表、因为它的读取/写入协议与24WC256略有不同。
当为24WC256设置读取/写入时、您在实际发送或接收数据之前发送两个8位地址字(高地址和低地址):
// //设置要发送 MsgBuffer + Address 的字节数 // I2caRegs.I2CCNT = msg->NumOfBytes+2; // //设置要发送的数据 // I2caRegs.I2CDXR = msg->MemoryHighAddr; I2caRegs.I2CDXR = msg->MemoryLowAddr; 对于(i=0;i NumOfBytes;i++) { I2caRegs.I2CDXR =*(msg->MsgBuffer+I); }
对于 AT24C08、如果查看其数据表、读取/写入仅使用一个8位地址字、而不是两个地址字。 可能还有其他一些注意事项、这正是我在 DS 中注意到的。
最棒的
Kevin
尊敬的 Kevin、感谢您的建议。
最后、我可以通过移除来向 EEPROM 写入和读取2字节数据
MemoryHighAddr 格式 I2CA_WriteData (struct I2CMSG *msg)和 UINT16 I2CA_ReadData (struct I2CMSG *msg)函数并更改 I2caRegs.I2CCNT 寄存器。
对于 I2CA_WriteData 函数 I2caRegs.I2CCNT 寄存器等于3 (1个地址、2个数据);对于 I2CA_ReadData 函数 I2caRegs.I2CCNT 寄存器等于1 (1个地址)。
所以,现在我需要将25个字存储到 EEPROM 中,并读取它们,所以为了继续工作,我删除了用于(;.)的传递和失败函数。
始终在主循环中进行编程。
void pass () { // asm (" ESTOP0"); // for (;;); } void fail () { // asm (" ESTOP0"); // for (;); }
还用于存储我写的25个字
//cnt 初始化 cnt=0 CNT++; I2cMsgOut1.MsgBuffer[0]= cnt; CNT++; I2cMsgOut1.MsgBuffer[1]=cnt; //ADR 初始化 ADRs=0 ADRs++; I2cMsgOut1.MemoryLowAddr = ADC;
if (ADRs=25){for (;);} CurrentMsgPtr =&I2cMsgOut1; I2cMsgOut1.MsgStatus = I2C_MSGSTAT_SEND_WITHSTOP;
因此、通过这样做、我们希望存储25个字
但遗憾的是、没有存储任何数据。
我感到困惑,请帮助我解决我的问题,
// (;) {.的应用程序循环 //对每次写入/读取进行延迟 for (j=0;j<10000;j++) I2cMsgOut1.MsgStatus=I2C_MSGSTAT_SEND_WITHSTOP; I2cMsgOut1.SlaveAddress=I2C_SLAVE_ADDR; I2cMsgOut1.NumOfBytes=I2C_NUMBYTES; I2cMsgOut1.MemoryHighAddr=I2C_EEPROM_HIGH_ADDR; CNT++; I2cMsgOut1.MsgBuffer[0]= cnt; CNT++; I2cMsgOut1.MsgBuffer[1]=cnt; ADRs++; I2cMsgOut1.MemoryLowAddr = ADC; CurrentMsgPtr =&I2cMsgOut1; I2cMsgOut1.MsgStatus = I2C_MSGSTAT_SEND_WITHSTOP; ////////////////////////////////////////////////////////////////////// //将数据写入 EEPROM 部分// ////////////////////////////////////////////////////////////////////// //检查外发消息是否应发送。 //在本例中,初始化后发送一个停止位。 if (I2cMsgOut1.MsgStatus = I2C_MSGSTAT_SEND_WITHSTOP) { 错误= I2CA_WriteData (&I2cMsgOut1); //如果通信已正确启动,请将 msg 状态设置为忙 //并更新中断服务例程的 CurrentMsgPtr。 //否则,不执行任何操作,然后重试下一个循环。 发送一条消息 //启动后、I2C 中断将处理其余中断。 搜索 // i2c_EEPROM_ISR.c 文件中的 ICINTR1A_ISR。 如果(错误= I2C_Success) { CurrentMsgPtr =&I2cMsgOut1; I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY; } }//写入段结束 //每次写入/读取时产生延迟 (j=0;j<100000;j++){} I2cMsgIn1.MsgStatus=I2C_MSGSTAT_SEND_NOSTOP; I2cMsgIn1.SlaveAddress=I2C_SLAVE_ADDR; I2cMsgIn1.NumOfBytes=I2C_NUMBYTES; I2cMsgIn1.MemoryHighAddr=I2C_EEPROM_HIGH_ADDR; //它将从 EEPROM 读取以前的数据 I2cMsgIn1.MemoryLowAddr = ADRs-1; //////////////////////////////////////////////////////////////////////// //从 EEPROM 部分读取数据// //////////////////////////////////////////////////////////////////////// //检查外发消息状态。 如果状态为、则绕过读取段 //未处于非活动状态。 IF (I2cMsgOut1.MsgStatus = I2C_MSGSTAT_INACTIVE) { //检查传入消息状态。 if (I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP) { // EEPROM 地址设置部分 while (I2CA_ReadData (&I2cMsgIn1)!= I2C_Success) { //可以设置一个尝试计数器来打破无限 while //循环。 EEPROM 将在执行时发回一个 NACK //写入操作。 即使是写公报 //完成此时,EEPROM 仍可能处于忙状态 //对数据进行编程。 因此、会多次尝试 //必需。 } //更新当前消息指针和消息状态 CurrentMsgPtr =&I2cMsgIn1; I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY; } //一旦消息经过设置内部地址的过程 //在 EEPROM 中、发送重新启动以从读取数据字节 // EEPROM。 完成公报并停留一会。 MsgStatus 为 //在中断服务例程中更新。 否则、IF (I2cMsgIn1.MsgStatus = I2C_MSGSTAT_RESTART) { //读取数据部分 while (I2CA_ReadData (&I2cMsgIn1)!= I2C_Success) { //可以设置一个尝试计数器来打破无限 while //循环 。} //更新当前消息指针和消息状态 CurrentMsgPtr =&I2cMsgIn1; I2cMsgIn1.MsgStatus = I2C_MSGSTAT_READ_BUSY; } }//读取段的末尾 }// for (;)} // main 的末尾
我需要将25个字存储到 EEPROM 中,然后读取这些字, 我真的需要您的帮助来解决我的问题。
此致。
Dave。
亲爱的 Kevin、谢谢
我将看到 e2e.ti.com/.../2627724
然后,我将告诉您我的问题是否得到解决。
此致
Dave。