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.

Compiler/TM4C123GH6PM: Facing problem with UART1.

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Tool/software: TI C/C++ Compiler

I have written the code on Keil uVision4, I'm trying to use #UART1. But I'm unable to find the mistake in my code written below. I've have also used the same code with some required changes in  the values of Registers and replacing #UART1 with #UART0 (earlier used UAT0),  for blinking the LED on #PortF. That code worked good.

But now, I'm facing problems with UART1 and don't understand what the problem is in the code. I think I'm doing wrong with the Register 

GPIOD->PCTL = (GPIOB->PCTL&0xFFFFFF00)+0x00000040; //GPIO PORTB 0-1

Please guide me, for now I'm trying to use UART1 for blinking LED on PortF because I want to interface GSM with TM4C123GH6PM launchpad as there are no external Pins for Rx and Tx of UART0, that's why I want to use UART1 with Rx and Tx on Pins PB0 and PB1. 

#include <stdint.h>

#include <TM4C123GH6PM.H>

 

void PLL_Init(void);

void UART1_Init(void);

void PortF_Init(void);

void UartWrite(char *pstr);

unsigned char Receiver(void);

void Transmitter(unsigned char data);

 

int main(void){

    unsigned char command;

PLL_Init();                                    

    UART1_Init();                              

PortF_Init();

 

UartWrite("This program control LEDs on PortF through UART.\r\n");

 

    while(1)

    {

UartWrite("Enter Command \'0\',\'1\',\'2\',\'3\':");    

UartWrite("AT");       

                                          

        command = Receiver();

        Transmitter(command);

UartWrite("AT\r\n");

 

        switch (command){

            case '0':               

                            GPIOF->DATA = 0x00;

                            break;

            case '1':               

                            GPIOF->DATA = 0x02;

                            break;

            case '2':               

                            GPIOF->DATA = 0x04;

                            break;

            case '3':               

                            GPIOF->DATA = 0x08;

                            break;

            default:

UartWrite("Wrong command ! \r\n");                           

                            break;

       

    }

 

}

void UART1_Init(void)

{

    SYSCTL->RCGCUART |= 0x00000002;   //UART1

    SYSCTL->RCGCGPIO |= 0x00000002;    //PORTB CLOCK ENABLE

    UART1->CTL &= ~0x00000002;             //UART1 DISABLE

    UART0->IBRD = 43;                                 //BAUD INTEGER

    UART1->FBRD = 26;                                 //BAUD FLOATING

    UART1->LCRH = 0x00000070;                 //ENABLE FEN & WLEN

    UART1->CTL |= 0x01;                            //UART ENABLE;

    GPIOB->AFSEL |= 0x03;                          // OTHER ALTERNATIVE FUNCTION AT PORTB 0-1

    GPIOB->DEN |= 0x02;                             // PORTB 0-1 OUTPUT

    GPIOB->PCTL = (GPIOB->PCTL&0xFFFFFF00)+0x00000040;        //GPIO PORTB 0-1

    GPIOB->AMSEL &= ~0x03;                     //ANALOG DISABLE

}

 

void PLL_Init(void)

{   

  SYSCTL->RCC2 |=  0x80000000; 

  SYSCTL->RCC2 |=  0x00000800; 

  SYSCTL->RCC = (SYSCTL->RCC &~0x000007C0) + 0x00000540;  

  SYSCTL->RCC2 &= ~0x00000070; 

  SYSCTL->RCC2 &= ~0x00002000; 

  SYSCTL->RCC2 |= 0x40000000;

  SYSCTL->RCC2 = (SYSCTL->RCC2&~ 0x1FC00000) + (4<<22);  

  while((SYSCTL->RIS&0x00000040)==0){};  

  SYSCTL->RCC2 &= ~0x00000800;

}

 

void PortF_Init(void)

{

  volatile unsigned long delay;

  SYSCTL->RCGC2 |= 0x00000020;    

  delay = SYSCTL->RCGC2; 

  GPIOF->AMSEL &= ~0x0E;     

  GPIOF->PCTL &= ~0x0000FFF0;                  

  GPIOF->DIR |= 0x0E;        

  GPIOF->AFSEL &= ~0x0E;        

  GPIOF->DEN |= 0x0E;        

}

 

void UartWrite(char *pstr){

    while(*pstr != 0)    {

        Transmitter(*pstr++);       

    }

}

unsigned char Receiver(void){

    while((UART1->FR&0x10) != 0){};

    return UART1->DR&0xFF;

}

void Transmitter(unsigned char data){

    while((UART1->FR&0x20) != 0){};

    UART1->DR = data;

}

  • Please download the TivaWare library and use the functions provided. The library functions and the examples in TivaWare greatly simplify the task of initializing the peripherals.

  • Sir I've learned Initializations this way only from my Teacher. I don't know how to use the Peripheral initialization/and peripheral library, I've already downloaded Tivaware Software and have read the peripherals library , but no use for me.
  • I've got a code related to my work below. but there are errors while compiling in the Keil Uvisio4. The errors are 31 below is there copy:
    Rebuild target 'Target 1'
    assembling startup_TM4C123.s...
    compiling system_TM4C123.c...
    compiling GSM[ERIPHERAL.c...
    GSM[ERIPHERAL.c(9): error: #20: identifier "NULL" is undefined
    static char *msgContent = NULL; // Message content holder
    GSM[ERIPHERAL.c(27): warning: #223-D: function "SysCtlPeripheralEnable" declared implicitly
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //Enable clock on UART2
    GSM[ERIPHERAL.c(27): error: #20: identifier "SYSCTL_PERIPH_UART2" is undefined
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //Enable clock on UART2
    GSM[ERIPHERAL.c(28): error: #20: identifier "SYSCTL_PERIPH_GPIOD" is undefined
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable clock on port D //PD6 and PD7 will be RX and TX to GSM module
    GSM[ERIPHERAL.c(29): warning: #223-D: function "SysCtlPeripheralReady" declared implicitly
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_UART2)); //wait for UART2 to initialize
    GSM[ERIPHERAL.c(30): warning: #223-D: function "SysCtlPeripheralReady" declared implicitly
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)); //wait for PortD to initialize
    GSM[ERIPHERAL.c(32): error: #20: identifier "GPIO_PORTD_LOCK_R" is undefined
    GPIO_PORTD_LOCK_R = 0x4C4F434B; //Unlock GPIO PD7
    GSM[ERIPHERAL.c(33): error: #20: identifier "GPIO_PORTD_CR_R" is undefined
    GPIO_PORTD_CR_R |= 0xC0; //Allow changes to PD6,7
    GSM[ERIPHERAL.c(35): warning: #223-D: function "IntDisable" declared implicitly
    IntDisable(INT_UART2);
    GSM[ERIPHERAL.c(35): error: #20: identifier "INT_UART2" is undefined
    IntDisable(INT_UART2);
    GSM[ERIPHERAL.c(36): warning: #223-D: function "UARTIntDisable" declared implicitly
    UARTIntDisable(UART2_BASE,UART_INT_RX|UART_INT_TX|UART_INT_RT); //Disable UART2 Interrupts
    GSM[ERIPHERAL.c(36): error: #20: identifier "UART_INT_RX" is undefined
    UARTIntDisable(UART2_BASE,UART_INT_RX|UART_INT_TX|UART_INT_RT); //Disable UART2 Interrupts
    GSM[ERIPHERAL.c(36): error: #20: identifier "UART_INT_TX" is undefined
    UARTIntDisable(UART2_BASE,UART_INT_RX|UART_INT_TX|UART_INT_RT); //Disable UART2 Interrupts
    GSM[ERIPHERAL.c(36): error: #20: identifier "UART_INT_RT" is undefined
    UARTIntDisable(UART2_BASE,UART_INT_RX|UART_INT_TX|UART_INT_RT); //Disable UART2 Interrupts
    GSM[ERIPHERAL.c(37): warning: #223-D: function "UARTDisable" declared implicitly
    UARTDisable(UART2_BASE); //Disable UART2 while configuration
    GSM[ERIPHERAL.c(39): warning: #223-D: function "GPIOPinConfigure" declared implicitly
    GPIOPinConfigure(GPIO_PD6_U2RX); //PCTL
    GSM[ERIPHERAL.c(39): error: #20: identifier "GPIO_PD6_U2RX" is undefined
    GPIOPinConfigure(GPIO_PD6_U2RX); //PCTL
    GSM[ERIPHERAL.c(40): error: #20: identifier "GPIO_PD7_U2TX" is undefined
    GPIOPinConfigure(GPIO_PD7_U2TX);
    GSM[ERIPHERAL.c(41): warning: #223-D: function "GPIOPinTypeUART" declared implicitly
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); //DIR, PAD,
    GSM[ERIPHERAL.c(41): error: #20: identifier "GPIO_PORTD_BASE" is undefined
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); //DIR, PAD,
    GSM[ERIPHERAL.c(41): error: #20: identifier "GPIO_PIN_6" is undefined
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); //DIR, PAD,
    GSM[ERIPHERAL.c(41): error: #20: identifier "GPIO_PIN_7" is undefined
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); //DIR, PAD,
    GSM[ERIPHERAL.c(43): warning: #223-D: function "UARTClockSourceSet" declared implicitly
    UARTClockSourceSet(UART2_BASE, UART_CLOCK_SYSTEM); //Set the clock source for UART2
    GSM[ERIPHERAL.c(43): error: #20: identifier "UART_CLOCK_SYSTEM" is undefined
    UARTClockSourceSet(UART2_BASE, UART_CLOCK_SYSTEM); //Set the clock source for UART2
    GSM[ERIPHERAL.c(44): warning: #223-D: function "UARTParityModeSet" declared implicitly
    UARTParityModeSet(UART2_BASE, UART_CONFIG_PAR_NONE);
    GSM[ERIPHERAL.c(44): error: #20: identifier "UART_CONFIG_PAR_NONE" is undefined
    UARTParityModeSet(UART2_BASE, UART_CONFIG_PAR_NONE);
    GSM[ERIPHERAL.c(45): warning: #223-D: function "UARTFIFOEnable" declared implicitly
    UARTFIFOEnable(UART2_BASE); //Enable the UART FIFO
    GSM[ERIPHERAL.c(46): warning: #223-D: function "UARTStdioConfig" declared implicitly
    UARTStdioConfig(GSM_UART_PORT, GSM_BAUD_RATE, SysCtlClockGet());
    GSM[ERIPHERAL.c(46): warning: #223-D: function "SysCtlClockGet" declared implicitly
    UARTStdioConfig(GSM_UART_PORT, GSM_BAUD_RATE, SysCtlClockGet());
    GSM[ERIPHERAL.c(47): warning: #223-D: function "UARTEchoSet" declared implicitly
    UARTEchoSet(false);
    GSM[ERIPHERAL.c(47): error: #20: identifier "false" is undefined
    UARTEchoSet(false);
    GSM[ERIPHERAL.c(48): warning: #223-D: function "UARTIntRegister" declared implicitly
    UARTIntRegister(UART2_BASE,&UARTStdioIntHandler);
    GSM[ERIPHERAL.c(48): error: #20: identifier "UARTStdioIntHandler" is undefined
    UARTIntRegister(UART2_BASE,&UARTStdioIntHandler);
    GSM[ERIPHERAL.c(49): warning: #223-D: function "UARTConfigGetExpClk" declared implicitly
    UARTConfigGetExpClk(UART2_BASE, SysCtlClockGet(), &GSM_Baud_Rate_Read, &uart_config_read); //Get the Baud Rate
    GSM[ERIPHERAL.c(49): error: #20: identifier "GSM_Baud_Rate_Read" is undefined
    UARTConfigGetExpClk(UART2_BASE, SysCtlClockGet(), &GSM_Baud_Rate_Read, &uart_config_read); //Get the Baud Rate
    GSM[ERIPHERAL.c(57): warning: #223-D: function "UARTprintf" declared implicitly
    UARTprintf("AT+CMGF=%u\r\n",1); //message format text
    GSM[ERIPHERAL.c(58): warning: #223-D: function "SysCtlDelay" declared implicitly
    SysCtlDelay(Millis2Ticks(100)); //Interrupts are NOT disabled and OS is NOT stoped during delay!
    GSM[ERIPHERAL.c(58): warning: #223-D: function "Millis2Ticks" declared implicitly
    SysCtlDelay(Millis2Ticks(100)); //Interrupts are NOT disabled and OS is NOT stoped during delay!
    GSM[ERIPHERAL.c(59): warning: #223-D: function "GSMgetResponse" declared implicitly
    lineCount = GSMgetResponse();
    GSM[ERIPHERAL.c(53): warning: #550-D: variable "lineCount" was set but never used
    uint8_t lineCount = 0;
    GSM[ERIPHERAL.c(54): warning: #177-D: variable "i" was declared but never referenced
    uint16_t i = 0;
    GSM[ERIPHERAL.c(55): warning: #177-D: variable "uart2_dump" was declared but never referenced
    uint8_t uart2_dump[1024] = "";
    GSM[ERIPHERAL.c(78): error: #20: identifier "bool" is undefined
    bool msgPresent = 0; // Flag to ignore deleted messages
    GSM[ERIPHERAL.c(83): warning: #223-D: function "UARTprintf" declared implicitly
    UARTprintf("AT+CMGR=%u\r\n",msgNum); //read request for msgNum
    GSM[ERIPHERAL.c(84): warning: #223-D: function "SysCtlDelay" declared implicitly
    SysCtlDelay(Millis2Ticks(10));
    GSM[ERIPHERAL.c(84): warning: #223-D: function "Millis2Ticks" declared implicitly
    SysCtlDelay(Millis2Ticks(10));
    GSM[ERIPHERAL.c(87): warning: #223-D: function "GSMgetResponse" declared implicitly
    lineCount = GSMgetResponse();
    GSM[ERIPHERAL.c(90): warning: #223-D: function "GSMparseMessage" declared implicitly
    msgPresent = GSMparseMessage(lineCount);
    GSM[ERIPHERAL.c(93): warning: #223-D: function "PC_Display_Message" declared implicitly
    PC_Display_Message("\n\r>>> MESSAGE :",msgNum," ");
    GSM[ERIPHERAL.c(108): error: #159: declaration is incompatible with previous "GSMgetResponse" (declared at line 59)
    uint8_t GSMgetResponse(void) {
    GSM[ERIPHERAL.c(109): error: #20: identifier "bool" is undefined
    bool readResponse = true; // Keeps the loop open while getting message
    GSM[ERIPHERAL.c(109): error: #20: identifier "true" is undefined
    bool readResponse = true; // Keeps the loop open while getting message
    GSM[ERIPHERAL.c(114): warning: #223-D: function "PC_Display_Message" declared implicitly
    PC_Display_Message("> Started message reading", 0," ");
    GSM[ERIPHERAL.c(118): warning: #223-D: function "UARTRxBytesAvail" declared implicitly
    if(UARTRxBytesAvail() > 2) UARTgets(g_cInput,sizeof(g_cInput));
    GSM[ERIPHERAL.c(118): warning: #223-D: function "UARTgets" declared implicitly
    if(UARTRxBytesAvail() > 2) UARTgets(g_cInput,sizeof(g_cInput));
    GSM[ERIPHERAL.c(120): warning: #223-D: function "strcpy" declared implicitly
    strcpy(responseLine[readLine],g_cInput/*GSMresponse*/);
    GSM[ERIPHERAL.c(124): warning: #223-D: function "strncmp" declared implicitly
    if((strncmp(responseLine[readLine],"OK",2)==0)||
    GSM[ERIPHERAL.c(126): error: #20: identifier "false" is undefined
    readResponse = false;
    GSM[ERIPHERAL.c(140): error: #20: identifier "bool" is undefined
    bool GSMparseMessage(uint8_t lineCount) {
    GSM[ERIPHERAL.c(148): warning: #223-D: function "PC_Display_Message" declared implicitly
    PC_Display_Message("Processed line: ",activeLine,responseLine[activeLine]);
    GSM[ERIPHERAL.c(151): warning: #223-D: function "strstr" declared implicitly
    if ( strstr(responseLine[activeLine],"+CMGR:") != '\0' ) //if message received
    GSM[ERIPHERAL.c(157): warning: #223-D: function "strtok" declared implicitly
    msgSender = strtok(msgEnvelope,","); // Go to first comma, skipping status
    GSM[ERIPHERAL.c(157): error: #513: a value of type "int" cannot be assigned to an entity of type "char *"
    msgSender = strtok(msgEnvelope,","); // Go to first comma, skipping status
    GSM[ERIPHERAL.c(158): error: #513: a value of type "int" cannot be assigned to an entity of type "char *"
    msgSender = strtok(NULL,","); // Grab the number
    GSM[ERIPHERAL.c(162): error: #513: a value of type "int" cannot be assigned to an entity of type "char *"
    msgDate = strtok(NULL,","); // Go to next comma, skipping phonebook entry
    GSM[ERIPHERAL.c(163): error: #513: a value of type "int" cannot be assigned to an entity of type "char *"
    msgDate = strtok(NULL,","); // Grab the date
    GSM[ERIPHERAL.c(167): error: #513: a value of type "int" cannot be assigned to an entity of type "char *"
    msgTime = strtok(NULL,","); // Grab the time
    GSM[ERIPHERAL.c: 37 warnings, 30 errors
    compiling uart.c...
    C:\ti\TivaWare_C_Series-2.1.4.178\driverlib\uart.c(49): error: #5: cannot open source input file "inc/hw_ints.h": No such file or directory
    #include "inc/hw_ints.h"
    C:\ti\TivaWare_C_Series-2.1.4.178\driverlib\uart.c: 0 warnings, 1 error
    ".\gsm_peripherAL.axf" - 31 Error(s), 37 Warning(s).
    Target not created





    Here is the code :

    #include <stdint.h>
    #include <TM4C123GH6PM.H>
    void UART2_Init(void);
    void PowerOnGSM(void);
    void GSMprocessMessage(uint8_t msgNum);

    // Data from most recent incoming message stored here
    char responseLine[10][160]; // Use to store UART inputs
    static char *msgContent = NULL; // Message content holder
    static char *msgSender = NULL; // Message sender
    static char *msgDate = NULL; // Message date
    static char *msgTime = NULL; // Message time

    #define BAUD_RATE (115200)
    #define GSM_BAUD_RATE (115200)
    #define GSM_UART_PORT (2)
    #define UART2_INT_PRIO (2)


    int main(void){


    }

    void UART2_Init(void){
    uint32_t uart_config_read = 0;
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2); //Enable clock on UART2
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); //Enable clock on port D //PD6 and PD7 will be RX and TX to GSM module
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_UART2)); //wait for UART2 to initialize
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOD)); //wait for PortD to initialize

    GPIO_PORTD_LOCK_R = 0x4C4F434B; //Unlock GPIO PD7
    GPIO_PORTD_CR_R |= 0xC0; //Allow changes to PD6,7

    IntDisable(INT_UART2);
    UARTIntDisable(UART2_BASE,UART_INT_RX|UART_INT_TX|UART_INT_RT); //Disable UART2 Interrupts
    UARTDisable(UART2_BASE); //Disable UART2 while configuration

    GPIOPinConfigure(GPIO_PD6_U2RX); //PCTL
    GPIOPinConfigure(GPIO_PD7_U2TX);
    GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7); //DIR, PAD,

    UARTClockSourceSet(UART2_BASE, UART_CLOCK_SYSTEM); //Set the clock source for UART2
    UARTParityModeSet(UART2_BASE, UART_CONFIG_PAR_NONE);
    UARTFIFOEnable(UART2_BASE); //Enable the UART FIFO
    UARTStdioConfig(GSM_UART_PORT, GSM_BAUD_RATE, SysCtlClockGet());
    UARTEchoSet(false);
    UARTIntRegister(UART2_BASE,&UARTStdioIntHandler);
    UARTConfigGetExpClk(UART2_BASE, SysCtlClockGet(), &GSM_Baud_Rate_Read, &uart_config_read); //Get the Baud Rate
    }

    void PowerOnGSM(void){
    uint8_t lineCount = 0;
    uint16_t i = 0;
    uint8_t uart2_dump[1024] = "";

    UARTprintf("AT+CMGF=%u\r\n",1); //message format text
    SysCtlDelay(Millis2Ticks(100)); //Interrupts are NOT disabled and OS is NOT stoped during delay!
    lineCount = GSMgetResponse();

    UARTprintf("AT+CSDH=%u\r\n",0); //do not show complete message header
    SysCtlDelay(Millis2Ticks(100));
    lineCount = GSMgetResponse();

    UARTprintf("AT+CNMI=%u%u%u%u%u\r\n",0,0,0,0,1); //set new message indication mode
    //Messages are stored on GSM module, no indication is provided
    //AT+CMGR=msgNum will read the messages when user triggers GSMprocessMessage(msgNum)
    SysCtlDelay(Millis2Ticks(100));
    lineCount = GSMgetResponse();
    }

    //*****************************************************************************
    //
    // PROCESS SMS FOR ENVELOPE AND CONTENT
    //
    //*****************************************************************************
    void GSMprocessMessage(uint8_t msgNum) {
    bool msgPresent = 0; // Flag to ignore deleted messages
    int lineCount=0; // Hold the number of lines


    // Request the message and get the lines of the response (includes envelope, nulls, SIM responses)
    UARTprintf("AT+CMGR=%u\r\n",msgNum); //read request for msgNum
    SysCtlDelay(Millis2Ticks(10));

    // Start message retrieval
    lineCount = GSMgetResponse();

    // Make sure there's message content, process for envelope and content
    msgPresent = GSMparseMessage(lineCount);

    // Show the user what we found
    PC_Display_Message("\n\r>>> MESSAGE :",msgNum," ");
    if (msgPresent) {
    PC_Display_Message("> FROM: ",0,msgSender); //TODO: Try to send a BS to delete the 0
    PC_Display_Message("> AT:",0,msgDate);
    PC_Display_Message("> ON: ",0,msgTime);
    PC_Display_Message("> TEXT :",0,msgContent);
    }
    else PC_Display_Message("> NOT PRESENT!",0," ");
    }

    //*****************************************************************************
    //
    // STORE A GSM RESPONSE TO ARRAY responseLine[]
    //
    //*****************************************************************************
    uint8_t GSMgetResponse(void) {
    bool readResponse = true; // Keeps the loop open while getting message
    int readLine = 0; // Counts the lines of the message
    char *GSMresponse = NULL; // Use to grab input
    char g_cInput[128]; // String input to a UART

    PC_Display_Message("> Started message reading", 0," ");
    while(readResponse&&(readLine<10)) { //TODO, do not hardcode, use macro
    // Grab a line
    //UART2_GetString(g_cInput,sizeof(g_cInput)); //grabs string untill character != CR or LF
    if(UARTRxBytesAvail() > 2) UARTgets(g_cInput,sizeof(g_cInput));
    // Stop after newline
    strcpy(responseLine[readLine],g_cInput/*GSMresponse*/);
    //PC_Display_Message(">>> Line nr: ", readLine, g_cInput);
    //PC_Display_Message(">>> Line nr: ", readLine, responseLine[readLine]);
    // If this line says OK we've got the whole message
    if((strncmp(responseLine[readLine],"OK",2)==0)||
    (strncmp(responseLine[readLine],"ERROR",5)==0)){
    readResponse = false;
    }
    else readLine++;
    }
    return (readLine+1);
    }

    //*****************************************************************************
    //
    // PARSE GSM MESSAGE FOR ENVELOPE AND MESSAGE CONTENT
    // Stores message envelope and constant to global variables, OR returns true
    // for message present, false for no message
    //
    //*****************************************************************************
    bool GSMparseMessage(uint8_t lineCount) {
    uint8_t activeLine = 0; // Counter for line being processed
    char *msgEnvelope = NULL; // Message envelope holder

    msgContent = NULL; // Clear out the old message
    // Parse the new message
    while (activeLine < lineCount) //lineCount is larger by 1 than responseLine [index]
    {
    PC_Display_Message("Processed line: ",activeLine,responseLine[activeLine]);
    // CASE FOR ENVELOPE (which will look like:)
    // +CMGR: "REC READ","+40712334501","","17/04/12,22:53:48+12"
    if ( strstr(responseLine[activeLine],"+CMGR:") != '\0' ) //if message received
    {
    // Start parsing
    msgEnvelope = responseLine[activeLine];
    PC_Display_Message("> Envelope is: ",0,msgEnvelope);

    msgSender = strtok(msgEnvelope,","); // Go to first comma, skipping status
    msgSender = strtok(NULL,","); // Grab the number
    msgSender += 3; // Skip the prefix from the phone number and qautation marks
    msgSender[10] = '\0'; // Store the number (with null terminator)

    msgDate = strtok(NULL,","); // Go to next comma, skipping phonebook entry
    msgDate = strtok(NULL,","); // Grab the date
    msgDate += 1; //remove qautation marks
    msgDate[8] = '\0'; // Store the date (with null terminator)

    msgTime = strtok(NULL,","); // Grab the time
    msgTime[8] = '\0'; // Store the time (with null terminator)
    }

    // CASE FOR MESSAGE CONTENT
    // If we already found the envelope, and the line's not blank...
    else if (( msgEnvelope != NULL) && (responseLine[activeLine] != NULL))
    {
    // ... and we haven't found any content, this is the first line.
    if (msgContent == NULL) {msgContent = responseLine[activeLine];}

    // ... otherwise, add a space and append this line.
    else if ( activeLine+2 <= lineCount ) { //+2 because of emply line before OK and last line with OK.
    strcat(msgContent, " ");
    strcat(msgContent, responseLine[activeLine]);
    }
    }
    activeLine++; // Proceed to next line
    }
    if (msgEnvelope == NULL) { // If we didn't find an envelope, there's no message
    return false;
    }
    else { // Otherwise, return true.
    return true;
    }
    }
  • Hi,

     Some comments.

    ASIM MEHAR said:

    But now, I'm facing problems with UART1 and don't understand what the problem is in the code. I think I'm doing wrong with the Register 

    GPIOD->PCTL = (GPIOB->PCTL&0xFFFFFF00)+0x00000040; //GPIO PORTB 0-1

    1. Why are you assigning the value to GPIOD? 

    2. Why are you writing 0x00000040? See below pinmux in datasheet. You are selecting 4 as the alternate function for GPIOB[1] but there is nothing at for 4. You need to use 1. Same for GPIOB[0]. 

     

     

     3. On the launchpad the UART0 is used as a COM port to the PC. You can't use UART1 as a COM port.

     4. PortF[0] has special consideration if you want to use PortF[0]. Please see below.

     

      

      5. Lastly, you are using DRM instead of the provided TivaWare library. Please use TivaWare library to greatly speed up your software development. 

     

  • Can you build an execute this example from TivaWare?
    C:\ti\TivaWare_C_Series-2.1.4.178\examples\boards\ek-tm4c123gxl\hello

    This example uses UART0. If you get this example to work, then you can modify the function calls to use UART1 (make sure you also configure the proper port pins).
  • Would it not be (more) appropriate for such (instruction) to flow from the "teacher" - who directed use of the (always confounding) DRM?
    That's NEVER suggested - and (beyond) understanding...    (loss of 100 or so LPad Sales to a school appears inconsequential...)

    Is it not (beyond clear) that such "teachers" employ this forum as a "dumping ground" - is that what (alone) is being taught?     Can this be good?