Following my last post a few days ago, I was finally able to communicate with a slave via the TWI interface, thank you very much for your help! This time, I have a problem concerning timer interrupts. Basically, I can't get one : the program seems to never enter the timer_handler. I have followed the same procedure as in the timer example (altough I am using nrfx_timer instead of nrf_drv_timer). The other difference being that my nrfx_config.h file does not call on a sdk_config.h file (I have taken the nrfx_config.h file located in the templates folder for nRF52832).
So what could it be? I suspect it could be linked to my project not having a sdk_config.h file of sorts but it seemed to be working fine without it when I was testing the TWI communication. I also read somewhere that it was the SoftDevice that was controlling the timers, could that be interfering with my code?
I have included the TWI section of my code for context in case one interferes with the other but I doubt that it does.
#include <stdio.h>
#include "nrf_gpio.h"
#include "nrfx_timer.h"
#include "nrfx_twi.h"
//-----------------------------------------------------------------------// TEMPS
const nrfx_timer_t m_timer = NRFX_TIMER_INSTANCE(0);
void timer_init(void)
{
const nrfx_timer_config_t timer_config =
{
.frequency = NRF_TIMER_FREQ_1MHz,
.mode = NRF_TIMER_MODE_TIMER,
.bit_width = NRF_TIMER_BIT_WIDTH_32,
.interrupt_priority = NRFX_TIMER_DEFAULT_CONFIG_IRQ_PRIORITY,
.p_context = NULL
};
void timer_handler(nrf_timer_event_t event_type,void* p_context)
{
switch(event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
{
nrf_gpio_pin_toggle(17);
break;
}
default:
{
break;
}
}
}
nrfx_timer_init(&m_timer,&timer_config,timer_handler);
uint32_t time_ticks = nrfx_timer_ms_to_ticks(&m_timer,500);
nrfx_timer_extended_compare(&m_timer,NRF_TIMER_CC_CHANNEL0,time_ticks,NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrfx_timer_enable(&m_timer);
}
//-----------------------------------------------------------------------// ADDRESSAGE
#define ADDR 0x20 // 0x20 à 0x27
const nrfx_twi_t m_twi = NRFX_TWI_INSTANCE(0);
uint8_t dirA[2] = {0x00,0x00};
uint8_t ioA[2] = {0x0A,0x00};
uint8_t conf[2] = {0x05,0xA0};
void twi_init(void)
{
const nrfx_twi_config_t twi_config =
{
.scl = 27,
.sda = 26,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = NRFX_TWI_DEFAULT_CONFIG_IRQ_PRIORITY,
.hold_bus_uninit = false,
};
nrfx_twi_init(&m_twi,&twi_config,NULL,NULL);
nrfx_twi_enable(&m_twi);
}
//-----------------------------------------------------------------------// MAIN
void main(void)
{
timer_init();
nrf_gpio_pin_dir_set(17, NRF_GPIO_PIN_DIR_OUTPUT);
nrf_gpio_pin_dir_set(18, NRF_GPIO_PIN_DIR_OUTPUT);
if(nrfx_timer_is_enabled(&m_timer) == 1) nrf_gpio_pin_clear(18);
while(1)
{
}
}