您好、TI!
我必须对旧版产品进行一些小的更新。 遗憾的是、我无法访问其中的 JTAG 端口、并且只能使用引导加载程序更新固件。 无调试。
该器件会与整个基于 I2C 的不同传感器通信、并且大部分情况下运行良好。 唯一的问题是、如果从 I2C 器件没有响应(缺失、损坏等)、TM4C 会锁定在 I2CSend 例程中的某个位置。
熟悉外设库的人能否建议我可以向此代码添加哪些内容来处理缺少的/无响应的 I2C 从器件?
非常感谢!
P.S.我实际上发布了一个类似的问题,关于这个确切的问题几年前,从来没有真正想出一个完整的修复. 早在那时、我们就有这个器件的开发版本(具有 JTAG 访问权限)、但多年来它们一直被弃用、因此这就变得更加困难了。
uint32_t I2C3Send(uint8_t slave_addr, uint8_t num_of_args, ...)
{
uint8_t i;
// Tell the master module what address it will place on the bus when
// communicating with the slave.
I2CMasterSlaveAddrSet(I2C3_BASE, slave_addr, false);
//stores list of variable number of arguments
va_list vargs;
//specifies the va_list to "open" and the last fixed argument
//so vargs knows where to start looking
va_start(vargs, num_of_args);
//put data to be sent into FIFO
I2CMasterDataPut(I2C3_BASE, va_arg(vargs, uint32_t));
//if there is only one argument, we only need to use the
//single send I2C function
if(num_of_args == 1)
{
//Initiate send of data from the MCU
I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_SINGLE_SEND);
// Wait until MCU is done transferring.
while(!I2CMasterBusy(I2C3_BASE));
while(I2CMasterBusy(I2C3_BASE));
if(I2CMasterErr(I2C3_BASE)) return 0;
//"close" variable argument list
va_end(vargs);
}
//otherwise, we start transmission of multiple bytes on the
//I2C bus
else
{
//Initiate send of data from the MCU
I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_START);
// Wait until MCU is done transferring.
while(!I2CMasterBusy(I2C3_BASE));
while(I2CMasterBusy(I2C3_BASE));
if(I2CMasterErr(I2C3_BASE)) return 0;
//send num_of_args-2 pieces of data, using the
//BURST_SEND_CONT command of the I2C module
for(i = 1; i < (num_of_args - 1); i++)
{
//put next piece of data into I2C FIFO
I2CMasterDataPut(I2C3_BASE, va_arg(vargs, uint32_t));
//send next data that was just placed into FIFO
I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_CONT);
// Wait until MCU is done transferring.
while(!I2CMasterBusy(I2C3_BASE));
while(I2CMasterBusy(I2C3_BASE));
if(I2CMasterErr(I2C3_BASE)) return 0;
}
//put last piece of data into I2C FIFO
I2CMasterDataPut(I2C3_BASE, va_arg(vargs, uint32_t));
//send next data that was just placed into FIFO
I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
// Wait until MCU is done transferring.
while(!I2CMasterBusy(I2C3_BASE));
while(I2CMasterBusy(I2C3_BASE));
if(I2CMasterErr(I2C3_BASE)) return 0;
//"close" variable args list
va_end(vargs);
}
return 1;
}
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3); SysCtlPeripheralReset(SYSCTL_PERIPH_I2C3); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOR); GPIOPinConfigure(GPIO_PK4_I2C3SCL); GPIOPinConfigure(GPIO_PR5_I2C3SDA); GPIOPinTypeI2CSCL(GPIO_PORTK_BASE, GPIO_PIN_4); GPIOPinTypeI2C(GPIO_PORTR_BASE, GPIO_PIN_5); I2CMasterInitExpClk(I2C3_BASE, SysCtlClockGet(), true); //False = 100kbs, True = 400kbs HWREG(I2C3_BASE + I2C_O_FIFOCTL) = 80008000;

