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.

code for communication between SIM300 GSM module and MSP430G2553 controller

Other Parts Discussed in Thread: MSP430G2553

hi,

I want to send AT commands to SIM300 GSM Module with the code i have written for MSP430G2553 controller.i am using hyperterminal .the problem i am getting is i couldn't able to sent it.my code

#include <msp430.h>
#include <msp430g2553.h>
#include <string.h>

#define LED BIT0
#define RXD BIT1
#define TXD BIT2

void uart_init(void);
unsigned char uart_getc();
void uart_gets();
void uart_putc(unsigned char c);
void uart_puts(char *str);
char arr[32];

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

//------------------------------------------------------------------------------------------------
void uart_init(void)
{
P1SEL = RXD + TXD; //Setup the I/O
P1SEL2 = RXD + TXD;

P1DIR |= LED; //P1.0 red LED. Toggle when char received.
P1OUT |= LED; //LED off

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
IE2 |= UCA0RXIE; //Enable USCI_A0 RX interrupt

rx_flag = 0; //Set rx_flag to 0
tx_flag = 0; //Set tx_flag to 0

}
//-------------------------------------------------------------------------------------------------------
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;
}

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 null. Overwrites the \r with \0
{
Array[i] = '\0';
}
break;
}
i++;
}

}
//------------------------------------------------------------------------------------------------------------
void uart_putc(unsigned char c)
{
tx_char = c; //Put the char into the tx_char
IE2 |= UCA0TXIE; //Enable USCI_A0 TX interrupt
while(tx_flag == 1); //Have to wait for the TX buffer
tx_flag = 1; //Reset the tx_flag
}

void uart_puts(char *str) //Sends a String to the UART.
{
while(*str)
uart_putc(*str++); //Advance though string till end
}
//-----------------------------------------------------------------------------------------------------------

#pragma vector=USCIAB0TX_VECTOR//UART TX USCI Interrupt
__interrupt void TX_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
}

#pragma vector=USCIAB0RX_VECTOR//UART RX USCI Interrupt. This triggers when the USCI receives a char.
__interrupt void RX_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
}

//-------------------------------------------------------------------------------------------------------------
void gsm()
{
uart_gets(arr,sizeof(arr));
if((strcmp("Call Ready",arr))==0)
{
uart_puts((char *)"AT"); // COMMAND FOR INITIALIZING GSM
uart_putc(0x0A); //ENTER
uart_putc(0x0D);//CARRIAGE RETURN
__delay_cycles(100000);
}
else
uart_puts((char *)"call cannot be connected");


uart_gets(arr,sizeof(arr));
if((strcmp("OK",arr))==0)
{
uart_puts((char *)"ATD9028901369;"); //COMMUNICATION
uart_putc(0x0A); //ENTER
uart_putc(0x0D); //CARRIAGE RETURN
}
else
uart_puts((char *)"Enter valid number");

}
//-------------------------------------------------------------------------------------------------------------
int main(void)
{

WDTCTL = WDTPW + WDTHOLD; // STOP WATCHDOG TIMER
BCSCTL1 = CALBC1_8MHZ; // MAKE THE FREQUNCY AS PER THE LAUNCHPAD 8MHZ
DCOCTL = CALDCO_8MHZ;

uart_init(); // CALL THE UART INIT FUNCTION WHICH IS AVAILAIBLE IN THE FILE
__enable_interrupt(); //enable interrupt
//__delay_cycles(100000);
gsm();
while(1);

}

  • i want to use the com port5 i.e not using RS232.
  • Vikas,

    In the future if you get your code from an online source such as a website or blog could you please post a link to the source? This will help us better understand and debug your issue.
    researchdesignlab.com/gsm-interfacing-msp430.html

    The confusion here centers around understanding how the MSP430 is expected to communicate with the SIM300 GSM module. You mention hyperterminal and a COM port, meaning that you are connected to a host PC through backchannel UART for communication with the MSP430 (G2 LaunchPad, I assume). However the G2553 only has one UART-capable peripheral (USCI_A0) and I imagine that you are also trying to connect your SIM300 GSM module to the MSP430G2553 through USCI_A0.

    The problem is that you cannot connect two UART devices to the same communication lines...the SIM300 must either be connected to the MSP430G2553 or the host PC. Loading multiple devices on the same lines is causing communication failure. Why do you even need to be connected to Hyperterminal? Other than for debugging purposes (where Hyperterminal sends SIM300-like commands to the MSP430 to ensure that it returns the correct response) the SIM300 should be the only device sending commands to the MSP430. If you want to use both a host PC and SIM300 GSM you will need to upgrade to a MSP430 with more UART lines.

    Regards,
    Ryan

**Attention** This is a public forum