Hello,
nRF51822 SDKv11 Kail 5.18 SD130
I have a pcb that has a sensor with I2C. I made a project that based on the sample of "twi_sensor", and I can read the sensor data. The project sequence is like this.
-
send tx with no sotp condition,
-
tx inturrupt fire
-
send rx.
Then, I found a function "nrf_drv_twi_xfer" and it seems I could do same thing with less code amount. Then I made following code but I could not read the value. There is no twi error and the value is always "0". It's for sure the address or some setting is not wrong.
static const nrf_drv_twi_t twi = NRF_DRV_TWI_INSTANCE(0);
void twi_init (void)
{
ret_code_t err_code;
const nrf_drv_twi_config_t twi_config = {
.scl = SCL_PIN,
.sda = SDA_PIN,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
err_code = nrf_drv_twi_init(&twi, &twi_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&twi);
}
int main(void)
{
...
uint8_t reg = MPU6500_axh_adr;
nrf_drv_twi_xfer_desc_t xfer = NRF_DRV_TWI_XFER_DESC_TXRX(MPU6500_ADDR,
®,
sizeof(reg) ,
(uint8_t*)&m_samples,
sizeof(m_samples));
uint32_t flags = NRF_DRV_TWI_FLAG_TX_NO_STOP;
err_code = nrf_drv_twi_xfer(&twi, &xfer, flags);
if(err_code != NRF_SUCCESS){
SEGGER_RTT_printf(0, "OK\r\n");
}else{
SEGGER_RTT_printf(0, "NG\r\n");
}
...
}