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.

CCS/EK-TM4C123GXL: Trying to control two leds with on board switches

Hello i am trying to control two LEDs with the switches located at PF0 and PF4, when i try to run my code only one switch works correctly, that is LED lights up when i press SW2,
the other LED stays lit for the whole time. I
I am confused whether the problem is in my code or circuit. 

Below is the code, i want to read from PF0 and PF4 and write to PD0 and PD1.

Thanks 

_______________________________________________________________________________________________________________________________________________


#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "inc/tm4c123gh6pm.h"
#include <stdio.h>

volatile uint32_t code;

void PORTD_Init (void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD))
    {};
    GPIO_PORTD_DEN_R= 0x03;
}

void PORTF_Init (void)
{
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF)){};
    GPIO_PORTF_LOCK_R= 0x4C4F434B;
    GPIO_PORTF_CR_R=0x11;
    GPIO_PORTF_PUR_R=0x11;
    GPIO_PORTF_DEN_R=0x11;
}



int main(void)
{
    PORTD_Init();
    PORTF_Init();
    GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0|GPIO_PIN_1);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);



    while(1)
    {

        code=GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0|GPIO_PIN_4);
        

        GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1,code);
        

    }
}



  • Two things my friend:
    a) using DRM code is inefficient - wastes time/effort - especially when a terrific API stands at the ready
    b) you do realize that PD0 & PD1 are tied to other MCU pins - thus challenging your efforts - do you not? (although that's on the LPad - may not have carried over to your board - as well...)

    To your far more readable API code:

    Raza Haider said:
    GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1,code);

    Note that variable "code" may assume a value (i.e. 0x10 or 0x11 or 0x00) which proves improper to drive PD1 on!     Your code would work if both PF and PD ... employed the same numeric pins - they do not...   (0x02) would provide an output high to PD1.

    Your choice of employing a "variable" (which violates KISS) rather than "hard-coded values" (which follows KISS) is what has, "Done you in."     (and is now easily corrected - but minus that variable!)

  • I am trying to make this work I tried to use the same numeric pin on port b, defining output LEDs on PB0 and $, this time one led completely stays off. 

    Please tell me when I use the GPIOPinRead API where does it return the read pins? I want to continuously watch the inputs on PF) and PF4 but I am unable to do so...

     please advise