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

How to void repeated TWI start condition using nrf_drv_twi_tx()

Hello,

I would like to use Nordic SDK libraries (currently I'm using SDK 17.0.2) to read and write on a FM24CL16B I2C F-RAM.

This device has the following writing workflow:

datasheet, page 7

Following Nordic TWI example, the piece of code I'm using to write values 0x7A and 0x7B at 0x00 and 0x01 memory addresses:

static const nrf_drv_twi_t	twi_instance = NRF_DRV_TWI_INSTANCE( 1 );		// Instance of TWI master driver that will be used for communication

	ret_code_t err_code;
	static uint8_t reg_addr = 0x00;
    static uint8_t p_buff[5] = {0x7A, 0x7B, 0x83, 0x84, 0x85};
	
	static const nrf_drv_twi_config_t twi_config = {
		.scl =						TWI_SCL_PIN,											// SCL pin number.
		.sda =						TWI_SDA_PIN,											// SDA pin number.
		.frequency =				NRF_DRV_TWI_FREQ_100K,								// TWI frequency.
		.interrupt_priority =	TWI_IRQ_PRIORITY,										// Interrupt priority.
		.clear_bus_init =			false,													// Clear bus during init.
		.hold_bus_uninit =		false														// Hold pull up state on gpio pins after uninit.
	};
	err_code = nrf_drv_twi_init( &twi_instance, &twi_config, NULL, NULL );
	APP_ERROR_CHECK( err_code );
	nrf_drv_twi_enable( &twi_instance );												// enable I2C
	err_code = nrf_drv_twi_tx( &twi_instance, 0x50, &reg_addr, 1, true );
	APP_ERROR_CHECK( err_code );
	err_code = nrf_drv_twi_tx( &twi_instance, 0x50, p_buff, 2, false );
	APP_ERROR_CHECK( err_code );
	nrf_drv_twi_disable( &twi_instance );

Using this library the problem I have is that the start condition and the slave address are sent twice, and the writing on the memory does not happen correctly.

Due to double sending, the value 0x7B is written to the address 0x7A:

Could you give me some hints to set the code correctly?

Thanks!

Parents Reply
  • Dear awneil,

    having the address and the data in the same array is not convenient because in this way the function nrf_drv_twi_tx() that has the same name in SDK 17 and SDK11 accepts the same parameters but produces two different outputs (I checked with the oscilloscope).
    The only workaround seems to be to copy each time the address plus all the data in a single array and call the function function nrf_drv_twi_tx(), in this way it wastes time, and also RAM is wasted

Children
No Data
Related