Hello,
I am trying to learn how to use the Tiva C series launchpad (TM4C123GXL) with code composer studio and I can't figure out how to make interrupts work without TIVA ware. I tried to write a simple program that uses the watchdog timer0 to test out it is interrupt but it is not working so far.
Could somebody point me to the right direction.
Note that stuff like BIT1,BIT0 are things that I have defined and the code compiles properly and the WDT is resetting the system when it overflows twice.
/* Program to test the WDT0 functionallity, WDT1 is a little bit different
* WDT0 uses the system clock.
* WDT0 is a 32-bit down counter
* When WDT overflows for the first time, in enters a ISR and an interrupt flag is set and tries to save the system
* When it overflows a second time, it resets the system.
*
*/
// includes
#include <tiva.h>
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
// functions prototype
void WDT_0(void);
int main (void)
{
IntMasterEnable();
volatile unsigned long int i;
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; // Enable the GPIO port that is used for the on-board LED.
i = SYSCTL_RCGC2_R; // Do a dummy read to insert a few cycles after enabling the peripheral.
GPIO_PORTF_LOCK_R = 0x4C4F434B; // unlock PortF pins (only portF needs this)
GPIO_PORTF_CR_R |= 0x1F; // allow changes to PF4-0 (only portF needs this)
GPIO_PORTF_DIR_R |= BIT2+BIT1; // set PF2,PF1 as outputs
GPIO_PORTF_DIR_R &= ~(BIT4+BIT0); // set PF4 and PF0 as inputs
GPIO_PORTF_PUR_R |= 0x11; // enable pullup resistors on PF4,PF0
GPIO_PORTF_DEN_R |= BIT4+BIT3+BIT2+BIT1+BIT0; // enable digital for PF4-PF0
WDT_0();
GPIO_PORTF_DATA_R |= BIT2;
while (1)
{
//WATCHDOG0_LOAD_R = 0xFFFFFFFF; // pet WDT by reloading a value
//WATCHDOG0_ICR_R =0x01; // clear interrupt overflow flag.
}
}
void WDT_0(void)
{
volatile unsigned long int i;
SYSCTL_RCGCWD_R |= 0x01; // enable clock for WDT 0
i = SYSCTL_RCGCWD_R; // Do a dummy read to insert a few cycles after enabling the peripheral.
WATCHDOG0_LOAD_R = 50000000; // load value into counter
WATCHDOG0_CTL_R |= 0x02; // these two lines let WDT reset system
WATCHDOG0_CTL_R |= 0x01; // and enable WDT 0 and interrupts.
}
void WDT_Handler(void)
{
GPIO_PORTF_DATA_R |= BIT1;
}