Tool/software:
Greetings... I am trying to write 16 bit data to the specific register address through I2C. Iam not getting any errors while writing the data into the register. Then I read it back from that register the values are not changing. Here is my code snippet.
Please help. Thanks in advance.
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");
return;
}
}
if (MAP_I2CMasterErr(I2C3_BASE) != I2C_MASTER_ERR_NONE) {
UARTprintf("TRANSFER ERROR\n");
return;
}
for (uint8_t i = 0; i < length; i++) {
MAP_I2CMasterDataPut(I2C3_BASE, data[i]);
if (i == length - 1) {
MAP_I2CMasterControl(I2C3_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
} else {
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");
return;
}
}
if (MAP_I2CMasterErr(I2C3_BASE) != I2C_MASTER_ERR_NONE) {
UARTprintf("TRANSFER ERROR\n");
return;
}
}
}
int main(){
...
uint8_t writeData[2] = {0xFF, 0xFF};
I2C_WriteRegister(registerAddress, writeData, 2);
UARTprintf("Data written to Register 0x%02X: 0x%02X 0x%02X\n", registerAddress, writeData[0], writeData[1]);
..
}