Hi everyone,
I have a problem I can't sort out. My program runs fine indefinitely if I set one variable in a function at one point but if I don't do that, the program, or at least the debugging stops after a while. The program sort of continues (I can send a few messages from my app to it) but after a while it just doesn't seem to respond.
So.
I added a debug print of "." in the main loop which has a 500ms delay in it. These are some startup messages I get when the program runs fine. The dots just keeps going.
app_timer: RTC: initialized! app: Erasing flash page app: --> Event received: erased 1 page from address 0x7F000. app: Converting a program to a buffer app: --> Event received: wrote 112 bytes at address 0x7F000. app: Converting a buffer to a program app: Accelerometers initialized. 25 app: Accelerometers initialized. 24 app: State --> NOT_CONNECTED app: end ..................................................................................................................
The dots just keeps going and going.
BUT! If I don't make that function call and set that variable the debugging (and parts of the program) stops after exactly the same amount of time every time:
app_timer: RTC: initialized! app: Erasing flash page app: --> Event received: erased 1 page from address 0x7F000. app: Converting a program to a buffer app: --> Event received: wrote 112 bytes at address 0x7F000. app: Converting a buffer to a program app: Accelerometers initialized. 25 app: Accelerometers initialized. 24 app: State --> NOT_CONNECTED app: end ....................
Compare the number of dots in the two examples.
The weird thing now is that the difference is in the beginning of main.c. If I make a function call to a function located in an included file called:
set_potentiometer_resistance(&m_twi_1, DIGITAL_POT_I2C_ADDRESS_MAX5434, 25000);
In that function I only do this:
ret_code_t set_potentiometer_resistance(nrf_drv_twi_t const * p_instance, uint8_t address, int32_t resistance) { actual_potentiometer_resistance = resistance; ret_code_t err_code; // uint8_t payload[2]; // payload[0] = DIGITAL_POT_MAX5434_COMMAND_VREG; // payload[1] = get_potentiometer_tap_position_from_resistance(resistance); // // err_code = nrf_drv_twi_tx(p_instance, address, &payload, sizeof(payload), false); return err_code; }
The actual_potentiometer_resistance variable is placed in the header file of the potentiometer function.
static int32_t actual_potentiometer_resistance;
I can set it to zero, it works just as well. But if I try to set the value of that variable instead of calling the function, like this:
actual_potentiometer_resistance = 0;
instead of:
set_potentiometer_resistance(&m_twi_1, DIGITAL_POT_I2C_ADDRESS_MAX5434, 25000);
It doesn't work. It stops after the same amount of time.
I can't understund this behavior. It feels like I'm changing something totally unrelated. When I've had similar issues earlier, if the program stops after a while or the debugging stops after a while, all of those problems have been due to me not freeing a malloc:ed variable or so. But what could cause this?
Thanks in advance,
Samuel