I'm working on a project and for the moment am just trying to get GPIO working on my tiva c launchpad, and sometimes it seems to work and sometimes not.
Here is my current (relevant) code:
int
main(void)
{
//
// Run from the PLL at 120 MHz.
//
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
//
// The PWM peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
PortFunctionInit();
SysCtlDelay(10);
//
// Set the PWM clock to the system clock.
//
PWMClockSet(PWM0_BASE, PWM_SYSCLK_DIV_1);
//
// Configure the PWM0 to count down without synchronization.
//
PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_DOWN | PWM_GEN_MODE_NO_SYNC);
//
// Set the PWM period to 13kHz. To calculate the appropriate parameter
// use the following equation: N = (1 / f) * SysClk. Where N is the
// function parameter, f is the desired frequency, and SysClk is the
// system clock frequency.
// In this case you get: (1 / 13kHz) * 120MHz = 9231 cycles. Note that
// the maximum period you can set is 2^16.
//
PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, 9231);
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 7431);
GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_1 , GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
//
// Enable the PWM0 output signal (PD0).
//
PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT, true);
//
// Enables the PWM generator block.
//
PWMGenEnable(PWM0_BASE, PWM_GEN_0);
//GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 1);
//GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 1);
/*SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 7311);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 7191);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 7071);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6951);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6831);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6711);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6591);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6471);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6351);
SysCtlDelay((SysCtlClockGet()/(3))*741) ; //delay for 60 seconds, experimentally calculated
PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, 6231);*/
//GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_3, 1);
while(1)
{
if (GPIOPinRead(GPIO_PORTJ_BASE , GPIO_PIN_1) == 0)
{
GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1, 1);
}
else
{
GPIOPinWrite(GPIO_PORTN_BASE , GPIO_PIN_1, 0);
}
}
}
And here's the pinmux output file that it's loading in earlier:
void
PortFunctionInit(void)
{
//
// Enable Peripheral Clocks
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
//
// Enable pin PJ0 for GPIOInput
//
MAP_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0);
//
// Enable pin PJ1 for GPIOInput
//
MAP_GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_1);
//
// Enable pin PN1 for GPIOOutput
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
//
// Enable pin PN2 for GPIOOutput
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_2);
//
// Enable pin PN0 for GPIOOutput
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
//
// Enable pin PG0 for PWM0 M0PWM4
//
MAP_GPIOPinConfigure(GPIO_PG0_M0PWM4);
MAP_GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_0);
//
// Enable pin PF0 for PWM0 M0PWM0
//
MAP_GPIOPinConfigure(GPIO_PF0_M0PWM0);
MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0);
//
// Enable pin PF4 for PWM0 M0FAULT0
//
MAP_GPIOPinConfigure(GPIO_PF4_M0FAULT0);
MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_4);
//
// Enable pin PK4 for PWM0 M0PWM6
//
MAP_GPIOPinConfigure(GPIO_PK4_M0PWM6);
MAP_GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_4);
//
// Enable pin PG1 for PWM0 M0PWM5
//
MAP_GPIOPinConfigure(GPIO_PG1_M0PWM5);
MAP_GPIOPinTypePWM(GPIO_PORTG_BASE, GPIO_PIN_1);
//
// Enable pin PL0 for PWM0 M0FAULT3
//
MAP_GPIOPinConfigure(GPIO_PL0_M0FAULT3);
MAP_GPIOPinTypePWM(GPIO_PORTL_BASE, GPIO_PIN_0);
//
// Enable pin PK5 for PWM0 M0PWM7
//
MAP_GPIOPinConfigure(GPIO_PK5_M0PWM7);
MAP_GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_5);
//
// Enable pin PF2 for PWM0 M0PWM2
//
MAP_GPIOPinConfigure(GPIO_PF2_M0PWM2);
MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_2);
//
// Enable pin PF1 for PWM0 M0PWM1
//
MAP_GPIOPinConfigure(GPIO_PF1_M0PWM1);
MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_1);
//
// Enable pin PK6 for PWM0 M0FAULT1
//
MAP_GPIOPinConfigure(GPIO_PK6_M0FAULT1);
MAP_GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_6);
//
// Enable pin PK7 for PWM0 M0FAULT2
//
MAP_GPIOPinConfigure(GPIO_PK7_M0FAULT2);
MAP_GPIOPinTypePWM(GPIO_PORTK_BASE, GPIO_PIN_7);
//
// Enable pin PF3 for PWM0 M0PWM3
//
MAP_GPIOPinConfigure(GPIO_PF3_M0PWM3);
MAP_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_3);
}
I'm trying to figure out why none of the other LEDs are lighting up aside from led4 (PF_0, PWM) - have I defined something incorrectly?
What should be happening is that if I push SW2, PJ_1 is tied to ground and N1 gets written high, which would turn on LED1, but nothing happens.
I'd appreciate another set of eyes looking this over!
Thanks
Garrett