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.
工具与软件:
您好... 我正在尝试通过 I2C 将16位数据写入特定的寄存器地址。 IAM 在将数据写入寄存器时未收到任何错误。 然后、我从该寄存器读回它、其值没有更改。 这是我的代码片段。
请提供帮助。 提前感谢。
void I2C_WriteRegister (uint8_t regAddress、uint8_t * data、uint8_t length){
MAP_I2CMasterSlaveAddrSet (I2C3_BASE、SLAVE_ADDRESS、FALSE);
MAP_I2CMasterDataPut (I2C3_BASE、regAddress);
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_START);
timeoutCounter = 0;
while (MAP_I2CMasterBusy (I2C3_BASE)){
MAP_SysCtlDelay (1000);
if (++timeoutCounter > timeout){
UARTprintf ("transfer timeout\n");
返回;
}
}
if (MAP_I2CMasterErr (I2C3_BASE)!= I2C_MASTER_ERR_NONE){
UARTprintf ("transfer error\n");
返回;
}
对于(uint8_t i = 0;i < length;i++){
MAP_I2CMasterDataPut (I2C3_BASE、DATA[i]);
如果(i == length - 1){
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH);
其他{
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_CONT);
}
timeoutCounter = 0;
while (MAP_I2CMasterBusy (I2C3_BASE)){
MAP_SysCtlDelay (1000);
if (++timeoutCounter > timeout){
UARTprintf ("transfer timeout\n");
返回;
}
}
if (MAP_I2CMasterErr (I2C3_BASE)!= I2C_MASTER_ERR_NONE){
UARTprintf ("transfer error\n");
返回;
}
}
}
int main(){
...
uint8_t writeData[2]={0xFF、0xFF};
I2C_WriteRegister (registerAddress、writeData、2);
UARTprintf ("写入寄存器0x%02x:0x%02x 0x%02x\n"、registerAddress、writeData[0]、writeData[1]);
.
}
您好!
您能否展示在写入和读取时 I2C 波形的逻辑分析仪捕捉?
我看到您有 while (MAP_I2CMasterBusy (I2C3_BASE))、 后跟等待 SysCtlDelay (1000)。 除了使用延迟、请在所有存在 while (MAP_I2CMasterBusy)的地方更改为下方。
更改自:
while (MAP_I2CMasterBusy (I2C3_BASE))
收件人:
while (! MAP_I2CMasterBusy (I2C3_BASE)//在使用以下行的任何位置添加这一行。
while (MAP_I2CMasterBusy (2C3_BASE))
感谢您的答复...但我没有逻辑分析仪。 我将 while (MAP_I2CMasterBusy (I2C3_BASE) )更改为 while (!MAP_I2CMasterBusy (I2C3_BASE))。
但现在也没有得到任何错误。 但该值不会写入特定寄存器(使用 readI2C 函数进行检查)。 请帮帮我。 提前感谢。
void I2C_WriteRegister (uint8_t regAddress、uint8_t * data、uint8_t length){
MAP_I2CMasterSlaveAddrSet (I2C3_BASE、SLAVE_ADDRESS、FALSE);
MAP_I2CMasterDataPut (I2C3_BASE、regAddress);
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_START);
timeoutCounter = 0;
while (! MAP_I2CMasterBusy (I2C3_BASE){
if (++timeoutCounter > timeout){
UARTprintf ("transfer timeout\n");
返回;
}
}
if (MAP_I2CMasterErr (I2C3_BASE)!= I2C_MASTER_ERR_NONE){
UARTprintf ("transfer error\n");
返回;
}
对于(uint8_t i = 0;i < length;i++){
MAP_I2CMasterDataPut (I2C3_BASE、DATA[i]);
如果(i == length - 1){
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH);
其他{
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_CONT);
}
timeoutCounter = 0;
while (! MAP_I2CMasterBusy (I2C3_BASE){
if (++timeoutCounter > timeout){
UARTprintf ("transfer timeout\n");
返回;
}
}
if (MAP_I2CMasterErr (I2C3_BASE)!= I2C_MASTER_ERR_NONE){
UARTprintf ("transfer error\n");
返回;
}
}
}
int main(){
...
uint8_t writeData[2]={0xED、0x97};
I2C_WriteRegister (registerAddress、writeData、2);
UARTprintf ("写入寄存器0x%02x:0x%02x 0x%02x\n"、registerAddress、writeData[0]、writeData[1]);
...
}
Putty 的输出:
数据写入寄存器0x00:0xED 0x97
您好!
如果您没有逻辑分析仪、那么您是否有示波器? 逻辑分析仪或示波器对于诊断问题非常有用。
您有正确的从器件地址吗?
您是否在 SCL 和 SDA 总线上设置了上拉电阻器?
看一下下面的代码、您需要插入繁忙检查按钮、如下所示。 尝试看看这是否有什么不同。
对于(uint8_t i = 0;i < length;i++){
MAP_I2CMasterDataPut (I2C3_BASE、DATA[i]);
如果(i == length - 1){
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_FINISH);
while (! map_I2CMasterBusy (I2C3_base);//将该新行添加到使用以下行的任何位置。
while (MAP_I2CMasterBusy (2C3_BASE));
其他{
MAP_I2CMasterControl (I2C3_BASE、I2C_MASTER_CMD_BURST_SEND_CONT);
while (! map_I2CMasterBusy (I2C3_base);//将该新行添加到使用以下行的任何位置。
while (MAP_I2CMasterBusy (2C3_BASE));
}
也请查看这个帖子。 我认为这会有所帮助。