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

TWI callback function can't build dynamically

Hello All.

I try to build a generic function that read device reg over its I2C. I take the TWI master example of Nordic.

There is need for callback function to get in the ISR whenever there is a replay.

It build statically put the function name in nrf_twi_mngr_transaction_t type like this

static nrf_twi_mngr_transaction_t NRF_TWI_MNGR_BUFFER_LOC_IND transaction =
{
.callback = read_all_cb,
.p_user_data = NULL,
.p_transfers = transfers,
.number_of_transfers = sizeof(transfers) / sizeof(transfers[0])
};

But I want to give the function name in the function input and place it inside like this:

Serial_read_2BytesReg(uint8_t instance,uint8_t dev_add, uint16_t reg_add,void const * p_buffer,size_t size, nrf_twi_mngr_callback_t callback_fn )

.

.

.

nrf_twi_mngr_transaction_t NRF_TWI_MNGR_BUFFER_LOC_IND transaction =
{
.callback = callback_fn,
.p_user_data = NULL,
.p_transfers = transfers,
.number_of_transfers = sizeof(transfers) / sizeof(transfers[0])
};

I also place its prototype in the h file

I don't get error during build, but on run it fail. So I try to place brake point into the callback function but it tell me I can't. It is look like it don't place any code for it.

1. Can I place the callback function to the struct and don't make it const?

2. What should I I do so it recognize that function?

Thanks

Bar.

Parents Reply
  • I see. Let us know if you still have problems.

    Also, I want to mention that the SDK includes a library for accessing arbitrary I2C registers: the nrf_wi_sensor library (<SDK>\components\libraries\twi_sensor\nrf_twi_sensor.h). It is not used by any of the TWI examples in the SDK. However, you can see how it is used in many of the drivers under <SDK>\components\drivers_ext\.

Children
No Data
Related