This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using app_twi_perform() for a read transaction - Internal Error

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?

Parents
  • Turns out the error was due to the number of transfers being incorrect. I made the mistake of not realising that the macro for SHT21_READ was actually two transfers instead of just one, so simply this did the trick to fix it:

    APP_ERROR_CHECK( app_twi_perform(m_app_twi, transfers, 2, NULL) );   // Change # tranfers from 1 to 2
    

    So for anyone else with this issue, which I've since been able to reproduce with the same error code resulting, the issue is probably sending the wrong number of transfers to the app_twi_perform function.

Reply
  • Turns out the error was due to the number of transfers being incorrect. I made the mistake of not realising that the macro for SHT21_READ was actually two transfers instead of just one, so simply this did the trick to fix it:

    APP_ERROR_CHECK( app_twi_perform(m_app_twi, transfers, 2, NULL) );   // Change # tranfers from 1 to 2
    

    So for anyone else with this issue, which I've since been able to reproduce with the same error code resulting, the issue is probably sending the wrong number of transfers to the app_twi_perform function.

Children
Related