Tool/software: TI C/C++ Compiler
Hi sir,
I am new to Embedded programming.so if there is any error in my code please let me know.
Problem:
I am generating delay in LED blink program using Systick timer interrupt.The program is given below and I am attaching my c file also.
#include "stdio.h" #include "driverlib/sysctl.h" #include "driverlib/gpio.h" #include "hw_memmap.h" #include "driverlib/pin_map.h" #include "inc/hw_types.h" #include "driverlib/interrupt.h" #include "driverlib/systick.h" void delay(int a); volatile uint32_t count=0;//Counter to count the number of interrupts that have been called int main() { SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_OSC |SYSCTL_XTAL_8MHZ|SYSCTL_OSC_MAIN); //seting system clock as 50Mhz SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Enabling port A peripheral pin while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)); //delay(3000); //GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_7,GPIO_DIR_MODE_OUT);// make portA as output //GPIODirModeSet(GPIO_PORTF_BASE, GPIO_PIN_2,GPIO_DIR_MODE_IN); //make portF pin2 as input //GPIODirModeGet(GPIO_PORTF_BASE, GPIO_PIN_1); //GPIOPinConfigure(GPIO_PIN_1); //GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_7,GPIO_HIGH_LEVEL);//set the interrupt type for a specified pin //GPIOIntRegister(GPIO_PORTA_BASE,PortAIntHandler);//PortAIntHandler function is called when an interrupt is detected from the selected GPIO port //GPIOIntEnable(GPIO_PORTA_BASE, GPIO_INT_PIN_7);//Enable the interrupt for a specified pin GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_7);//Set portApin7 as output count=0; SysTickPeriodSet(SysCtlClockGet());// Set up the period for the SysTick timer. The SysTick timer period will // be equal to the system clock, resulting in a period of 1 second. IntMasterEnable();// Enable interrupts to the processor. SysTickIntEnable(); // Enable the SysTick Interrupt. // // Enable interrupts to the processor. // SysTickEnable();// Enable SysTick. while(1) { //uint32_t pinVal=0; // variable to hold the pinRead //pinVal= GPIOPinRead(GPIO_PORTF_BASE,GPIO_PIN_2); // read F4 //if( (pinVal & GPIO_PIN_2)==0){ // AND to strip out anything but the value read from F4 //GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1, 0);} // turn on one LED //GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1,1); //make portA pin7 as high //delay(); //else{} // GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, GPIO_PIN_7); //make portA pin7 as high //GPIO_PORTF_DATA1_bit = 1; // delay(3000); // GPIO_PORTF_DATA1_bit = 0; // GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7, 0); //make portA pin7 as low // delay(3000); } } void delay(int a) { int i,j; for (i=0;i<=a;i++) for (j=0;j<=a;j++) ; } // // The interrupt handler for the for Systick interrupt. // void SysTick_Handler(void){ // // Update the Systick interrupt counter. // count++; // // Check to see if systick interrupt count changed, and if so then // write high to the port pin. // if(count == 1){ GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7,GPIO_PIN_7); } else if(count == 2){ GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7,0); count=0;} }
#include "stdio.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "hw_memmap.h"
#include "driverlib/pin_map.h"
#include "inc/hw_types.h"
#include "driverlib/interrupt.h"
#include "driverlib/systick.h"
void delay(int a);
volatile uint32_t count=0;//Counter to count the number of interrupts that have been called
int main()
{
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_OSC |SYSCTL_XTAL_8MHZ|SYSCTL_OSC_MAIN); //seting system clock as 50Mhz
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //Enabling port A peripheral pin
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA));
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_7);//Set portApin7 as output
count=0;
SysTickPeriodSet(SysCtlClockGet());// Set up the period for the SysTick timer. The SysTick timer period will
// be equal to the system clock, resulting in a period of 1 second.
IntMasterEnable();// Enable interrupts to the processor.
SysTickIntEnable();
SysTickEnable();// Enable SysTick.
while(1)
{
}}
void SysTick_Handler(void){
//
// Update the Systick interrupt counter.
//
count++;
//
// Check to see if systick interrupt count changed, and if so then
// write high to the port pin.
//
if(count == 1){
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7,GPIO_PIN_7);
}
else if(count == 2){
GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_7,0);
count=0;}
}
The above code is working, but If I am inserting the highlighted section of above program inside the while loop(i.e, while(1) in main) then the program is not taking the interrupt handler function, it will run inside while loop only. I am incrementing the count inside interrupt handler function because of that only that I am not able to blink the led.
I am not getting why the interrupt handler function is not executing.Please help me to solve the issue.Feel free to contact me if you are having any doubt in my code.
Thank you,
Alphy Ouseph