Hi
I was creating a function to send i2c data trough sensor that I use. But when I double check the communication, there is a part that doesn't works properly. So as you can see, below is the function :
int ch201_write_byte(ch201_device *dev_ptr, uint16_t mem_addr, uint8_t data_value) { uint8_t message[2] = { sizeof(data_value), data_value }; int ch_err = i2c_block_write(CH201_I2C_ADDR_PROG, mem_addr, sizeof(message), message); return ch_err; }
That code used many times, but when I check all the time, the result goes wrong when it goes to int ch_err = i2c_block_write...
I create you an that putting watchdog for checking all of the variables that happens.
Below is the first time it is executed, so data_value is 0x00, but message array goes wrong, it is 0x75, 0x6c. It should be 0x00, 0x01. CMIIW
Another example is in the image below. The data_value is 0x10. But when you check message, it is 0x00 and 0x00. It should be 0x01,0x10. CMIIW
because of that, the sensor doesn't works properly, since the sensor works with SoC system, so I need to double-check all of the communication process.
Anybody experience in this issue? Thanks.