This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

how to controll sw1 and sw2 on board tm4c123gxl to controll RGB LED

Hi.

i'm tring to controll RGB LED on board by SW1 and SW2. i know that SW2 is connected to PF0 and SW1 is connected to PF4. 

RGB LED is connected to PF1-PF3. 

i attached my code here, any advice of resolving the problem will be thankfull.

int main(void)
{

uint8_t ui8LED =8;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);

while(1)
{
// Make SW2 and SW1 rissing edge triggerd interrupt
GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_0|GPIO_PIN_4, GPIO_RISING_EDGE);
// Read the current state of SW2 and SW1
GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, ui8LED);
SysCtlDelay(2000000);
if (ui8LED == 2) {ui8LED =4;} else {ui8LED = ui8LED*2;}

}
}
}

  • Hello Shlomi

    Note that the SW1 and SW2 are switches to GND. So they need to have Pull Up in the normal rest state.

    You would have to use the GPIO PUR register to enable the Pull Up to the 2 GPIOs of PF0 and PF4.

    With the Pull Up enabled in rest state and in pressed state the pin connected to GND, you may now use the interrupt edge detection for the 2 GPIOs to preform the neccessary task.

    Regards
    Amit
  • Hi Amit,

    Might it make some sense to add the "misfortune" experienced by "PF0" (locked by default to NMI) and its, "brother in crime" (PD7) - cast to the same fate?

    Also - KISS would dictate that poster "not" tie his beginning code to interrupts.   Far simpler, loop on the designated GPIO input pins, would more quickly - and far easier - confirm poster's (port) input reads & output writes.   Once "test/verified" (and after unlocking) the "shrunken" battle-field may move to interrupts...

  • Hello cb1

    Yes, that is true, but looking at the code structure where an interrupt was being mentioned, I thought that in line of continuation, the same may be used. But surely, the locked pin needs to be addressed

    e2e.ti.com/.../374640

    Regards
    Amit