Chat freely about anything...

User avatar
By eriksl
#53278 When I make a handler function for the FRC1 timer interrupt, it acts strangely, I can't explain. Please help.

The only thing the handler does (for the moment) is count how many times it has been called (counter++). It does not clear an interrupt mask and also it does not reload the timer, so it might or might not called more than once. I am aware of that.

This is what happens:

- when using "normal" FRC1 interrupt, NOTHING happens, the interrupt handler is never called (counter remains at zero)
- when using the "NMI" FRC1 interrupt, the handler is called, but the timer is reloaded automatically and the handler is called again and again, without the timer being reloaded by me and without setting "autoreload".

I am NOT using any os_timer* functions. I am NOT using pwm (not even -lpwm linked).

This is my testing code:
Code: Select allenum
{
   FRC1_DIVIDE_BY_1 = 0,
   FRC1_DIVIDE_BY_16 = 4,
   FRC1_DIVIDE_BY_256 = 8
};

enum
{
   FRC1_EDGE_INT = 0,
   FCR1_LEVEL_INT = 1
};

enum
{
   FRC1_AUTO_LOAD = 0x0040,
   FRC1_ENABLE_TIMER = 0x0080,
};

unsigned int ints;

static void intr_handler(void)
{
   ints++;
}

ICACHE_FLASH_ATTR static void intr_test(void)
{
   RTC_REG_WRITE(FRC1_CTRL_ADDRESS, FRC1_ENABLE_TIMER | FRC1_DIVIDE_BY_16 | FRC1_EDGE_INT);

   ETS_FRC_TIMER1_INTR_ATTACH(intr_handler, NULL); // non-NMI interrupt
   //ETS_FRC_TIMER1_NMI_INTR_ATTACH(intr_handler); // NMI interrupt, choose one

   TM1_EDGE_INT_ENABLE();

   ETS_FRC1_INTR_ENABLE();

   RTC_REG_WRITE(FRC1_LOAD_ADDRESS, 256);

   RTC_CLR_REG_MASK(FRC1_INT_ADDRESS, FRC1_INT_CLR_MASK);
}
User avatar
By eriksl
#53864 When I "or" 0x01 into the value that is written into FRC1_CTRL_ADDRESS (+ PERIPHS_TIMER_BASEADDR of course), it works.

According to the "documentation" (ehhhrmm, just examples found here and there), LEVEL_INT would be 0x1 and EDGE_INT would be 0x0. It seems it's the other way around actually?

It IS an EDGE interrupt now, because I don't need to clear the interrupt mask to have the ISR called again.

How comes it seems to for others nonetheless?