Hello everyone,
I'm working with a nrf52840 devboard on which I put a LIS2DH12 accelerometer. I had a perfectly working example program featuring multiple functions. My program is very similar to this one, featured in another topic, that helped me a lot : https://devzone.nordicsemi.com/f/nordic-q-a/36089/using-the-lis2dh12-driver-of-the-sdk-v15-0-0-to-configure-the-lis2dh12-sensor/139406#139406.
Once it was working, I decided to sort my functions in different files to make it easier and clearer to find. This is where the trouble begins : I can't figure a way to compile my program now that the functions are separated in different files.
To take the most simple example, let's say I have 2 .c and 2 .h associated files : init_accelero.c / .h which contains the initialization functions, and whoami.c / .h which holds a simple function that prints the value of the Who Am I registry. Here's the code for the 4 of them :
init_accelero.c :
init_accelero.h :
whoami.c :
whoami.h :
The error comes from those 3 lines of code in init_accelero.h, when I call NRF_TWI_MNGR_DEF, NRF_TWI_SENSOR_DEF and LIS2DH12_INSTANCE_DEF. Here's the output of my Make command :
I know I'm supposed to call those macros once, and that's why I didn't have any trouble when everything was in one single file. However now both of my C files are using m_lis2dh12, which means I have no choice but include "init_accelero.h" in both C files. The problem is that it seems like variables used inside those macros like nrf_twi_mngr_queue and nrf_twi_sensor_pool are redefined ? I don't quite understand why it would be redefined here, honestly, and I don't know how I could solve this compilation issue. There must be another way than just putting all functions in a single file, right ?
I've been trying different things to avoid this error but other errors occured instead. For example, when I tried putting those macros in a function and then calling this function from acc_init(), I had : "section attribute cannot be specified for local variables", even if I declared m_nrf_twi_mngr, m_nrf_twi_sensor, m_lis2dh12 in init_accelero.h . I tried just putting those macros at the beggining of init_accelero.c, which didn't give me any compilation error but obviously prevented get_whoami() from working since it doesn't have access to the initialization of m_lis2dh12.
I hope I was clear enough, if you need more info, don't hesitate to ask. This is probably an easy thing to solve but I can't figure out how. I'm not programming for nrf since very long so I don't not understand how everything works yet, and I may have missed an obvious fix to this.
Thanks in advance !
Hugo