Connect with us

Serial Data Communication Using Sim 900 gsm module

Discussion in 'Microcontrollers, Programming and IoT' started by snel, Jul 21, 2012.

Scroll to continue with content
  1. snel

    snel

    11
    0
    Jul 21, 2012
    Hii to Everyone.
    This will be my first post as an issue.
    First of all i will like to thank the members of electronispoint who are here to support our querries.


    I am making a project module in which i am supposed to send the serial data as a text sms to a predefined number over the Gsm module (I have purchased sim 900 module)

    I have been successful in recieving the data over the tx line (at 9600 bps) from a serial communication device.


    Now the type of data i am recieving over here is alphanumeric.
    now my aim is to send these characters to a predefined number using a gsm module.

    I am a bit confused in accomplishing my task since i am a new bie in this field.
    I am stuck at these points:

    1) Do i need a microcontroller for my task.??
    2) Do we have an option in gsm module to connect the Tx to Rx directly so that my gsm module can directly recieve the serial data by
    eliminating the need of microcontroller...??
    3) What type of a circuit will i have to design....????


    Any help will be appreciated...
    Please reply soon...
    Thanks in advance..
     
  2. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    Do you have a datasheet for the device?

    Perhaps it's as easy as sending some sort of pseudo-Hayes ATxxxxx string to the device?
     
  3. snel

    snel

    11
    0
    Jul 21, 2012
    My apologies Steve.......I dont have a datasheet yet.....

    As you mentioned that i have to use the AT commands for my task.....
    The issue is ...do i have to use the AT commands from the Module only or do i have to send these AT commands to module by a microcontroller....?
     
  4. snel

    snel

    11
    0
    Jul 21, 2012
    To make it more clear, I would also introduce the breakout board that i am using.
    Its available at this link
    .
    http://probots.co.in/Manuals/SIM300 Breakout Board - Manual.pdf

    In this breakout board we are having four main lines (TX,RX,GND,VCC)
    I have in my mind to transfer the serial data from my TX ( The one that i am recieving from my serial communication device) to the RX line of this breakout board.

    But unfortunately i am not able to decide as to what interface shall i use to make these both communicate to each other...
     
  5. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    what are you viewing the return data on? A PC configured as a terminal?

    You could use the PC to drive it. However a microcontroller may be smaller and more economical :)
     
  6. snel

    snel

    11
    0
    Jul 21, 2012
    Yes, i am viewing the serial data on the pc configured as terminal.

    But in the real scenario the PC wont be involved anywhere.

    Could you suggest which microcontroller would be best for my task and what code shall i write to my microcontroller...

    (If there are some important links, that you consider important to me, please let me know)
     
  7. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    First question is "Why are you doing this?" Is it for real, or just a school project?

    Second thing is... Get the datasheet before you do anything else (not having one tends to indicate to me that this project is not "for real")

    Yes, I imagine a uC would be a probable requirement. You may have to look for one with 2 UARTs, or use a bit banging library to allow read/writing via other pins.

    I have no idea what your code will eventually look like.
     
  8. snel

    snel

    11
    0
    Jul 21, 2012
    Yes its a final year project.

    The project is yet in conceptual phase of development.
    Once it reaches the logical phase we will be given the datasheet and
    I will for sure upload the same here to get a better understanding of the project.

    Is there any specific microcontroller that suits best for my task.

    I mean the one that till now, you can gather will be the best for me...:)
     
  9. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,363
    2,758
    Jan 21, 2010
    Given it's a conceptual phase, I would just say "microcontroller".

    You don't know until you get the specs of the device *exactly* how the thing talks. Maybe you'll need something different. You could just pick pic or atmel or anything else you're vaguely familiar with. But I wouldn't pick a particular device. Maybe you could narrow it down to a particular series or family, or maybe to a number of I/O pins and peripherals required -- knowing that this may change slightly.
     
  10. snel

    snel

    11
    0
    Jul 21, 2012
    Thanks for the nice support Steve.

    Get me a day or two we are about to get the datasheet (A block diagram)
    for the same....:)
     
  11. snel

    snel

    11
    0
    Jul 21, 2012
  12. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    I would suggest hooking the micro to the PC so that you can see and debug what you will eventually send the SIM module.

    The SCI ports on the micro takes a bit of configuration with speeds and interrupts (at least it does on a HCS12), so this will allow you to have a way of debugging.

    You will need some kind of buffer to fill the message once ready the message can be sent byte per byte.
     
  13. snel

    snel

    11
    0
    Jul 21, 2012
    I agree with you that i would have to hook the micro to the PC to see and debug.

    But what is the kind of buffer that i would be needing.
    How should i add buffer...
    Would appreciate if you can suggest me on the usage of buffers...
    Any links or some knowledge..
     
  14. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    Code for S12 sci / UART

    This is some code I've found backed up in my email from 2007 for a project I did with a S12. I can't say this was a working copy. Though I think this will demonstrate some of the complexity with getting getting serial communications working.

    /* sci.c
    *
    *
    *
    * Author: djm and drk
    */

    #include <mc9s12c32.h>

    #include "globals.h"
    #include "sci.h"


    #include <stdio.h>
    #include <string.h>

    /* Gloabals */

    #define MIW ('A')

    #define SCI_TIMEOUT (15) // 15 * 20 ms = 300 ms


    #define debugSCI (1)

    char debug[30];

    U_BYTE txBuffer[255]; //FIFO Queue
    U_BYTE txBufferInIndex =0;
    U_BYTE txBufferOutIndex =0;

    #pragma CODE_SEG NON_BANKED
    interrupt void sci_isr(void)
    {
    SCIInterruptHandler();
    PTT = (PTT&(~0x04)) | ((PTT^0x04)&0x04);
    }

    #pragma CODE_SEG DEFAULT
    void InitSCI(void) /* */
    {
    SCIBDH = 0x00;
    SCIBDL = 0x1A; // SCI0BDL = 0x1A;
    SCICR1 = 0x04; /* Mr Vardons Settings ILT*/
    SCICR2 = 0x2C; /* Trial and error from Debugger RIE | ILIE | TE */

    //Test
    clearTxBuffer();
    /* Enable LOOPS for Test*/

    //SCICR1 |= LOOPS;
    }

    void clearTxBuffer(void)
    {
    int i;
    for(i =0; i<255; i++)
    {
    txBuffer = 'A';
    }
    }

    void SCIInterruptHandler(void)
    {
    U_BYTE dummyData;
    /* Clear Flag*/
    if (SCISR1 & (RDRF + OR))
    {
    // clear the interrupt flag by reading the status register and
    // then the data register
    dummyData = SCISR1;
    dummyData = SCIDRL;

    //Echo
    ProcessSCIByte(dummyData);
    }
    if ((SCICR2 & SCICR2_TIE) && (SCISR1 & TDRE))
    {
    TransmittBufferEmpty();
    }
    }

    void TransmittBufferEmpty(void)
    {
    U_BYTE dummyData;

    // clear the interrupt flag by reading the status register
    dummyData = SCISR1;

    if(txBufferOutIndex < txBufferInIndex)
    {
    SCIDRL = txBuffer[txBufferOutIndex++]; // Put Byte in SCI Transmitt Register
    }
    else
    {
    // turn off the transmit empty interrupt
    SCICR2 &= ~SCICR2_TIE;
    txBufferInIndex = 0;
    txBufferOutIndex = 0;
    }
    }

    void TransmittMessage(char * message)
    {
    int i;
    for(i =0; message != '\0' ; i++)
    {
    txBuffer[txBufferInIndex++] = message; // Add to Queue
    }

    if ((SCICR2 & SCICR2_TIE) == 0) // If Transmitt Empty Interrupt Disabled
    {
    SCIDRL = txBuffer[txBufferOutIndex++]; // Service Byte
    SCICR2 |= SCICR2_TIE; // Enable Tx Empty Interrupt
    }
    }

    /*
    Method to buffer Recieved Bytes until full message is recieved.
    MIW -> DataLength -> Data -> DataChecksum
    */
    void ProcessSCIByte(U_BYTE sciData)
    {
    static U_BYTE state = 0;
    static U_BYTE dataLength = 0;
    static U_BYTE dataBytesRecieved = 0;
    static U_BYTE rxBuffer [36];
    static U_BYTE rxBufferIndex = 0;
    static U_BYTE dataChecksum =0;
    static U_WORD timeout = 0;


    /*

    Will time out messages, not in debug mode

    */

    #if debugSCI

    if (state > 0 && timer20msTick > timeout)
    {
    state = 0;
    dataLength = 0;
    dataBytesRecieved = 0;
    rxBufferIndex = 0;
    dataChecksum =0;
    }

    #endif


    switch(state)
    {

    case 0: //MIW
    {
    if(sciData == MIW) // Correct MIW
    {
    state = 1;
    timeout = timer20msTick + SCI_TIMEOUT;

    #if debugSCI
    // Debug Message
    sprintf(debug, "Valid MIW Found: %c \n\r", sciData);
    TransmittMessage(debug);
    #endif
    }
    else // Incorrect MIW
    {
    state = 0;

    #if debugSCI
    // Debug Message
    sprintf(debug, "Invalid MIW Found: %c \n\r", sciData);
    TransmittMessage(debug);
    #endif

    }
    break;
    }

    case 1: //Message Length
    {
    dataLength = sciData-176; //Conversion from ASCII to Numerical, needed for talking to Hyperterminal.
    state = 2;

    #if debugSCI
    // Debug Message
    sprintf(debug, "Message Length is: %d \n\r", dataLength);
    TransmittMessage(debug);
    #endif

    break;
    }

    case 2: // Buffer Data
    {
    rxBuffer[dataBytesRecieved++] = sciData;
    dataChecksum += sciData;

    #if debugSCI
    // Debug Message
    sprintf(debug, "Data is:%c \n\r", sciData);
    TransmittMessage(debug);
    #endif

    if (dataBytesRecieved == dataLength)
    {
    state = 3;

    #if debugSCI
    // Debug Message
    sprintf(debug, "Data Complete!!!!\n\r");
    TransmittMessage(debug);
    #endif

    }
    break;
    }

    case 3: // Checksum
    {
    if (sciData == dataChecksum) //valid message
    {

    #if debugSCI
    // Debug Message
    sprintf(debug, "Checksum Correct!!!! : %d \n\r", dataChecksum);
    TransmittMessage(debug);
    #endif

    }
    else
    {

    #if debugSCI
    // Debug Message
    sprintf(debug, "Checksum Failed!!!! : %d \n\r", dataChecksum);
    TransmittMessage(debug);
    #endif
    }

    //Test

    state = 4; // No Break on Purpose
    }

    case 4: //Clear Variables
    {
    state = 0;
    dataLength = 0;
    dataBytesRecieved = 0;
    rxBufferIndex = 0;
    dataChecksum =0;

    break;
    }
    }
    }
     
  15. snel

    snel

    11
    0
    Jul 21, 2012
    thanks a ton for the code....
    Although it took me a bit time to consider the code but finally i have got the concept
    of buffer from this code....


    as it is clear now that we can store the set of characters in the buffer that will then be transfered byte by byte to the sim module....


    Just consider a case that we have in our buffer, the values LEFT23-RIGHT33
    Now the problem comes that the sim module recognises only the values prefixed by AT+CMGF as its valid commands to send the value as sms.


    Like consider the above values in buffer LEFT23-RIGHT33

    Since these values have to be sent to a predefined number it means that the following command will have to be issued.

    AT+CMGF=1
    AT+CMGS="cell number1234"
    >value in buffer i.e (LEFT23-RIGHT33)

    Now how can we prefix these AT commands to our code in buffer..

    Do you have any idea on this....
     
  16. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    try sprintf to get the ASCII into a buffer.

    No worries with the code. It was only rotting away. best it be put to use.

    I'm a little confused with the example. I have no idea what CMGF and CMGS is?

    I think you can just use what you would type out in a terminal with sprintf.
    ie. (I'm unsure of the AT commands as above)
    char sData[30]; // this may need to be changed to a larger buffer.
    sprintf(sData, "AT+61408223344LEFT23-RIGHT33");
    TransmittMessage(sData);
     
  17. snel

    snel

    11
    0
    Jul 21, 2012
    .....:):)

    I think increasing the buffer could perhaps work in my case....
    Let me modify and implement this code and i will keep you updated...:)

    These AT commands are the commands to communicate with the GSM module
    With CMGF and CMGS are the command arguments...
    CMGF- it sets the modem to text mode
    CMGS- lets us define a predefined cell number at which the data will be sent....:)
     
  18. dahhal

    dahhal

    58
    0
    Jul 17, 2012
    Ok. Sounds like a plan. Good luck.
     
  19. snel

    snel

    11
    0
    Jul 21, 2012
    Thanks a lot dahhal for the help...:)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-