• Not Answered

prgram code for interfacing of sim300 gsm modem with msp430f5529

Sir i m not getting results wen i try to interface sim300 gsm modem with msp430f5529 rather wen i debug my program i get error message in register of uart i.e unable to read

however dere is no error while building up program wat could be d reason for dat..

following is my code plz reply asap

#include <msp430f5529.h>
void UART_putChar (char c);
void UART_write (unsigned char serial_data);
char UART_getChar ();
char UART_getCharIsReady ();
void gsm_cmd( char *string);
void delay(int i);


void main(void)
{
P4SEL = BIT5+BIT4;
P4DIR |= BIT4; // port direction for TXD0
P4DIR &= ~BIT5; // port direction for RXD0
P1DIR=0x01;
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0xD8; // 9600 (see User's Guide)
UCA1BR1 = 0x00; //
UCA1MCTL |= UCBRS_6+UCBRF_0; // Modulation UCBRSx=6, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt

__bis_SR_register( GIE); // interrupts enabled
gsm_cmd("AT\r\n");
delay(100);
gsm_cmd("AT+CMGF=1\r\n");
delay(100);
gsm_cmd("AT+CMGS=\"+919815942820\"\r\n");
 delay(100);
gsm_cmd("hello");
UART_write(0x1a);
delay(100);
}
void UART_putChar (char c) // UART1 Transmit Subroutine
{
while ((UCA1IFG&UCTXIFG) == 0); // Wait for ready U1TXBUF
{
UCA1TXBUF = c;
P1OUT=0x01;// send data

//UCA1IFG &=0xfd;
}
}
void UART_write (unsigned char serial_data)
{

UART_putChar (serial_data);
}

char UART_getCharIsReady ()
{
return (UCA1IFG & UCRXIFG) != 0;
}
char UART_getChar ()
{
while (!UART_getCharIsReady ());
return UCA1RXBUF;
}

void gsm_cmd( char *string)
{
int i=0;
while(string[i]!='\0')
{
if(string[i]==0x5C) // Not to send '\' cahracter
i++;

UART_write(string[i]);
i++;
}
//UCA1IFG &=0xfd;
}
//void delay(int i)
{
 int j;
 for(j=1;j<i;j++)
 {
}

 

12 Replies

  • ankush kansal
    i get error message in register of uart i.e unable to read

    What do you mean by this? The UART may report a framing or parity error, but besides this there is no 'unable to read' error of any kind. The UART registers give you what's coming in - or nothign if nothing is coming in, but the UART doesn't 'try to read and fail' by any means.

    You send something into the void and you receive something out of the void. that's how UART (Universal Asynchroneous Receiver Transmitter) serial transmissions work.

  • In reply to Jens-Michael Gross:

    Thanks sir for ur kind attention towards my problem bt sir i m talking about  control word register of UART which we see after debugging from view menu then register option in code composer studio v5

  • In reply to ankush kansal:

    also sir, it executes first two commands of gsm in the program then during execution of  3rd or 4th command ...it shows the message like  no source available for 0xfffe n some other locations too,,,plz reply asap...

  • In reply to ankush kansal:

    ankush kansal
    no source available for 0xfffe

    Ah. This error has nothing to do with the UART.
    It means that the program counter is at a location where there is no known source code available for.
    Usually, this means that the CPU is running wild, as a result of a stack overflow, stack corruption or a missing ISR.

    Now let's look in your code for the usual suspects...

    ankush kansal
    UCA1IE |= UCRXIE; // Enable USCI_A1 RX interrupt

    And here we are. ;)

    You enable the receive interrupt of the USCI. And by setting GIE, you also globally allow interrupts. However, you don't have an ISR (service function) for the receive interrupt.
    So as soon as the first byte comes in, the USCI triggers a receive interrupt, the CPU tries to fetch the ISR address form the interrupt vector table but alas, there is none, only teh default '0xffff' flash content. As a result, the CPU jumps to 0xffff (or rather 0xfffe, as the LSB is ignored) where there is no code at all, and crashes or does other weird things.

  • In reply to Jens-Michael Gross:

    #include <msp430f5529.h>
    void UART_putChar (char c);
    void UART_write (unsigned char serial_data);
    char UART_getChar ();
    char UART_getCharIsReady ();
    void gsm_cmd( char *string);
    void delay(int i);

    int i;
    char *str2;
    void main(void)
    {
    //char *str="ok";
    char *str1="AT";
    P4SEL = BIT5+BIT4;
    P4DIR |= BIT4; // port direction for TXD0
    P4DIR &= ~BIT5; // port direction for RXD0
    P1OUT=0x01;
    P8OUT=0x02;
    UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
    UCA1BR0 = 138; // 9600 (see User's Guide)
    UCA1BR1 = 0x00; //
    UCA1MCTL |= UCBRS_6+UCBRF_0; // Modulation UCBRSx=6, UCBRFx=0
    UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

    while(1)
    {
    UCA1IE |= UCRXIE+UCTXIE; // Enable USCI_A1 RX interrupt

    __bis_SR_register( GIE); // interrupts enabled
    //gsm_cmd("AT\r\n");
    //delay(1000000);
    __no_operation();
    }
    }

    #pragma vector=USCI_A1_VECTOR

    __interrupt void USCI_A1_ISR(void)
    {
    UCA1TXBUF=0x00;
    switch(__even_in_range(UCA1IV,4))
    {
    case 0:break; // Vector 0 - no interrupt
    case 2:// Vector 2 - RXIFG
    //*str2="OK";
    while((UCA1IFG&UCRXIFG)==1)
    P8DIR=0x02;

    break;
    case 4:
    i=1;
    char *str1="AT\r";

    while (!(UCA1IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    {UCA1TXBUF = str1[i]; // TX -> RXed character
    i++;
    P1DIR=0x01;}
    break; // Vector 4 - TXIFG
    default: break;
    }
    }

    in this program, if we write UCA1TXBUF=0x00 instruction in the main loop then when the execution enters the ISR it stucks there and doesnt leave the 'while' loop....so the next command UCA1TXBUF = str1[i]; is never executed....plz help...n we dont want to write in ISR coz it will reset before transmitting data...

  • In reply to ankush kansal:

    ankush kansal
    while((UCA1IFG&UCRXIFG)==1)

    Doubly wrong.

    UCA1IFG&UCRXIFG is either 0 or UCR1IFG.It is pure coincidence that UCRXIFG is indeed 0x01. If it weren't, this while loop would loop forever without any changce to ever exit. On 2x family, you'd have a big problem with this line.

    However, the line is superfluous at all.
    By reading UCA1IV and switching to case 2, you know that UCRXIFG was set. Else you hadn't read 2 from UCA1IV. Howeve,r readign UCA1IV has at the same time cleared UCRXIFG, so it is no longer set. So you will loop here until another byte arrives.

    The same applies to case 4(TXIFG). Worse: since the interrupt was cleared but you didn't write anything to TXBUF yet, no more interrupts will come and you'll loop eternally.

  • In reply to Jens-Michael Gross:

    #include <msp430f5529.h>
    void UART_putChar (char c);
    void UART_write (unsigned char serial_data);
    char UART_getChar ();
    char UART_getCharIsReady ();
    void gsm_cmd( char *string);
    void delay(unsigned int i);


    void main(void)
    {

    P4SEL = BIT5+BIT4;
    P4DIR |= BIT4; // port direction for TXD0
    P4DIR &= ~BIT5; // port direction for RXD0
    P8OUT=0x02;
    P1OUT=0X01;

    UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
    UCA1BR0 = 0x8A; // 2400 (see User's Guide)
    UCA1BR1 = 0x00; //
    UCA1MCTL |= UCBRS_6+UCBRF_0; // Modulation UCBRSx=6, UCBRFx=0
    UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    //UCA1IE |= UCRXIE+UCTXIE; 

    gsm_cmd("A\r\n");
    delay(10000);
    gsm_cmd("AT\r\n");
    delay(10000);

    gsm_cmd("ATEO\r\n");
    delay(10000);
    gsm_cmd("AT+CMGF=1\r\n");
    delay(10000);
    gsm_cmd("AT+CMGS=\"+919779257497\"\r\n");
    delay(10000);
    gsm_cmd("hello");
    UART_write(0x1a);
    delay(10000);
    }
    void UART_putChar (char c) // UART1 Transmit Subroutine
    {
    while ((UCA1IFG&UCTXIFG) == 0); // Wait for ready U1TXBUF

    UCA1TXBUF = c;
    P1DIR=0x01;// send data
    delay(10000);

    }
    void UART_write (unsigned char serial_data)
    {

    UART_putChar (serial_data);
    }

    void gsm_cmd( char *string)
    {
    int i=0;
    while(string[i]!='\0')
    {


    UART_write(string[i]);
    i++;
    }
    }
    void delay(unsigned int i)
    {
    int j;
    for(j=1;j<i;j++)
    {
    }

    }

    sir,this program is not sending message to number which is specified in program.It is giving no error.plz help..

  • In reply to ankush kansal:

    ankush kansal
    It is giving no error

    What is giving no error?

    Do you mean that the code builds with no error? That it downloads to the chip with no error? That you receive no ERROR responses from the modem? Or what??

    ankush kansal
    plz help

    Before expecting others to help,  what debugging have you done yourself?

    Have you verified that the physical connections to the modem are correct, and all required signals are present & in the correct stated?

    In particular, have you verified that the voltage levels are all correct

    Are the correct commands actually being sent to the modem? Are they reaching the modem's input pin?

    Is the modem responding correctly to those commands? Are those responses reaching the microcontroller's input pin?

     

  • In reply to Andy Neil:

    Hello sir,

                 I am developing an application where i need to interface SIM300 module to MSP430F5529 EXPERIMENTAL BOARD, I want to know that the above mentioned code is Valid  for which version of SIM300..? 

  • In reply to Sunil Supekar:

    Sunil Supekar
    I want to know that the above mentioned code is Valid  for which version of SIM300..? 

    Did you not notice the author's own description of his code:

    ankush kansal
    this program is not sending message to number which is specified in program.It is giving no error.plz help..

    Probably as well to start it yourself from scratch: http://bit.ly/pWAASo