大家好
我想在 TMS320F28379D 上实现一个通过 I2C 连接到 Infineon 的3D 磁性霍尔传感器 TLI493D-W2BW A0的接口、但我面临的问题是传感器从未在 I2C 总线上使用 ACK 进行应答。 我认为问题是传感器以某种方式需要8位地址、但我不确定如何使用 TMS320F28379D 生成8位地址波形。 该传感器的写入地址为0x6A、下图给出了要写入传感器的示例波形(请注意8位地址)。

我的代码生成以下波形(示波器上显示了 SDA):

可以看出、0x6A 地址的"前导零"似乎没有生成(在第一个上升沿、如果 SCLK、SDA 为高电平而不是低电平、这应该是根据第一幅图片中的基准波形来生成的)。
我使用以下函数执行 I2C 写入:
/*! \brief Function Header: (uint8_t addr, const uint8_t* data, uint8_t count)
*
* I2C write command must have a header precisely of type:
* (uint8_t addr, const uint8_t* data, uint8_t count), where:
* \param addr Is the I2C address to read from data is the;
* \param data is the array that the function will read to
* \param count is the number of bytes the function will read
*
* \code{.c}
* // =============== EXAMPLE ================
* uint8_t payload[] = {5, 1, 2, 3};
* // write 4 bytes from payload to the I2C device with address 0x23
* error = _I2C_write(0x23, payload, 4);
* \endcode
* */
inline uint8_t w2bw_i2c_write(uint8_t addr,const uint8_t* data,uint8_t count){
//push the data to the I2C TX FIFO
uint8_t i=0;
for(i=0; i<count; i++){
I2C_putData(I2C0_W2BW_BASE,data[i]);
}
//set the I2C slave address to the write address
I2C_setSlaveAddress(I2C0_W2BW_BASE,0x6A);
//set the number of bytes to be sent
I2C_setDataCount(I2C0_W2BW_BASE, count);
//set the I2C mode to master
I2C_setConfig(I2C0_W2BW_BASE, I2C_MASTER_SEND_MODE);
//send the start condition
I2C_sendStartCondition(I2C0_W2BW_BASE);
//send the stop condition
I2C_sendStopCondition(I2C0_W2BW_BASE);
//wait until TX FIFO is empty
while(I2C_getTxFIFOStatus(I2C0_W2BW_BASE)!=I2C_FIFO_TXEMPTY){
;
}
return 0;
}
和以下用于初始化 I2C 模块的函数:
void I2Cinit(){
I2C_disableModule(I2C0_W2BW_BASE);
I2C_initMaster(I2C0_W2BW_BASE, DEVICE_SYSCLK_FREQ, 400000, I2C_DUTYCYCLE_33);
I2C_setConfig(I2C0_W2BW_BASE, I2C_MASTER_SEND_MODE);
I2C_setSlaveAddress(I2C0_W2BW_BASE, 0);
I2C_disableLoopback(I2C0_W2BW_BASE);
I2C_setBitCount(I2C0_W2BW_BASE, I2C_BITCOUNT_1);
I2C_setDataCount(I2C0_W2BW_BASE, 1);
I2C_setAddressMode(I2C0_W2BW_BASE, I2C_ADDR_MODE_7BITS);
I2C_enableFIFO(I2C0_W2BW_BASE);
I2C_setFIFOInterruptLevel(I2C0_W2BW_BASE, I2C_FIFO_TXEMPTY, I2C_FIFO_RXEMPTY);
I2C_setEmulationMode(I2C0_W2BW_BASE, I2C_EMULATION_STOP_SCL_LOW);
I2C_enableModule(I2C0_W2BW_BASE);
}
我注意到有一个选项可以将"I2C_ADDR_MODE_7BITS"更改为"I2C_ADDR_MODE_10BITS"、但似乎没有8位选项(我也从未听说过 I2C 的这种模式)。 是否有特殊选项可生成前导零位、或者是否缺少其他内容?


