DSP论坛
直播中

subaru

未满1年用户 8经验值
擅长:电源/新能源 嵌入式技术 处理器/DSP 接口/总线/驱动 控制/MCU
私信 关注

DSP28335移植官方IIC库读写EEPROM遇到问题

配置如下:
void I2CA_Init(void)
{
InitI2CGpio();
// Initialize I2C
I2caRegs.I2CSAR = 0x0050; // Slave address - EEPROM control code

#if (CPU_FRQ_150MHZ) // Default - For 150MHz SYSCLKOUT
I2caRegs.I2CPSC.all = 14; // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)
#endif
#if (CPU_FRQ_100MHZ) // For 100 MHz SYSCLKOUT
I2caRegs.I2CPSC.all = 9; // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)
#endif

I2caRegs.I2CCLKL = 10; // NOTE: must be non zero
I2caRegs.I2CCLKH = 5; // NOTE: must be non zero
//I2caRegs.I2CIER.all = 0x24;

I2caRegs.I2CMDR.all = 0x0020;

I2caRegs.I2CFFTX.all = 0x6000;
I2caRegs.I2CFFRX.all = 0x2040;

return;
}

Uint16 I2CA_WriteData(struct I2CMSG *msg)
{
Uint16 i;

if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}

I2caRegs.I2CCNT = msg->NumOfBytes+2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;

for (i=0; iNumOfBytes; i++)
{
I2caRegs.I2CDXR = *(msg->MsgBuffer+i);
}

I2caRegs.I2CMDR.all = 0x6E20;

return I2C_SUCCESS;
}

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
Uint16 i;

if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620;

I2caRegs.I2CCNT = msg->NumOfBytes;
I2caRegs.I2CMDR.all = 0x2C20;

for(i=0; i < msg->NumOfBytes; i++)
{
msg->MsgBuffer[i] = I2caRegs.I2CDRR;
}

return I2C_SUCCESS;
}

main函数如下(去掉多余部分):

I2cMsgOut1.MemoryHighAddr = 0x00;
I2cMsgOut1.MemoryLowAddr = 0x00;
I2cMsgOut1.NumOfBytes = 8;
I2cMsgOut1.MsgBuffer[0] = 0x11;
I2cMsgOut1.MsgBuffer[1] = 0x22;
I2cMsgOut1.MsgBuffer[2] = 0x33;
I2cMsgOut1.MsgBuffer[3] = 0x44;
I2cMsgOut1.MsgBuffer[4] = 0x55;
I2cMsgOut1.MsgBuffer[5] = 0x66;
I2cMsgOut1.MsgBuffer[6] = 0x77;
I2cMsgOut1.MsgBuffer[7] = 0x88;

for(;;) //infinite loop
{
I2CA_WriteData(&I2cMsgOut1);
DELAY_US(1);
}

具体现象使用逻辑分析仪抓取如下:
image.png

image.png

image.png

image.png

求大神解答!
搞了一整天了,累了,老老实实用软件模拟了...

回帖(1)

周璞

2024-8-2 16:19:58
软件模拟能读写的话,只能是官方库移植有问题,重点检查初始化配置
举报

更多回帖

发帖
×
20
完善资料,
赚取积分