If you forget to reenable them, you're in big trouble - your network, timers and Serial will all stop working. Unfortunately, disabling interrupts is error-prone - if you forget to do it, you'll have mysterious crashes. The only way to protect against this is to disable interrupts whenever your code might be accessing hardware or might have modifying data structures. This is the case with every subroutine and hardware access you do from an interrupt handler. while the software and hardware can be in inconsistent states. Now your code was running code somewhere inside Serial, and you call Serial again. Suppose your code is outputting something using Serial and the timer interrupt happens. The interrupt can interrupt anything that doesn't have interrupts locked out. When you call led_battery() from the interrupt handler, you're doing waaaaay too much work there. TimerAlarmWrite(timer, 10000, true) // Parameter : (timer_initialization, when_to_interrupt (us), flag_to_reload) Specify the counter value in which the timer interrupt will be generated (set every 10 ms) TimerAttachInterrupt(timer, &onTimer, true) // Parameter : (timer_initialization, address_interrupt,flag_to_activate - true(edge)/false(level)) Timer = timerBegin(0,80,true) // return a pointer to a structure of type hw_timer_t Base Clock Frequency = 80MHz Timer Frequency = 1MHz | Clock Cycle = 1us While (!Serial) // Leonardo: wait for serial monitor Led_status |= ~word(B11111100,B00000000) // setting up the bits that we want to change Led_status &= word(B00000011,B11111111) // clearing the bits that we want to change whilst preserving the other unchanged bits Led_status |= ~word(B11111000,B00000000) // setting up the bits that we want to change Led_status &= word(B00000111,B11111111) // clearing the bits that we want to change whilst preserving the other unchanged bits Led_status |= ~word(B11110000,B00000000) // setting up the bits that we want to change Led_status &= word(B00001111,B11111111) // clearing the bits that we want to change whilst preserving the other unchanged bits Led_status |= ~word(B11100000,B00000000) // setting up the bits that we want to change Led_status &= word(B00011111,B11111111) // clearing the bits that we want to change whilst preserving the other unchanged bits Led_status |= ~word(B11000000,B00000000) // setting up the bits that we want to change Led_status &= word(B00111111,B11111111) // clearing the bits that we want to change whilst preserving the other unchanged bits Int battery_percentage = voltage_amplifier*100/bit_max led_battery() led doesn't update if used here INTERRUPT MODE - INSERT INBETWEEN portENTER and portEXIT PortMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED // used to sync main loop and ISR Hw_timer_t * timer = NULL //configure the timer, need pointer to a variable type of hw_timer_t for Zero, output on USB Serial console, remove line below if using programming port to program the Zero! The way I go around it is that I set a flag in interrupt mode to show that I want to deepsleep and then execute it in the void loop() function.ĭoes anyone have any solution on how to make this work? (code is just for i2c and esp32) #include Same with deepsleep, I can't execute it in the interrupt mode. It's working fine for i2c (such as turning on LED) when I run it in the void loop() function, but when I port it to interrupt it doesn't work. I am using this library coding it in Arduino IDE : GPS_comms.I am having problem of executing deepsleep and i2c communication in the ISR(Interrupt Mode). Here's the gist( very much redacted) of the code: SoftwareSerial GPS_comms = SoftwareSerial(A0,A1) // RX, TX Just including soft serial.begin in setup() with no other calls to SoftSerial causes the 10pps motor to vary significantly.(to say nothing of what happens to the leds) All my routines in loop are run once every 2mSec for timer2 Actually the 2mSec interrupt is used to drive steppers at 500 pps(fast) 10pps(normal run) and a synchronised 60 led array.
0 Comments
Leave a Reply. |