Tool/software: Code Composer Studio
I have been using this code to detect the moment when SW1 (PJ0) button is pressed, it works well.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_nvic.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
int val = 0, intcase = 0;
uint32_t sysclock_T;
void button_press(void)
{
if(intcase == 0)
{
TimerEnable(TIMER1_BASE, TIMER_A);
intcase = 1;
}
else
{
TimerDisable(TIMER1_BASE, TIMER_A);
intcase = 0;
val = 0;
}
GPIOIntClear(GPIO_PORTJ_BASE,GPIO_INT_PIN_0);
}
void Timer1IntHandler(void)
{
ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
val++;
}
int main(void) {
sysclock_T = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER1_BASE, TIMER_A, (sysclock_T/(1000000*2)));
IntEnable(INT_TIMER1A);
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_1);//Led init
GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE,GPIO_PIN_0);//button init
GPIOIntTypeSet(GPIO_PORTJ_BASE,GPIO_PIN_0,GPIO_BOTH_EDGES);
GPIOIntRegister(GPIO_PORTJ_BASE,button_press);
GPIOIntEnable(GPIO_PORTJ_BASE,GPIO_INT_PIN_0);
GPIOPadConfigSet(GPIO_PORTJ_BASE,GPIO_PIN_0,GPIO_STRENGTH_6MA, GPIO_PIN_TYPE_STD_WPU);
while(1)
{
}
}
But I want to have the input pin in low (0) and detect when a rising edge comes using PD2, my code for that is this:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_nvic.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
int val = 0, intcase = 0;
uint32_t sysclock_T;
void button_press(void)
{
if(intcase == 0)
{
TimerEnable(TIMER1_BASE, TIMER_A);
intcase = 1;
}
else
{
TimerDisable(TIMER1_BASE, TIMER_A);
intcase = 0;
val = 0;
}
GPIOIntClear(GPIO_PORTD_BASE,GPIO_INT_PIN_2);
}
void Timer1IntHandler(void)
{
ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt.
val++;
}
int main(void) {
sysclock_T = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);//led clock GPIO init
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER1_BASE, TIMER_A, (sysclock_T/(1000000*2)));
IntEnable(INT_TIMER1A);
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_1);//Led init
GPIOPinTypeGPIOInput(GPIO_PORTD_BASE,GPIO_PIN_2);//button init
//interrupt set-up
GPIOIntTypeSet(GPIO_PORTD_BASE,GPIO_PIN_2,GPIO_RISING_EDGE);
GPIOIntRegister(GPIO_PORTD_BASE,button_press);
GPIOIntEnable(GPIO_PORTD_BASE,GPIO_INT_PIN_2);
GPIOPadConfigSet(GPIO_PORTD_BASE,GPIO_PIN_2,GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0x0);
IntMasterEnable();
while(1)
{
}
}
the problem is that PD2 always begin in high, even if I use "GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_2, 0x0); ", How can I make this input begin in low????
thanks