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.

CDMA response reading through UART using TM4c123gh6pmi

Other Parts Discussed in Thread: EK-TM4C123GXL

HI All,

UART communication with CDMA is as follows:

* Send AT command to CDMA through UART

* Receive response which is of huge bytes through UART.

I can able to read perfectly if the response is few bytes (only 26), if the response is more I cant able to read those and my code is as below.

Any help is appreciated....

uint8_t i=0,j=0,k=0;
// if(ui32Count <= 30){
while(i<=ui32Count){
UARTCharPut(UART1_BASE, pui8Buffer[i]);
DataBuffer[j] = UARTCharGet(UART1_BASE);
i++;j++;
}
SysCtlDelay(5000);
while((UARTCharsAvail(UART1_BASE)) == true){
DataBuffer[j] = UARTCharGetNonBlocking(UART1_BASE);
j++;
}

If I remove the SysCtlDelay then response will not be stored in buffer even for 2 bytes response, but if debug step by step without SysCtlDelay, buffer can get the response.

Thanks 

srini

  • Hello Srini,

    What is the ui32Count value (just to understand the logic)

    In second loop the issue is that without the delay if there is no UART RX it will skip the loop, Similarly when the UART character is read out, and the next one is being shifted in it will exit the while loop.

    The second loop should be more like

    while(j <= Some_Known_Expected_Value)

    {

      while((UARTCharsAvail(UART1_BASE)) == true);
      DataBuffer[j] = UARTCharGetNonBlocking(UART1_BASE);
      j++;
    }

    Regards

    Amit

  • Hi Amit,

    ui32Count value is that the size of command  ex: "AT\r\n" need to be sens then ui32Count value will be 4. Always modem will return what we sent and then the actual response so only I am receiving the know bytes first and then wait for some delay and continue to get the actual response.

    BTW I tried the above logic but still I am receiving only 27 bytes of data :( not more than that.

    Thanks,

    srini

  • Hello Sreeni,

    What is the size of the DataBuffer? Also the j++ increments but to what value max?

    I would appreciate if you can upload the code as an attachment rather than a code snippet.

    Regards

    Amit

  • Hi Amith,

    Here is the entire code for CDMA modem communication with AT commands. Please see this and tell me whether I am wrong anywhere.

    #define CMD_AT "AT\r\n"
    #define CMD_MODEL_NUM "AT+CGMM\r\n"
    #define CMD_CREG "AT+CREG?\r\n"
    #define CMD_SCFG "AT#SCFG?\r\n"
    #define CMD_CSQ "AT+CSQ\r\n"
    #define CMD_SGACT_QUEST "AT#SGACT?\r\n"
    #define CMD_SGACT "AT#SGACT=1,1\r\n"
    #define CMD_MANUFACTURER "AT+CGMI\r\n"
    #define CMD_SIM_DET "AT#SIMDET=1"
    #define CMD_SELINT "AT#SELINT=2"
    #define CMD_CGDCONT "AT+CGDCONT=1,IP,TATA.DOCOMO.INTERNET"
    #define CMD_USERID "AT#USERID="""
    #define CMD_PASSWD "AT#PASSW="""
    #define CMD_IPADD "AT#GPRS=1"

    uint8_t DataBuffer[1000];


    void UARTSEND(uint8_t pui8Buffer[], uint32_t ui32Count) // pui8Buffer - actual command and ui32Count is size of the //AT command
    {
    uint8_t i=0;
    int j=0,k=0;

    while(i<=ui32Count){
    UARTCharPut(UART1_BASE, pui8Buffer[i]);
    DataBuffer[j] = UARTCharGet(UART1_BASE);
    i++;j++;
    }
    SysCtlDelay(300000);
    while((UARTCharsAvail(UART1_BASE)) == true){
    DataBuffer[j] = UARTCharGetNonBlocking(UART1_BASE);
    j++;
    }
    k++;

    }

    void EXE_CMD(uint8_t nextcmd[],uint8_t code ){
    /*Send the command to CDMA through UART*/
    UARTSEND(nextcmd,strlen((const char *)nextcmd));
    }

    void UART_INIT (void)
    {
    static int i;
    //Data1[30];

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);// To enable the CDMA modem

    GPIOPinConfigure(GPIO_PC4_U1RX);
    GPIOPinConfigure(GPIO_PC5_U1TX);

    GPIOPinTypeUART(GPIO_PORTC_BASE, 0x30);
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, 0x40);

    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));

    // Enable the UART.
    UARTEnable(UART1_BASE);

    /*CDMA modem initialization*/
    /*Turn ON the PA6*/
    GPIOPinWrite(GPIO_PORTA_BASE, 0x40,0x40);
    for(i = 0; i <= 100000; i++);
    /*Turn OFF the PA6*/
    GPIOPinWrite(GPIO_PORTA_BASE, 0x40,0);
    for(i = 0; i <= 500000; i++);
    }

    int main (void) {

    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    UART_INIT();

    EXE_CMD((uint8_t*)CMD_AT, None);
    EXE_CMD((uint8_t*)CMD_MODEL_NUM, Model_Number);
    EXE_CMD((uint8_t*)CMD_CREG, None);
    EXE_CMD((uint8_t*)CMD_SCFG, None);
    EXE_CMD((uint8_t*)CMD_SGACT_QUEST, None);
    EXE_CMD((uint8_t*)CMD_SGACT, None);
    }

  • Hi Amit,

    By the way I didnt used RTS and CTS in my code, did that causes the problem ?.....

    thanks

    srini

  • Hi Amith,

    I think I need to use the RTS and CTS signals flow control.

    Can anyone explain me how to use the RTS and CTS for Modem communication with TIVA C series MCU.

    I have called 2  library functions (which are in UART.C) as follows

    UARTFlowControlSet(UART1_BASE, UART_FLOWCONTROL_TX|UART_FLOWCONTROL_RX);
    UARTModemControlSet(UART1_BASE, UART_OUTPUT_DTR|UART_OUTPUT_RTS);

    But still I am able to receive only 26 bytes of response from CDMA.

    Thanks

    srini

  • Hi All,

    Could anybody hep me to resolve the issue of Modem communication I am stuck at this point.

    Issue: I am receiving only 26 bytes  from the modem not more than that through UART interface please see above for more details.

    Thanks

    srini

  • Hello Sreeni,

    I started work on the case and I am having the following errors during compilation.

    >> Compilation failure
    "../TM4C123_UARTCDMA.c", line 147: error #20: identifier "None" is undefined
    "../TM4C123_UARTCDMA.c", line 148: error #20: identifier "Model_Number" is undefined
    2 errors detected in the compilation of "../TM4C123_UARTCDMA.c".

    What is None and Model_Number defined as? Also are you doing a loopback to get what is being sent?

    Regards

    Amit

  • I don't think your problem has anything specifically to do with CDMA, modems, or TIVA - it looks like your serial receive code is just too slow!

    You are spinning in a loop checking for received characters, then reading just 1 character, then spinning in the loop again.

    What you need is a lean, mean, short & simple interrupt handler which just takes received characters from the UART as soon as they arrive, and puts them into a circular buffer.

    Your main-line code can then read from the circular buffer at its leisure.

    Look at the TivaWare uartstdio utility for example - you need what they call the "Buffered" mode...

    Can anyone explain me how to use the RTS and CTS for Modem communication with TIVA C series MCU

    Again, there's nothing really specific to TIVA here;  google (or even your modem documentation) will find you a description of how RTS/CTS works - the only TIVA specific part is how to set an output pin (RTS),  and read an input pin (CTS)

    eg, http://en.wikipedia.org/wiki/RS-232_RTS/CTS#RTS.2FCTS_handshaking

  • hi Amith,

    None u can set it to 0 (which i am used for future purpose for other commands) and model_number also the same.

    thanks

    srini

  • Hello Srini,

    I do not have a CDMA Modem responding to the Commands. Can you what can be done to emulate the other side response?

    Secondly the CDMA Modem will be sending the data asynchronously later, in which case why don't you use the Receive Interrupt to read the data bytes. I think you mentioned that you will get the same bytes first followed by the data. How do you know how much data. is there a frame format for the same?

    Regards

    Amit

  • Amit Ashara said:
    I do not have a CDMA Modem responding to the Commands.

    As I said, I don't think this has anything specifically to do with the CDMA modem.

    Can you what can be done to emulate the other side response?

    Just use a terminal emulator on a PC.

    You really need to get the serial comms working before you add the complication of a modem - do that with a terminal emulator on a PC; ensure that it handles large blocks of data.

  • Hello Andy

    I agree with you.

    But to me right now the fact that the user mention of "after sometime", means that an Interrupt function needs to be involved as the Modem will send the data in chunks and bursts, that the TM4C has to reconstruct.

    I have used UART for async communication for more than 100 bytes between two systems (Cannot share the details though) with interrupt and frame encoding. It has worked reliably, I would like the user to change the recieve data method to an interrupt based reconstruction.

    Regards

    Amit

  • Absolutely - that's why I recommended the TivaWare uartstdio utility  - in the "Buffered" mode...

    The "Buffered" mode is interrupt-driven and uses Ring Buffers. This is the standard way to go for anything but the most trivial, low-speed comms.

  • HI All,

    Quiet  some time I was out of station....

    I tried the interrupt driven method for receiving the data but still I cant able to read more data and also HTTP command response is not proper 

    Command : AT#HTTPQRY=0,0,"http://trail.dexceldesigns.com/api/v1/getconfig?macid=FF-00-FF-00-FF-00"

    Response: OK  (and we will receive an HTTP Ring as below)

    #HTTPRING: 0,200,"text/html",0

    Command: AT#HTTPRCV=0  (command to get the data)

    Response: Should be as below

    {"result":1,"error":0,"e_msg":"","camera":"My Camera Name","macid":"FF-00-FF-00-
    FF-00","transmission":0,"compression":2,"save":1,"mem_overwrite":1,"ftp_host":"t
    rail.lync.ftphost.com","ftp_user":"exampleuser","ftp_pass":"3J&cy[t_N6p?9JJ"}

    But in my case I am not able to receive this huge data .

    Any help is appreciated.

    Thanks and regards,

    Sreeni

  • I also try to understand the UARTSTDIO.h but couldn't get clear idea, so please anyone having sample code which tells how to use the API functions which are in uartstdio.h please post here so that i can give try once.

    Thanks & regards,

    sreeni

  • Hello Sreeni,

    Please have a look at the example code in TivaWare which calls the functions from uartstdio

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\boards\ek-tm4c123gxl\udma_demo

    You can then post questions on what you are not able to understand and how it relates to the problem you are facing.

    Regards

    Amit

  • hi Amith,

    Thanks for the reply.

    I try to use the uartstdio.c APIs  in my implementation but recevie buffer is always empty could you please see that initialization and Transmitting and receiving were correctly implemented or not

    initialization: I am using UART1 for the communication between modem and the MCU.

    void UART_Init(void)

    {

    uint_fast16_t ui16Idx;

    uint32_t g_ui32SysClock, i;
    // Set the clocking to run directly from the crystal at 120MHz.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, 0x40);
    // g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
    // SYSCTL_OSC_MAIN |
    // SYSCTL_USE_PLL |
    // SYSCTL_CFG_VCO_320), 120000000);

    //
    // Fill the TX buffer with a simple data pattern.
    //
    for(ui16Idx = 0; ui16Idx < UART_TXBUF_SIZE; ui16Idx++)
    {
    g_ui8TxBuf[ui16Idx] = ui16Idx;
    }

    //
    // Enable the UART peripheral, and configure it to operate even if the CPU
    // is in sleep.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1);

    //
    // Configure the UART communication parameters.
    //
    // ROM_UARTConfigSetExpClk(UART1_BASE, g_ui32SysClock, 115200,
    // UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
    // UART_CONFIG_PAR_NONE);
    UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));

    //
    // Set both the TX and RX trigger thresholds to 4. This will be used by
    // the uDMA controller to signal when more data should be transferred. The
    // uDMA TX and RX channels will be configured so that it can transfer 4
    // bytes in a burst when the UART is ready to transfer more data.
    //
    ROM_UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);

    // // This register write will set the UART to operate in loopback mode. Any
    // // data sent on the TX output will be received on the RX input.
    // //
    // HWREG(UART1_BASE + UART_O_CTL) |= UART_CTL_LBE;

    //
    // Enable the UART DMA TX/RX interrupts.
    //
    ROM_UARTIntEnable(UART1_BASE, UART_INT_TX | UART_INT_RX | UART_INT_CTS | UART_INT_RI);

    // //
    // // Enable the UART peripheral interrupts.
    // //
    ROM_IntEnable(INT_UART1);

    /*Turn ON the PA6*/
    GPIOPinWrite(GPIO_PORTA_BASE, 0x40,0x40);
    for(i = 0; i <= 100000; i++);
    /*Turn OFF the PA6*/
    GPIOPinWrite(GPIO_PORTA_BASE, 0x40,0);
    for(i = 0; i <= 5000000; i++);
    }

    And then I try to send the AT command and receive the response is as follows:

    char pcBuf[] = "AT\r\n";

    j = UARTwrite(pcBuf, strlen(pcBuf));
    j = UARTRxBytesAvail();
    for(i =0; i<=9;i++){
    pcBuf[i] = UARTgetc();
    }
    //j = UARTgets(pcBuf, len); // tried this also but always code will stuck at buffer empty.

    Any help is appreciated.

    Thanks & Regards,

    Sreeni

  • Hello Amit ,

    I had the same problem with the SIM900 module so I used the udma_demo on my board tm4c1294xl on UART port 7. I edited the code and connected a Arduino mega to port 7 and successfully received the AT commands send by the board to the arduino and also the responses I manually wrote on arduino serial monitor were retrived by the board and displayed on the console using printf() function. But when I connect it to GSM module I also have the same issue of limiting the commands and responses to sixteen characters. Unfortunately I cannot post the code. 

  • Hello SahanH,

    I would ask for a simple experiment. Use the UART to display the data on a console with a string greater than 16. This will sanitize the setup from Transmit perspective on your setup

    Regards
    Amit