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/TM4C129ENCPDT: Having problem with GPIO

Part Number: TM4C129ENCPDT

Tool/software: Code Composer Studio

In my project i want to change status of some pins, I have used PORT K firstly i can out my data to the pin number 0 of the PORT K, but when i am using other pins of the PORT K (eg: pin 1, pin 2,...) ther is no output at the pin. I have used the same steps which used for pin number 0 of PORT K to configure other pins of the PORT K 

My code is shown below please help me to find the trouble

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "drivers/pinout.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

uint32_t g_ui32SysClock;
void delay_2ms(uint32_t );
void supplyswitch(bool );
void adc3v3supply(bool );
void second3v3(bool stage);


#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif


void
ConfigureUART(void)
{

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, g_ui32SysClock);
}

//*****************************************************************************
//
// Print "Hello World!" to the UART on the Intelligent UART Module.
//
//*****************************************************************************
void ConfigGPIO(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
delay_2ms(100);
GPIOPinConfigure()
GPIOPinTypeGPIOOutput(GPIO_PORTH_BASE, GPIO_PIN_0|GPIO_PIN_1);
GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0);
delay_2ms(100);
}

int
main(void)
{
//
// Run from the PLL at 120 MHz.
//
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);

//
// Configure the device pins.
//
PinoutSet(false, false);

//
// Enable the GPIO pins for the LED D1 (PN1).
//
ConfigGPIO();
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);

//
// Initialize the UART.
//
ConfigureUART();


while(1)
{
//
// Turn on D1.
//
//ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0,true);
supplyswitch(1);
adc3v3supply(true);
second3v3(true);
LEDWrite(CLP_D1, 1);
UARTprintf("M0 High\r\n");

//
// Delay for a bit.
//
delay_2ms(1000);
//
// Turn off D1.
//
//ROM_GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0,false);
supplyswitch(0);
adc3v3supply(false);
second3v3(false);
LEDWrite(CLP_D1, 0);
UARTprintf("M0 Low\r\n");

//
// Delay for a bit.
//
delay_2ms(1000);
}
}

void delay_2ms(uint32_t delay)
{
// delay=delay/2;
SysCtlDelay(delay*40000);
return;
}

void supplyswitch(bool stage)
{
if(stage==true)
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0,true);

if(stage==false)
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_0,false);
}


void adc3v3supply(bool stage)
{
if(stage==true)
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0,true);

if(stage==false)
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0,false);
}


void second3v3(bool stage)
{
if(stage==true)
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_1,true);

if(stage==false)
GPIOPinWrite(GPIO_PORTH_BASE, GPIO_PIN_1,false);
}

After loading the program to the board i can find the output signal from the pin 0 of PORT H, but there is no output from the pin 1 of PORT H. The same is happening for all the other ports.

  • Hi,
    I only see you configure port K with the below line of code. In this case, only PK0 is configured for output and not other pins
    GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0);

    If you want to configure other pins of PK then you will something like below.
    GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 ); // Set both PK0 and PK1 to output pins

    GPIOPinWrite(GPIO_PORTK_BASE, (GPIO_PIN_0 | GPIO_PIN_1) ,GPIO_PIN_0 | GPIO_PIN_1); // Set PK0 and PK1 high

    Note you cannot do something like below to set both pins high. Not sure if this was your problem.
    GPIOPinWrite(GPIO_PORTK_BASE, (GPIO_PIN_0 | GPIO_PIN_1) ,true); // This will only set PK0 high, not PK1 as "true" means 0x1, not 0x3
  • I checked what u have said but my problem still remaining. Please check the below codes and plz help me to find what i have missed in my code.

    The First code working fine i can see the output at PORT K pin number 0.

    But in the second code(Code number 2) there is no output at pin number 1 of PORT K, i just changed the pin number from 0 to 1 in the second code.

    *********Code Number 1*********

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "drivers/pinout.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"


    uint32_t g_ui32SysClock;


    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif

    void
    ConfigureUART(void)
    {

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);


    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);


    UARTStdioConfig(0, 115200, g_ui32SysClock);
    }


    int
    main(void)
    {

    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_480), 120000000);


    PinoutSet(false, false);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
    SysCtlDelay(40000);
    GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0);


    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);


    ConfigureUART();


    UARTprintf("Hello, world!\n");

    while(1)
    {
    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0,true);
    SysCtlDelay(40000);
    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_0,false);
    SysCtlDelay(40000);
    }
    }


    ********Code Number 2***********

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_types.h"
    #include "driverlib/gpio.h"
    #include "drivers/pinout.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/rom.h"
    #include "driverlib/rom_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/uart.h"
    #include "utils/uartstdio.h"


    uint32_t g_ui32SysClock;


    #ifdef DEBUG
    void
    __error__(char *pcFilename, uint32_t ui32Line)
    {
    }
    #endif

    void
    ConfigureUART(void)
    {

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);


    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);


    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);


    UARTStdioConfig(0, 115200, g_ui32SysClock);
    }


    int
    main(void)
    {

    g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
    SYSCTL_CFG_VCO_480), 120000000);


    PinoutSet(false, false);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
    SysCtlDelay(40000);
    GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_1);


    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);


    ConfigureUART();


    UARTprintf("Hello, world!\n");

    while(1)
    {
    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1,true);
    SysCtlDelay(40000);
    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1,false);
    SysCtlDelay(40000);
    }
    }


    Please help to find a solution
  • I don't think you understood my comments in my last reply. Let me repeat my prior comment one more time.

    Note you cannot do something like below to set both pins high. Not sure if this was your problem.

    GPIOPinWrite(GPIO_PORTK_BASE, (GPIO_PIN_0 | GPIO_PIN_1) ,true); // This will only set PK0 high, not PK1 as "true" means 0x1, not 0x3

    If you want to set PK1 high you need to do below

    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1,GPIO_PIN_1); // This is correct

    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1,true); // This is incorrect

    Please ask yourself what is "true"? True means 0x1. 0x1 will only set PK0. PK1 is the second pin. To set PK1 you need to set 0x2. What if you want to set PK7? You need to write 0x80 to set PK7. You can not just write "true" to set any pins. Refer to the driver library description.