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,

Parents
  • 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,

Reply
  • 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,

Children
No Data
Related