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.
工具/软件:Code Composer Studio
我在 HDC2080传感器上读取和写入数据时遇到问题、如果我连续添加一些写入命令、则数据不会写入传感器...
如果我尝试按顺序读取数据、所有读数都会返回相同的值、有时与第一次读取的值相同、有时也与第二次读取的值相同。
这可能是什么?
void initI2C9 (uint32_t clock1) { ROM_SysCtlPeripheralEnable (SYSCTL_Periph_I2C9); ROM_SysCtlPeripheralReset (SYSCTL_Periph_I2C9); ROM_SysCtlPeripheralEnable (SYSCTL_Periph_GPIOA); ROM_GPIOPinConfigure (GPIO_PA0_I2C9SCL); ROM_GPIOPinConfigure (GPIO_PA1_I2C9SDA); ROM_GPIOPinTypeI2CSCL (GPIO_Porta_base、GPIO_PIN_0); ROM_GPIOPinTypeI2C (GPIO_Porta_base、GPIO_PIN_1); ROM_I2CMasterInitExpClk (I2C9_BASE、clock1、true); HWREG (I2C9_BASE + I2C_O_FIFOCTL)= 80008000; } uint8_t buf; uint8_t readI2C9 (uint16_t DEVICE_ADDRESS、uint16_t DEVICE_register) { ROM_I2CMasterSlaveAddrSet (I2C9_BASE、DEVICE_ADDRESS、false); ROM_I2CMasterDataPut (I2C9_BASE、DEVICE_REGISTER); ROM_I2CMasterControl (I2C9_BASE、I2C_MASTER_CMD_SINGLE_SEND); while (ROM_I2CMasterBusy (I2C9_BASE)); ROM_I2CMasterSlaveAddrSet (I2C9_BASE、DEVICE_ADDRESS、TRUE); ROM_I2CMasterControl (I2C9_BASE、I2C_MASTER_CMD_SINGLE_Receive); while (ROM_I2CMasterBusy (I2C9_BASE)); buf= ROM_I2CMasterDataGet (I2C9_BASE); return (buf); } void writeI2C9 (uint16_t device_address、uint16_t device_register、uint8_t device_data) { ROM_I2CMasterSlaveAddrSet (I2C9_BASE、DEVICE_ADDRESS、false); ROM_I2CMasterDataPut (I2C9_BASE、DEVICE_REGISTER); ROM_I2CMasterControl (I2C9_BASE、I2C_MASTER_CMD_BURST_SEND_START); while (ROM_I2CMasterBusy (I2C9_BASE)); ROM_I2CMasterSlaveAddrSet (I2C9_BASE、DEVICE_ADDRESS、TRUE); ROM_I2CMasterDataPut (I2C9_BASE、DEVICE_DATA); ROM_I2CMasterControl (I2C9_BASE、I2C_MASTER_CMD_BURST_Receive_finish); while (ROM_I2CMasterBusy (I2C9_BASE)); }
您好!
在 writeI2C9()函数中,我不太确定为什么需要第二个 ROM_I2CMasterDataPut (I2C9_BASE、DEVICE_DATA)。 我不熟悉 HDC2080、但在数据表中、它说、在您更改为读取的从器件地址后、主器件应该只是在等待数据。 但是、在更改从器件地址进行读取后、您将尝试写入另一个数据。
您能像下面那样尝试写入 I2C9中的内容、看看是否会有所不同?
//之前的行未显示
while (!I2CMasterBusy (I2C9_BASE)//添加此行
while (ROM_I2CMasterBusy (I2C9_BASE)); ROM_I2CMasterSlaveAddrSet (I2C9_BASE、DEVICE_ADDRESS、TRUE);// ROM_I2CMasterControl (I2C9_BASE、I2C_MASTER_CMD_SINGLE_Receive);
while (!I2CMasterBusy (I2C9_BASE)//添加此行
while (ROM_I2CMasterBusy (I2C9_BASE));
buf= rom_I2CMasterDataGet (I2C9_BASE);
它可以正常工作、但在每个代码之前只进行了微小的更改
while (ROM_I2CMasterBusy (I2C9_BASE));
我添加了您的建议:
while (!ROM_I2CMasterBusy (I2C9_BASE));
代码现在运行良好!
谢谢你