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

using TWI transaction manager with callback

Hi,

I'm using 3rd Generation of the nRF51822 with SoftDevice 8.0.0 and SDK 10.0.

There is an example in the SDK installation folder which shows how to use the TWI transaction manager with no callback function.

I believe using TWI transaction manager without callback function will force the TWI to run in the blocking mode.

I want to use the TWI transaction manager with the callback function but i don't know that function type should i pass into the transaction manager

I'm using below code to configure the TWI and perform write operation on the EEPROM

app_twi_t m_app_twi = APP_TWI_INSTANCE(0);
#define MAX_PENDING_TRANSACTIONS    128
static void twi_config(void)
{
    uint32_t err_code;

    nrf_drv_twi_config_t const config = {
       .scl                = SCLK,
       .sda                = SDAT,
       .frequency          = NRF_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_LOW
    };

    APP_TWI_INIT(&m_app_twi, &config, MAX_PENDING_TRANSACTIONS, err_code);
    APP_ERROR_CHECK(err_code);
}

Write to EEPROM memory

void AT24C_write_byte(uint32_t address,uint8_t data)
{
		
		uint8_t write_data[3];
		write_data[0] = address>>8;
		write_data[1] = address&0xFF;
		write_data[2] = data;
	
		#define TRANSFER_COUNT 	1
		
		app_twi_transfer_t const transfers[TRANSFER_COUNT] =
		{
				APP_TWI_WRITE(at24c.address, write_data,sizeof(write_data), 0)
		};
		
		app_twi_transaction_t const transaction =
		{
				.callback            = NULL,//transaction_callback,
				.p_user_data         = NULL,
				.p_transfers         = transfers,
				.number_of_transfers = sizeof(transfers)/sizeof(transfers[0])
		};		
		
		
		uint32_t err_code = app_twi_schedule(&m_app_twi, &transaction);
		
		APP_ERROR_CHECK(err_code);
}

i put the write operation in a while loop and after some write operation the HardFault handler is called.

Please give me an example on how to use the TWI transaction manager with callback function and also how to find the cause of HardFault.

Related