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 GPIO simple read and write code

I am new to C and Tiva:

I have been using Arduino Uno to read a digital signal 1 or 0 and tried to translate it to Tiva. 

Am I doing this right? I looked up the driver peripheral library and get a programming example code which give me errors(in bold red)

the code is as follow:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_gpio.h"
#include "inc/hw_types.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"

//volatile int a;
uint8_t ui8PinData=1;

int main(void)
{
GPIOIntRegister(GPIO_PORTE_BASE, PortEIntHandler);
GPIOIntRegister(GPIO_PORTC_BASE, PortCIntHandler);

//the error say PortEIntHandler and PortCIntHandler are undefined)


SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);



GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_7);
GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4);
GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);

// Make pins 2 and 4 rising edge triggered interrupts.
//
GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4, GPIO_RISING_EDGE);
GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6, GPIO_RISING_EDGE);


GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_7, 0x00);
SysCtlDelay(10);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_7, ui8PinData);

GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4);
GPIOIntEnable(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);

while(1)
{

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2|GPIO_PIN_3, 0x00);
SysCtlDelay(10000000);

int32_t D0 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0);
int32_t D1 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1);
int32_t D2 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2);
int32_t D3 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3);
int32_t D4 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4);
int32_t D5 = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4);
int32_t D6 = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5);
int32_t D7 = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6);

SysCtlDelay(10000000);

GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, ui8PinData);
SysCtlDelay(10000000);

int32_t D10 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_0);
int32_t D11 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_1);
int32_t D12 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_2);
int32_t D13 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_3);
int32_t D14 = GPIOPinRead(GPIO_PORTE_BASE, GPIO_PIN_4);
int32_t D15 = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_4);
int32_t D16 = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_5);
int32_t D17 = GPIOPinRead(GPIO_PORTC_BASE, GPIO_PIN_6);

SysCtlDelay(10000000);
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_3, ui8PinData);
SysCtlDelay(10000000);
}
}

please help me, thanks

  • Maria Wahono said:
    GPIOIntRegister(GPIO_PORTE_BASE, PortEIntHandler);
    GPIOIntRegister(GPIO_PORTC_BASE, PortCIntHandler);

    At your main C file, where is PortEIntHandler and PortCIntHandler? 

    See, how interrupts is setup at one of the example programs such as interrupts, timer, and uart_echo example program. See, also the example program's startup file.

    - kel

  • so basically, do you mean I dont need to use the interrupt to read digital signal?

    or do i need to initialize the PortEIntHandler and PortCIntHandler?

     

    thanks

  • Hi Maria, Depends on you if you want to read gpio signals either polling or interrupt based. The problem with your code is your setting up interrupt at your initialization then at your while loop, you are implementing polling method. Search also in this forum for similar post. -kel
  • Hello Maria,

    1. Are you using the GPIOPinWrite function in the while loop to make the pins for the GPIOPinRead as 1?

    2. As Kel mentioned, if you are using the polling mechanism, then you should not be using interrupt!!!

    Regards

    Amit

  • Markel Robregado said:
    Hi Maria, Depends on you if you want to read gpio signals either polling or interrupt based. The problem with your code is your setting up interrupt at your initialization then at your while loop, you are implementing polling method. Search also in this forum for similar post. -ke

    I replied this using my iPhone. It seems that the text automatically becomes small.

    - kel

  • Hi Amit,

    Sorry for the delayed reply

    In detail, what I am trying to do is to make the Tiva board talking to a counter chip, which need SELect signal, OE signal, and RESET signal . All are active high except for reset. The counter chip will give a digital signal, 3-5Volt signal in 8 pins, as binary , to signifies the number it has been counting. for example the signal will be 00001101 which translate to count of 13. the ones are from the digital signal HIGH and 0 from digital signal LOW.

    1. No, I am trying to output 5 Volt to the pin I was writing, to send signal to the chip(as SEL signal / OE signal / RESET signal)

    2. Yes, I am sorry that I am not aware of that. 

    More questions:

    1. I hve been trying to get digital signal to be read in the GPIO without the interrupt, but it shows error : Error register: execution state prevented access. How exactly do I read digital signal then? Does GPIOPinRead Sufficient to do the task, or do i have to disable analog signal reading somewhere?

    Thank you very much for your replies

  • Hi Maria,

         Are you using Tiva Launchpad?

    Maria Wahono said:
    I hve been trying to get digital signal to be read in the GPIO without the interrupt, but it shows error : Error register: execution state prevented access. How exactly do I read digital signal then? Does GPIOPinRead Sufficient to do the task, or do i have to disable analog signal reading somewhere?

         Have you tried reading GPIO signal from the on-board switch? If you have not, just for learning, try reading GPIO signal from the on-board switches. Try either polling or interrupt based. 

         You can find posts in this forum that has code for reading on-board switches.

         If you are using Tivaware for Tiva Launchpad you can learn how to initialize the switches at buttons.c, which can be found at "\\drivers".

    -kel

  • Hello Maria

    1. The TM4C123 device will not put out 5V on the IO. It will do it at 3.3V. If you want to use 5V output from the device, then you need to put in open drain mode and connect an external pull up to 5V to the Pin.

    2. Can you please send a code post. that would be useful

    Regards

    Amit