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总线上进行通信的包装程序。这种封装程序如下所示:
int8_t user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr) { int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */ uint8_t i = 0; /* * The parameter intf_ptr can be used as a variable to store the I2C address of the device */ /* * Data on the bus should be like * |------------+---------------------| * | I2C action | Data | * |------------+---------------------| * | Start | - | * | Write | (reg_addr) | * | Stop | - | * | Start | - | * | Read | (reg_data[0]) | * | Read | (....) | * | Read | (reg_data[len - 1]) | * | Stop | - | * |------------+---------------------| */ I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false); I2CMasterDataPut(I2C0_BASE, reg_addr); I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_SEND); while (I2CMasterBusy(I2C0_BASE)) { } I2CMasterSlaveAddrSet(I2C0_BASE, *(uint8_t *)intf_ptr, false); if ( len == 1){ I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_SINGLE_RECEIVE); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[0] = I2CMasterDataGet(I2C0_BASE); }else { I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_START); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[0] = I2CMasterDataGet(I2C0_BASE); for(i = 0 ; i < len -2 ; i++){ I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_CONT); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[i+1] = I2CMasterDataGet(I2C0_BASE); } I2CMasterControl(I2C0_BASE,I2C_MASTER_CMD_BURST_RECEIVE_FINISH); while (I2CMasterBusy(I2C0_BASE)) ; reg_data[i+1] = I2CMasterDataGet(I2C0_BASE); return rslt; }
在查看总线上发生的情况的范围上,请参阅以下 内容:
地址正确,数据发送也正常,但我想知道为什么第二个插槽不是读取插槽。 主控制器发送相同的牵引时间。 我的第一个插槽就像我们看到的一样,第二个插槽必须是同一地址上的一个读取插槽。如果你需要更多信息,请告诉我。谢谢你的帮助。
提前感谢您的帮助。
标记
您好,
地址1294地址正确,数据发送也正常,但我想知道为什么第二个插槽不是读取插槽。 [/引述]在您的第27行中,您指定了对I2C总线的第一个写入。 在第38行中,再次指定另一个写入。 第27行和第28行的呼叫如下。
I2CMasterSlaveAddrSet (I2C0_BASE,*(uint8_t *) intf_ptr,FALSE);// FALSE表示写入;TRUE表示读取。 如果要阅读,则需要更改为true。