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.

TM4C123GH6PM: Problem interfacing with GSM Modem with AT command

Part Number: TM4C123GH6PM


i would like to interface GSM SIM800 module with Tiva c series coordinator.

and to send AT commands to GSM module with uart of TM4C.i want to published MQTT data over GPRS using SIM800 and AT commands

if i send
"AT\r\n" I receive back

"AT"

OK
"\"AT+CSTT=\"BSNLNET\"\n\r\0" I receive back

"AT+CSTT="BSNLNE  expected

AT+CSTT="BSNLNET"     

OK

here is my code

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
//#include "inc/tm4c123gh6pm.h"
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/uart.h"

char ok[]="OK\r\n";

char receivechar[50];
int count=0;
int count1=0;
unsigned int i,j;

void UARTTransmitCommand( char *p)
{
while(*p!='\0')
{
ROM_UARTCharPutNonBlocking(UART1_BASE, *p);
p++;
}

ROM_IntEnable(INT_UART1);

}
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif

//*****************************************************************************

// The UART interrupt handler.
/************************************************************/
void
UART1IntHandler(void)
{

uint32_t ui32Status;
++count1;

//
// Get the interrrupt status.
//
ui32Status = ROM_UARTIntStatus(UART1_BASE, true);

//
// Clear the asserted interrupts.

ROM_UARTIntClear(UART1_BASE, ui32Status);


// Loop while there are characters in the receive FIFO.
//


while(ROM_UARTCharsAvail(UART1_BASE))
{
receivechar[count]=ROM_UARTCharGetNonBlocking(UART1_BASE);
ROM_UARTCharPutNonBlocking(UART0_BASE, receivechar[count]);

count++;
if(count==50);
count=0;

}

ROM_IntDisable(INT_UART1);
}
/********************************************************/
int
main(void)
{
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// //instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPUEnable();
ROM_FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);


//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Enable processor interrupts.
//
ROM_IntMasterEnable();

//
// Set GPIO B0 and B1 as UART pins.
//
GPIOPinConfigure(GPIO_PB0_U1RX);
GPIOPinConfigure(GPIO_PB1_U1TX);

GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);


ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);


//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));

//
// Enable the UART interrupt.

ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

ROM_UARTFIFOEnable(UART1_BASE);

UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);


ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

ROM_UARTFIFOEnable(UART0_BASE);

UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX1_8, UART_FIFO_RX1_8);

UARTEnable (UART0_BASE);
UARTEnable (UART1_BASE);

while(1)
{

do
{

UARTTransmitCommand("AT\r\n");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
break;
}while((strcmp(ok,receivechar))!=0);


do
{

UARTTransmitCommand("\"AT+CSTT=\"BSNLNET\"\n\r\0");

SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());
SysCtlDelay(SysCtlClockGet());


break;
}while((strcmp(ok,receivechar))!=0);

}

}

i get output as following


Please help me give me any suggestion.

Thanks in Advanced..............

  • Had you noted that your "excess characters" (AT) occurred exactly "17 UART counts" into your transmission?
    Why do "you" think that is?     What portion of the MCU's UART proves "sensitive" to characters (17 and beyond?)

    Your Subject Line - which really is "quite good" - "targets the "AT Command" as your problem's cause.        Yet - might the AT Command be "blameless" - and "length of your UART data" be the (real) cause?        Be not "rushed" to perform diagnosis - deeper thinking IS required...

  • CB1 has given you a great hint, but because of the time zone difference and the upcoming weekend, I will be more specific. (Sorry, CB1, I may be ruining the teachable moment you created.)

    Your use of the function UARTCharPutNonBlocking() in UARTTransmitCommand() without checking the return value means that some characters were not transmitted. The "NonBlocking" means that the routine does not wait if there is no room in the FIFO. Rather it returns "FALSE" to let you know it could not load another character yet. Use of UARTCharPut() instead is a possible alternative.
  • Greetings Bob,

    It "does appear" as if,
    teaching_moment --;

    has arrived. We'd both hope that poster would "extend his probing & investigation" (really) master the difference between UART functions - (carefully "logging his findings") expanding his capability & confidence - in that process. (it is "not always" that you - and/or other capable vendor staff - are here to provide such "rescue.") Thus my push for "Self-Help" via focused experimentation - under KISS (always) and One SMALL STEP at a time...