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.

TM4C1294NCPDT: Setting GPIO outputs doesn't work properly

Hi

If I try to enable PD0, PD1, PD2 and PD3  and PK0, PK1, PK2 and PK3 as outputs, only PD0 and PK0 works:

(in void EK_TM4C1294XL_initGPIO(void) ):

GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

I did in EK_TM4C1294XL.h:

typedef enum EK_TM4C1294XL_GPIOName {
EK_TM4C1294XL_D1 = 0,
EK_TM4C1294XL_D2,
EK_TM4C1294XL_USR_SW1,
EK_TM4C1294XL_USR_SW2,

TIO_ENTRADA_I1,
TIO_ENTRADA_I2,
TIO_ENTRADA_I3,
TIO_ENTRADA_I4,
TIO_ENTRADA_I5,
TIO_ENTRADA_I6,
TIO_ENTRADA_I7,
TIO_ENTRADA_I8,


TIO_SAIDA_O1,
TIO_SAIDA_O2,
TIO_SAIDA_O3,
TIO_SAIDA_O4,
TIO_SAIDA_O5,
TIO_SAIDA_O6,
TIO_SAIDA_O7,
TIO_SAIDA_O8,

EK_TM4C1294XL_GPIOCOUNT
} EK_TM4C1294XL_GPIOName;

I did in EK_TM4C1294XL.c:

const GPIO_Config GPIO_config[] = {
{&gpioHWAttrs[0]},
{&gpioHWAttrs[1]},
{&gpioHWAttrs[2]},
{&gpioHWAttrs[3]},

{&gpioHWAttrs[4]},
{&gpioHWAttrs[5]},
{&gpioHWAttrs[6]},
{&gpioHWAttrs[7]},
{&gpioHWAttrs[8]},
{&gpioHWAttrs[9]},
{&gpioHWAttrs[10]},
{&gpioHWAttrs[11]},

{&gpioHWAttrs[12]},
{&gpioHWAttrs[13]},
{&gpioHWAttrs[14]},
{&gpioHWAttrs[15]},
{&gpioHWAttrs[16]},
{&gpioHWAttrs[17]},
{&gpioHWAttrs[18]},
{&gpioHWAttrs[19]},

{NULL}
};

If I try ( ON or OFF ):

GPIO_write(TIO_SAIDA_O1 , TIO_OUT_ON);    //works
GPIO_write(TIO_SAIDA_O2 , TIO_OUT_ON);    // no
GPIO_write(TIO_SAIDA_O3 , TIO_OUT_ON);    // no
GPIO_write(TIO_SAIDA_O4 , TIO_OUT_ON);    // no
GPIO_write(TIO_SAIDA_O5 , TIO_OUT_ON);    //works
GPIO_write(TIO_SAIDA_O6 , TIO_OUT_ON);    // no
GPIO_write(TIO_SAIDA_O7 , TIO_OUT_ON);    // no
GPIO_write(TIO_SAIDA_O8 , TIO_OUT_ON);    // no

Any ideas about?

Thanks

Sergio

  • Hello Sergio,

    What is GPIO_write? Please note that the GPIO Data Register has bit banding and hence if you write to the 0x0 register then only Pin-0 will toggle. Instead do it to 0x3FC offset

    Regards
    Amit
  • Hi Amit

    GPIO_write is a function from driverlib from TI-RTOS.

    All examples from driver samples have:

    /* Turn on user LED */
    GPIO_write(Board_LED0, Board_LED_ON);

    Could you point an example of GPIO use under TI-RTOS that uses other GPIOs as output other than used as LEDs?

    When you say to do to 0x3FC offset, how to do that? I don't know nothing about bit-banding yet.

    Thanks

    Sergio
  • Hello Sergio,

    I think based on the TI-RTOS usage it should be

    GPIO_write(0, 0x1) for Pin-0
    GPIO_write(1, 0x2) for Pin-1
    GPIO_write(2, 0x4) for Pin-2
    GPIO_write(3, 0x8) for Pin-3

    As for the bit banded approach, it is described in the data sheet

    Regards,
    Amit
  • Hi Amit

    GPIO_write() code follows ( ..ti/drivers/gpio/GPIOTiva.c ):

    /*
    * ======== GPIO_write ========
    */
    void GPIO_write(unsigned int index, uint32_t value)
    {
    unsigned int key;
    GPIO_HWAttrs const *attrs;

    Assert_isTrue(GPIO_count >= 0 && (int)index < GPIO_count, NULL);
    Assert_isTrue(GPIO_config[index].hwAttrs->direction == GPIO_OUTPUT, NULL);

    attrs = GPIO_config[index].hwAttrs;

    key = Hwi_disable();

    GPIOPinWrite(attrs->port, attrs->pin, value);

    Hwi_restore(key);

    Log_print3(Diags_USER1, "GPIO: port 0x%x, pin 0x%x wrote 0x%x",
    attrs->port, attrs->pin, value);
    }

    So, your suggestion will not work. The index will point to a struct member defined in gpioHWAttrs.

    What is very strange, is the fact that the following code works:

    GPIO_write( Board_LED1 , Board_LED_OFF ); //works
    GPIO_write( Board_LED1 , Board_LED_ON ); // works
    GPIO_write(Board_LED0, Board_LED_ON); // works ( it is heartbeat blink led on board )

    The above GPIO pins configuration were defined in driver examples by CCSv6 by default. What I did was replicate the same procedure in other pins. If there is a bit-banding issue, the commands above should not work on LED1 ( LED0 is used for heartbeat blink ).

    So, I really don't understand what is going on in my design.

    I did a piggy-back board that plugs into Launchpad TM4C1294XL board. I defined 8 inputs ( using tactile switches ) and 8 outputs ( LEDs ).

    All inputs works perfectly. Only the outputs shows that strange behaviour ( only BIT0 works on GPIO D and GPIO K).

    I will revise all my code again.

    If you have any suggestion, it will welcome.

    Thanks.

    Sergio
  • Hello Sergio

    GPIO_write uses GPIOPinWrite which requires that the Pin Value be the same as the Pin Number when one pin is being toggled. If instead of using GPIO_write you use GPIOPinWrite with the Pin Number and Pin value as the same it will toggle.

    Regards
    Amit
  • Hi Amit

    You are right.

    Reading the EK_TM4C1294XL.h file, I found this piece of code:

    /* LEDs on EK_TM4C1294XL are active high. */
    #define EK_TM4C1294XL_LED_OFF ( 0)
    #define EK_TM4C1294XL_LED_ON (~0)

    Look that when I want to turn on the LED, I need to send (~0 = 0xFF if char ), not 0x01, as I was doing.

    So, I replaced my I/O state definition using the same as above and all are working now.

    I am "digesting" the information still, to understand why must be (~0), but, now I can go forward.

    Thank you very much.

    Sergio