Hi,
I'm trying to interface a keypad that, when a button is pressed, starts sending a corresponding bitsequence. I've written an interrupthandler that detects the falling edges and counts for 9 interrupts, then it will reset the counter and start a timer. This timer has to be resetted and started over again if an interrupt occurs within the timercycle. This has been done because I only want to receive the 'number' (first 9 interrupts) only once.
Now when I press the button with a corresponding number, I receive the first 9 interrupts and the timer is started. When I keep the button pressed, the timer is resetted several times but then it spits out a number again? Could this be due to a Watchdog Timer? I see in CCS that a Watchdog Timer is Enabled when I a start the code?
My code:
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "inc/lm4f120h5qr.h"
#include "driverlib/fpu.h"
#include "driverlib/pin_map.h"
#include "driverlib/timer.h"
#include "utils/uartstdio.h"
#include "utils/cmdline.h"
int i = 0;
int j = 0;
int k = 0;
int l = 0;
int GPIOarrays[];
int TimerFlag = 0;
int main(void)
{
unsigned long ulPeriod;
//Clock & Ports
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //zet kloksnelheid op 40mhz
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//LEDs
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//Interrupt
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
IntPrioritySet(INT_GPIOF, GPIO_PIN_4);
GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE);
GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_4);
IntEnable(INT_GPIOF);
//Set LEDs off
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0x0F);
//Timer
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_ONE_SHOT);
ulPeriod = (SysCtlClockGet()/2);
TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod -1);
//UART
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTStdioInit(0);
UARTprintf("UART Shoutbox:");
UARTprintf("\n");
IntMasterEnable();
while(1){}
}
void Timer0IntHandler(void){
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerFlag = 0;
}
void TimerDelay(void){
TimerFlag = 1;
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntEnable(INT_TIMER0A);
TimerEnable(TIMER0_BASE, TIMER_A);
IntMasterEnable();
}
void Counter(void){
if(i == 8){
if(TimerFlag == 0){
for(j=1; j<=i; j++){
UARTprintf("%i", GPIOarrays[j]);
}
UARTprintf("\n");
TimerDelay();
}
i = 0;
}else{
i++;
}
}
void PortFIntHandler(void){
SysCtlDelay(40000);
Counter();
if(TimerFlag == 1){
TimerDelay();
}else{
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4)){
GPIOarrays[i] = 1;
}else{
GPIOarrays[i] = 0;
}
}
GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_4);
}
The signal I'm receiving:
The UART data I'm getting (have set a symbol '-' to show the timer):
Although I keep the button pressed, it does keep sending the number instead of resetting and restarting the timer!
I've changed prolonged the timer up to a second without change so I wonder if this could be something else that I'm not seeing? (Watchdog Timer or so..?)
Kind regards,
Bart