HI, Im developing a custom board (NRF58232) with a bmx055 connected by TWI.
I have used the twi_scanner and twi_sensor and all OK, It was working !
But now I want to use the Bosch drivers API to a better implementation.
I can see that, the only thing that I must to do its implement the read and write functions but I dont know how !!
And, Must I initialize the TWI like in the twi_sensor like this ?
void twi_init(void) {
ret_code_t
err_code;
nrf_gpio_cfg_output(9);
const nrf_drv_twi_config_t bmx_config = {
.scl = 10,
.sda = 8,
.frequency = NRF_DRV_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};
err_code = nrf_drv_twi_init(&m_twi, &bmx_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_INFO("TWI_ENABLED");
nrf_drv_twi_enable(&m_twi);
}
The drivers can be found here
And the implementation about write/read are however i know it`s not like that :
s8 BMA2x2_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) {
uint8_t
data_11 = {reg_addr};
nrf_drv_twi_tx(&m_twi, dev_addr, &data_11, sizeof(data_11), true);
nrf_delay_ms(10);
nrf_drv_twi_rx(&m_twi, dev_addr, ®_data, sizeof(reg_data));
/* Please take the below function as your reference
* for read the data using I2C communication
* add your I2C rad function here.
* "IERROR = I2C_WRITE_READ_STRING(DEV_ADDR, ARRAY, ARRAY, 1, CNT)"
* iError is an return value of SPI write function
* Please select your valid return value
* In the driver SUCCESS defined as 0
* and FAILURE defined as -1
*/
return (s8) reg_data;
}
s8 BMA2x2_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt) {
uint8_t
data_11 = {reg_addr};
nrf_drv_twi_tx(&m_twi, dev_addr, &data_11, sizeof(data_11), true);
nrf_delay_ms(10);
nrf_drv_twi_tx(&m_twi, dev_addr, ®_data, sizeof(reg_data),true);
/* Please take the below function as your reference
* for read the data using I2C communication
* add your I2C rad function here.
* "IERROR = I2C_WRITE_READ_STRING(DEV_ADDR, ARRAY, ARRAY, 1, CNT)"
* iError is an return value of SPI write function
* Please select your valid return value
* In the driver SUCCESS defined as 0
* and FAILURE defined as -1
*/
return (s8) reg_data;
}
Can you help me please? A lot of thanks !