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.

Problem with enable UART1 TIVA-C

Other Parts Discussed in Thread: TM4C123GH6PM

Hello,

I need to use UART1 to send AT command to Sim800A module but it doesn't work. I know it because I didn't receive the message from my sim module. I need your help, I have to finish this project at the end of the week. It's urgent. This is my code:

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

void Delay_ms(int t)
{
SysCtlDelay(SysCtlClockGet()/(3*1000/t));
}

void sendStr(char *str)
{
while(*str)
{
UARTCharPut(UART1_BASE,*str);
str++;
}
}

int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PCTL_PB0_U1RX);
GPIOPinConfigure(GPIO_PCTL_PB1_U1TX);
GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART1_BASE,SysCtlClockGet(),9600,(UART_CONFIG_WLEN_8 |UART_CONFIG_STOP_ONE|UART_CONFIG_PAR_NONE));
sendStr("AT\n");
Delay_ms(200);
sendStr("AT+CMGF=1\n");
Delay_ms(200);
sendStr("AT+CMGS=\"0944353095\"\n");
Delay_ms(200);
sendStr("abcde\n");
Delay_ms(200);
UARTCharPutNonBlocking(UART1_BASE,26);
Delay_ms(200);
}

  • You have the wrong constant in the calls to GPIOPinCongure().

     GPIOPinConfigure(GPIO_PB0_U1RX);
     GPIOPinConfigure(GPIO_PB1_U1TX);
    

  • Thanks for your answer Bob Crosby , I have checked the gpio.h library and I can't find the constants "GPIO_PB0_U1RX" or "GPIO_PB1_U1TX". It worked with UART0 (GPIO_PCTL_PA0_U0RX and GPIO_PCTL_PA1_U0TX) but when I changed to UART1, it didn't work. I don't think those constants are my problem.
  • Those defines are on lines 8074 and 8077 of the file "C:\ti\TivaWare_C_Series-2.1.4.178\driverlib\pin_map.h". Perhaps you have the wrong include paths and are picking up a different version of "pin_map.h". I actually made the change to you code and ran it. I saw the UART1 output on a scope.

  • One suspects that poster's use of, "Project0" as just described & well illustrated (here today) at:

    https://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/588037

    would have prevented his misfortune!     And will enable his quick/efficient correction...

  • Thank you so much Bob Crosby, it works now. I'm a newbie, those libraries make me confused. When I used the constants in pin_map.h, there are errors like "GPIO_PB0_U1RX is undefined". I have to predefine symbol "PART_TM4C123GH6PM" in my project properties to make it work. I don't understand why I have to do that. I thougt when I create a project with TM4C123GH6PM, it's already defined the name. Could you explain this to me please? Anyway, thank you again.
  • Cb1 raises, cocks pistol...few so (blind) as those who will not see...
  • I am not sure what happened. When I created a new project (File -> New -> CCS Project) and selected TM4C123GH6PM as the target, it did create a predefined symbol PART_TM4C123GH6PM. I then had to set the include path and the library file for the TivaWare driver library, but it then built correctly. As CB1 suggested, I almost always start by importing an existing project such as "project0" from the TivaWare examples.