Jump to content
Sign in to follow this  

Timer & Pin Interrupts for TIVA

Recommended Posts

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 ?

Share this post

Link to post
Share on other sites

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)

Share this post

Link to post
Share on other sites

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);

  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_TimerEnable(TIMER0_BASE, TIMER_A);
  MAP_TimerEnable(TIMER1_BASE, TIMER_A);

void loop()
  // Nothing to do 

void Timer0IntHandler() {
  digitalWrite(GREEN_LED, greenLedState);
  greenLedState = !greenLedState;

void Timer1IntHandler() {
  digitalWrite(RED_LED, redLedState);
  redLedState = !redLedState;

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

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.



Share this post

Link to post
Share on other sites

Add below 2 lines to above example code for function declaration.

And then work correctly


void Timer0IntHandler();
void Timer1IntHandler();

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this