This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C write function error.

Hello, I am trying to interface bme280 with pca10040. I am using sdk12.2.2 and referring twi_sensor. I am able to make read function and it works as expected. I am facing some challenge in write function. My write function doesnt give me error but it is not writing anything in register. My slave address is 0x76, register address is 0xF4 and data I want to write is 0x01.

I am attaching my main.c here. write.txt

Please suggest me changes that I should make write function.

Thanks,

  • Are you sure you are not getting any errors? You are not checking the return value of nrf_drv_twi_tx() anywhere in your code? You should also check for *_NACK events in your twi_handler().

  • Hello Martin, I checked return value of nrf_drv_twi_tx and I am getting 0. I think 0 means success. Can you suggest me code snippet of write function or can you modify my code snippet for write function? Thanks,

  • Where in the attached code are you checking the return value? After you initialize the TWI you call write_sensor_data() which in turn calls nrf_drv_twi_tx() and stores the return code in ret_code. But I can't see that you are checking ret_code anywhere.

  • Hi Martin, My modified write function is as follows:

    ret_code_t write(uint8_t address, uint8_t reg, uint8_t value) { ret_code_t ret_code; uint8_t data[2]; data[0] = reg; data[1] = value;

    ret_code = nrf_drv_twi_tx(&m_twi,address, data, 2, false); printf("ret_c0de %d", ret_code); return ret_code;

    }

    In my main I am calling as: write(0x76, 0xF4, 0x01);

    I am printing the ret_code and its giving me 0 integer value. Thanks,

Related