TVG 0 Posted January 7, 2016 Share Posted January 7, 2016 I have experience with the traditional C programming in Code Composer and have implemented a timer interrupt routine in CCS for TIVA TM4C1294, now I want to create a timer ISR in Energia, how do I proceed ? Quote Link to post Share on other sites
L.R.A 78 Posted January 7, 2016 Share Posted January 7, 2016 The same way. If you set the ISR in the startup then in Energia the difference is that you need to use TimerIntRegister() function.There isn't any function in Energia to do this. (I've been wanting to make a library but too much too study or I simply forget) Quote Link to post Share on other sites
TVG 0 Posted January 7, 2016 Author Share Posted January 7, 2016 Can you please provide a simple example? Thanks @L.R.A Quote Link to post Share on other sites
energia 485 Posted January 7, 2016 Share Posted January 7, 2016 Below is a simple example using 2 timers to toggle 2 LED's. #include <stdint.h> #include <stdbool.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/debug.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/rom_map.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/timer.h" uint8_t greenLedState = HIGH; uint8_t redLedState = LOW; void setup() { pinMode(RED_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); MAP_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); MAP_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC); MAP_TimerLoadSet(TIMER0_BASE, TIMER_A, MAP_SysCtlClockGet()); MAP_TimerLoadSet(TIMER1_BASE, TIMER_A, MAP_SysCtlClockGet() / 10); TimerIntRegister(TIMER0_BASE, TIMER_A, &Timer0IntHandler); TimerIntRegister(TIMER1_BASE, TIMER_A, &Timer1IntHandler); MAP_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); MAP_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); MAP_TimerEnable(TIMER0_BASE, TIMER_A); MAP_TimerEnable(TIMER1_BASE, TIMER_A); } void loop() { // Nothing to do } void Timer0IntHandler() { MAP_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); digitalWrite(GREEN_LED, greenLedState); greenLedState = !greenLedState; } void Timer1IntHandler() { MAP_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); digitalWrite(RED_LED, redLedState); redLedState = !redLedState; } Fmilburn, spirilis and Rei Vilo 3 Quote Link to post Share on other sites
TVG 0 Posted January 8, 2016 Author Share Posted January 8, 2016 In the above code, the LEDs blink perfectly, however when I use Serial.println("xyz"); in void loop() , the LEDs blink abruptly in between. @@energia Quote Link to post Share on other sites
energia 485 Posted January 8, 2016 Share Posted January 8, 2016 Do not have a TivaC to try right now but you might want to try to insert a slight delay of 100ms in the loop. Robert Quote Link to post Share on other sites
spirilis 1,265 Posted January 8, 2016 Share Posted January 8, 2016 In the above code, the LEDs blink perfectly, however when I use Serial.println("xyz"); in void loop() , the LEDs blink abruptly in between. @@energia Can you post your whole sketch? I'm not seeing that... I added Serial.begin(115200) at the very top of setup and Serial.println("xyz"); inside loop. Still seeing the LEDs blink similarly. energia 1 Quote Link to post Share on other sites
energia 485 Posted January 8, 2016 Share Posted January 8, 2016 I just now gave it a try as well and I too see the LED's flashing as expected. You still might want to add a delay(100) or something in your loop to prevent the Serial monitor from being flooded. Robert Quote Link to post Share on other sites
L.R.A 78 Posted January 8, 2016 Share Posted January 8, 2016 Tested it at 9600 and 115200 and no visible issue. Maybe there are microseconds timing issues but not much else energia 1 Quote Link to post Share on other sites
DanielYoo 0 Posted May 7, 2016 Share Posted May 7, 2016 Add below 2 lines to above example code for function declaration. And then work correctly void Timer0IntHandler(); void Timer1IntHandler(); Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.