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.

CCS/MSP430FR5739: SMS sending example with MSP430FR5739 controller + quectel M95 GSM module (UART)

Part Number: MSP430FR5739
Other Parts Discussed in Thread: ENERGIA, MSP-EXP430FR5739

Tool/software: Code Composer Studio

Hi Team,

I am new to this GSM interfacing can you please share working code example for GSM communication and my case is : SMS sending example with MSP430FR5739 controller + quectel M95 GSM module (UART) 

Thanks,

Jack

  • 1362.main.c
    /*
    
     * Project name:
    
        GSM
    
     * Copyright
    
         (c) Researchdesignlab.com
    
     * Test configuration:
    
         MCU:             MSP430G2553
    
         Dev.Board:       TI LAUNCHPAD
    
         Oscillator:      16 MHz
    
         Software:        CCS STUDIO V.5
    
    
    
    */
    #include <msp430.h>
    #include "msp430fr5739.h"
    
    #include "uart.h" // uart hedder file
    
    
    
    
    
    void gsm();//GSM FUNCTION PROTOTYPE
    
    
    
    
    
    int main(void)
    
    {
    
        WDTCTL = WDTPW + WDTHOLD;// STOP WATCHDOG TIMER
    
    
        UCA0CTL1 = UCSSEL_2 | UCSWRST;
    
        uart_init(); // CALL THE UART INIT FUNCTION WHICH IS AVAILAIBLE IN THE FILE
    
        __enable_interrupt();// ENABLE INTERRUPT
    
    
    
        __delay_cycles(100000);
    
    
    
    
    
    
    
    
    
        gsm();// CALL THE GSM FUNCTION
    
    
    
    }
    
    
    
    
    
    void gsm()
    
    {
    
    
    
    
    
          uart_puts((char *)"AT"); // COMMAND FOR INITIALIZING GSM
    
          uart_putc(0x0A);//ENTER
    
          uart_putc(0x0D);//CARRIAGE RETURN
    
    
    
          __delay_cycles(10000000);//DELAY...WAIT FOR OK FROM GSM
    
          uart_puts((char *)"AT+CMGF=1");//COMMUNICATION
    
          uart_putc(0x0A);
    
          uart_putc(0x0D);
    
    
    
         __delay_cycles(10000000);//WAIT FOR OK
    
          uart_puts((char *)"AT+CMGS=\"7207125449\"");//SEND A MESSAGE TO PARTICULAR NUMBER
    
          uart_putc(0x0A);
    
          uart_putc(0x0D);
    
          uart_puts((char *)"GSMtest");//SEND HELLO
    
             uart_putc(0x1A);//CTRL Z
    
          //AFTER HARDWARE CONFIGURATION THE MESSAGE WILL GET SEND
    
         //ATTACH THE UART FILES OR WRITE THE CODE FOR INIT AND SENDING MESSAGE IN THE SAME FILE...
    
    }
    
    
    
    
    
    
    
    // end of gsm.c file
    
    //���������������������������������������������������������
    
    0724.uart.c
    /*   create file  named called   urat.c  and paste below given program
    
    /*
    
     *This is a uart.c file of the UART Hardware demo using USCI on the MSP430G2553 microcontroller.
    
     *Set your baud rate in your terminal to 9600 8N1.
    
     *When using your TI MSP-430 LaunchPad you will need to cross the TXD and RXD jumpers.
    
    */
    
     
    #include <msp430.h>
    #include "msp430fr5739.h"
    
    #include "uart.h"
    
     
    
    //#define LED BIT0
    
    #define RXD BIT0
    
    #define TXD BIT1
    
     
    
     
    
    volatile unsigned int tx_flag;             //Mailbox Flag for the tx_char.
    
    volatile unsigned char tx_char;            //This char is the most current char to go into the UART
    
     
    
    volatile unsigned int rx_flag;             //Mailbox Flag for the rx_char.
    
    volatile unsigned char rx_char;            //This char is the most current char to come out of the UART
    
     
    
    /*uart_init
    
    * Sets up the UART interface via USCI
    
    * INPUT: None
    
    * RETURN: None
    
    */
    
    void uart_init(void)
    
    {
    
        // P1SEL = RXD + TXD;                         //Setup the I/O
    
       //  P1SEL2 = RXD + TXD;
        P2SEL1 = BIT0 | BIT1;
     
    
       // P1DIR |= LED;                               //P1.0 red LED. Toggle when char received.
    
      //  P1OUT |= LED;                               //LED off
    
        UCA0BRW = 6;
          UCA0MCTLW = 0x2081;
          UCA0CTL1 &= ~UCSWRST;
    /*
         UCA0CTL1 |= UCSSEL_2;                      //SMCLK
    
                                                         //8,000,000Hz, 9600Baud, UCBRx=52, UCBRSx=0, UCBRFx=1
    
         UCA0BR0 = 52;                        //8MHz, OSC16, 9600
    
         UCA0BR1 = 0;                         //((8MHz/9600)/16) = 52.08333
    
         UCA0MCTL = 0x10|UCOS16;              //UCBRFx=1,UCBRSx=0, UCOS16=1
    
         UCA0CTL1 &= ~UCSWRST;                      //USCI state machine
    */
    
          UCA0IE |= UCRXIE;                         //Enable USCI_A0 RX interrupt
    
          _enable_interrupts();
    
         rx_flag = 0;                               //Set rx_flag to 0
    
         tx_flag = 0;                               //Set tx_flag to 0
    
     
    
         return;
    
    }
    
     
    
    /*uart_getc
    
    * Get a char from the UART. Waits till it gets one
    
    * INPUT: None
    
    * RETURN: Char from UART
    
    */
    
    unsigned char uart_getc()                  //Waits for a valid char from the UART
    
    {
    
         while (rx_flag == 0);                //Wait for rx_flag to be set
    
         rx_flag = 0;                               //ACK rx_flag
    
        return rx_char;
    
    }
    
     
    
    /*uart_gets
    
    * Get a string of known length from the UART. Strings terminate when enter is pressed or string buffer fills
    
    * Will return when all the chars are received or a carriage return (\r) is received. Waits for the data.
    
    * INPUT: Array pointer and length
    
    * RETURN: None
    
    */
    
    void uart_gets(char* Array, int length)
    
    {
    
         unsigned int i = 0;
    
     
    
         while((i < length))                        //Grab data till the array fills
    
         {
    
               Array[i] = uart_getc();
    
               if(Array[i] == '\r')                 //If we receive a \r the master wants to end
    
               {
    
                    for( ; i < length ; i++)        //fill the rest of the string with \0 nul. Overwrites the \r with \0
    
                    {
    
                         Array[i] = '\0';
    
                    }
    
                    break;
    
               }
    
               i++;
    
         }
    
     
    
        return;
    
    }
    
     
    
    /*uart_putc
    
    * Sends a char to the UART. Will wait if the UART is busy
    
    * INPUT: Char to send
    
    * RETURN: None
    
    */
    
    void uart_putc(unsigned char c)
    
    {
    
         tx_char = c;                               //Put the char into the tx_char
    
       //  IE2 |= UCA0TXIE;                           //Enable USCI_A0 TX interrupt
         UCA0IE |= UCTXIE;
         while(tx_flag == 1);                 //Have to wait for the TX buffer
    
         tx_flag = 1;                               //Reset the tx_flag
    
         return;
    
    }
    
     
    
    /*uart_puts
    
    * Sends a string to the UART. Will wait if the UART is busy
    
    * INPUT: Pointer to String to send
    
    * RETURN: None
    
    */
    
    void uart_puts(char *str)                  //Sends a String to the UART.
    
    {
    
         while(*str) uart_putc(*str++);        //Advance though string till end
    
         return;
    
    }
    
     
    
    #pragma vector = USCIAB0TX_VECTOR          //UART TX USCI Interrupt
    
    __interrupt void USCI0TX_ISR(void)
    
    {
    
         UCA0TXBUF = tx_char;                 //Copy char to the TX Buffer
    
         tx_flag = 0;                               //ACK the tx_flag
    
       //  IE2 &= ~UCA0TXIE;                          //Turn off the interrupt to save CPU
         UCA0IE &= ~UCRXIE;
    }
    
     
    
    #pragma vector = USCIAB0RX_VECTOR          //UART RX USCI Interrupt. This triggers when the USCI receives a char.
    
    __interrupt void USCI0RX_ISR(void)
    
    {
    
         rx_char = UCA0RXBUF;                 //Copy from RX buffer, in doing so we ACK the interrupt as well
    
         rx_flag = 1;                               //Set the rx_flag to 1
    
     
    
      //   P1OUT ^= LED;                              //Notify that we received a char by toggling LED
    
    }
    
     
    
     
    
     
    
    // end of urat.c file
    
    //………………………………………………………………………………………………………………………………………………………
    
    6253.uart.hHI Ryan,

    Thanks for your Valuable reply.

    I tried  that code and that complied without errors but no response when i loaded into the target that not getting SMS.

    and here i attached the main.c and uart.c code, could you please review those and correct me.

    thanks,

    Jack.

  • Hello Jack,

    The default DCO frequency is 8 MHz as can be seen in the CSCTL1 register default settings in the Family User's Guide. Therefore your baud rate settings are incorrect and need to be altered. Your ISR naming is also wrong as only the USCI_A0_VECTOR is required for both the RX/TX IFGs.
    Please review the MSP430FR57xx_uscia0_uart examples. If using the MSP-EXP430FR5739 then make sure that the eZ430 backchannel UART header pins on J3 are unpopulated.

    Regards,
    Ryan

**Attention** This is a public forum