I've been fiddling around and becoming familiar with the app_twi transaction manager. I wanted to do a quick unscheduled read of a peripheral's configuration register before I set up the regular reads in the transaction manager using app_twi_perform. I had previously used this to simply write a register, but not read.
Here is the code I am using:
Calling the function from main():
while(1){
SHT21_get_register(&m_app_twi, &m_sht21_buffer[3]);
printf("%x", m_sht21_buffer[3]);
nrf_delay_ms(500);
}
The function:
void SHT21_get_register(app_twi_t *m_app_twi, uint8_t *m_user_reg){
app_twi_transfer_t const transfers[] = {
SHT21_READ(&sht21_user_reg_r, m_user_reg, 1)
};
APP_ERROR_CHECK( app_twi_perform(m_app_twi, transfers, 1, NULL) );
}
The SHT21_READ macro:
#define SHT21_READ(p_reg_addr, p_buffer, byte_cnt) \
APP_TWI_WRITE(SHT21_ADDRESS, p_reg_addr, 1, APP_TWI_NO_STOP), \
APP_TWI_READ (SHT21_ADDRESS, p_buffer, byte_cnt, 0)
The terminal linked to UART is returning a '0' for register value and an Error #3, which I think is an NRF_INTERNAL_ERROR.
Is it not possible to use the app_twi_perform() for simple non-scheduled reads? Or is there a way and I'm just doing this wrong?