volatile uint8_t incount = 255;
uint16_t intimeout = 0;
uint16_t handledata(uint8_t buttonnumber)
{
intimeout = 0;
incount = 255;
buttonlink(buttonnumber); //point to correct array
ledmux(buttonnumber);
nrf_drv_gpiote_in_event_enable(IN_PIN, true); //enable input event interrupts
while (incount == 255)
{
//__WFE(); ?
//wait until first event has occurred, incount will become 0 thus exiting loop
}
while (incount < 72)
{
//__WFE(); ?
//wait until all array indices are filled with data
}
//if loop is done, disable timer and events and turn off LED
nrf_drv_timer_disable(&TIMER_4);
nrf_drv_gpiote_in_event_disable(IN_PIN);
ledmux(0);
return NRF_SUCCESS;
}
static void IN_PIN_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
//if first event occurs, activate timer
if (incount == 255)
{
nrf_drv_timer_enable(&TIMER_4);
}
incount++; //after first time, value becomes 0 and is needed for array indices
*(arrptr + incount) = intimeout * 50; //convert count value to microseconds
intimeout = 0;
}
static void timer4_handler(nrf_timer_event_t event_type, void* p_context)
{
// 50us period
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
intimeout++;
break;
default:
//Do nothing.
break;
}
}
Hello
I am currently trying to read data and save the timings of it. When pushing a button on my custom made PCB, the microcontroller goes to the handledata function. This function sets all the variables to their initial position. The buttonlink function makes sure the pointer is pointing to the correct array where the data will be stored.
The idea is to enable events on a pin. The microcontroller should wait until an event happens, this enables the timer and makes the value incount 0. The values stored in the array are timings in microseconds. As soon as all array positions are filled the timer and events should be deactivated and the function should return back to the main one.
However I cannot get out of my while loops. The event interrupt works without it but is not called when inside the while loop. How can I solve this?
Best regards