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.

TM4c129 I2C 有bug?!

Hi 大神们!

我故意把从机地址(salve_7bit_addr这个参数值)写错误,i2c_read_from_word_address()函数竟然返回0(正确),I2CMasterErr()不能返回从机无应答的状态位吗?!我开始怀疑TM4c129 I2C 有bug!

//初始部分代码

// 使能I2C模块及对应控制引脚端口
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C2);
// 配置相应控制端口
GPIOPinConfigure(GPIO_PN4_I2C2SDA);
GPIOPinConfigure(GPIO_PN5_I2C2SCL);
GPIOPinTypeI2CSCL(GPIO_PORTN_BASE, GPIO_PIN_5);
GPIOPinTypeI2C(GPIO_PORTN_BASE, GPIO_PIN_4);

I2CMasterInitExpClk(TEST_I2C_BASE, ui32SysClock, false);

//-------读函数--------------

static uint8_t i2c_read_from_word_address(uint32_t i2c_base,uint8_t salve_7bit_addr, uint8_t word_address,uint8_t count, uint8_t *data)
{
uint8_t i;
uint8_t rop;

//指定从设备地址
I2CMasterSlaveAddrSet(i2c_base, salve_7bit_addr, 0);
// udelay(1000);
while(I2CMasterBusBusy(i2c_base));

//发送寄存器地址

I2CMasterDataPut(i2c_base, word_address);
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(i2c_base)){SysCtlDelay(10000);};
rop = I2CMasterErr(i2c_base);
if(rop != 0)
{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_SEND_STOP);
return rop;
}
SysCtlDelay(10000);
I2CMasterSlaveAddrSet(i2c_base, salve_7bit_addr, 1);
if(count == 1)
{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_SINGLE_RECEIVE);

//读数据
while(I2CMasterBusy(i2c_base)){SysCtlDelay(10000);};
rop = I2CMasterErr(i2c_base);
if(rop != 0)
{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP);
return rop;
}
data[0] = (uint8_t)I2CMasterDataGet(i2c_base);
}
else if(count > 1)
{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(i2c_base)){SysCtlDelay(10000);};
rop = I2CMasterErr(i2c_base);
if(rop != 0)
{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP);
return rop;
}
data[0] = (uint8_t)I2CMasterDataGet(i2c_base);
for(i=1; i<count; i++)
{
if(i == (count-1)){
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
}else{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_RECEIVE_CONT);
}

//读数据
while(I2CMasterBusy(i2c_base)){SysCtlDelay(10000);};
rop = I2CMasterErr(i2c_base);
if(rop != 0)
{
I2CMasterControl(i2c_base,I2C_MASTER_CMD_BURST_RECEIVE_ERROR_STOP);
return rop;
}
data[i] = (uint8_t)I2CMasterDataGet(i2c_base);

SysCtlDelay(1000000);
}
}

//完成传输前等待
while(I2CMasterBusy(i2c_base)){SysCtlDelay(10000);}
rop = I2CMasterErr(i2c_base);

return rop;
}