Increase your Embedded skills with our new online classes (from Just Rs750/-) for details click here

For all your embedded quires visit our new forum.embed4u.com

Home > Projects > MSP430 launchpad GSM Modem interface

MSP430 launchpad GSM Modem interface

September 15th, 2012

MSP430 launchpad GSM Modem interface
In This project we are using MSP430 launchpad kit Additionally add only max232 line driver kit,GSM modem sim300, the cross cable is used to connect between GSM Modem and Max232 Board.The cross cable Tx and Rx Connected Inverted like Null Modem.If you need give External power supply for MSP430 Launchpad for 3.3v using LM317 or any other voltage source for Microcontroller.
First connect the max 232 board to launchpad P1.1 and P1.2 for UART in the launchpad kit check the hardware for proper connection.
Insert the Sim card into Modem check the Signal in the modem alive or not Type the Message “PW1″ to send the message insert sim card in the modem 1 to 2 sec u will see the RGB LED will glow different Color in your kit.. the same way type PW2 and Pw3 so on..
sour code:

//******************************************************************************
//  MSP430G2xx1 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, 32kHz ACLK
//
//  Description: Use Timer_A CCR0 hardware output modes and SCCI data latch
//  to implement UART function @ 9600 baud.a Software does not directly read and
//  write to RX and TX pins, instead proper use of output modes and SCCI data
//  latch are demonstrated. Use of these hardware features eliminates ISR
//  latency effects as hardware insures that output and input bit latching and
//  timing are perfectly synchronised with Timer_A regardless of other
//  software activity. In the Mainloop the UART function readies the UART to
//  receive one character and waits in LPM3 with all activity interrupt driven.
//  After a character has been received, the UART receive function forces exit
//  from LPM3 in the Mainloop which configures the port pins (P1 & P2) based
//  on the value of the received byte (i.e., if BIT0 is set, turn on P1.0).

//  ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO
//  //* An external watch crystal is required on XIN XOUT for ACLK *//
//
//               MSP430G2xx1
//            -----------------
//        /|\|              XIN|-
//         | |                 | 32kHz
//         --|RST          XOUT|-
//           |                 |
//           |   CCI0B/TXD/P1.1|-------->
//           |                 | 9600 8N1
//           |   CCI0A/RXD/P1.2|<--------
//
//  D. Dang
//  Texas Instruments Inc.
//  October 2010
//  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include "msp430g2231.h"
#include "pwm.h"

//------------------------------------------------------------------------------
// Hardware-related definitions
//------------------------------------------------------------------------------
#define UART_TXD   0x02                     // TXD on P1.1 (Timer0_A.OUT0)
#define UART_RXD   0x04                     // RXD on P1.2 (Timer0_A.CCI1A)

//------------------------------------------------------------------------------
// Conditions for 9600 Baud SW UART, SMCLK = 1MHz
//------------------------------------------------------------------------------
#define UART_TBIT_DIV_2     (1000000 / (9600 * 2))
#define UART_TBIT           (1000000 / 9600)

//------------------------------------------------------------------------------
// Global variables used for full-duplex UART communication
//------------------------------------------------------------------------------
unsigned int txData,i,flag;                        // UART internal variable for TX

unsigned char rxBuffer,a[20],b[4]={'P','W','1'},c[4]={'P','W','2'},d[4]={'P','W','3'};                     // Received UART character
unsigned int y1,z1,a1;

//------------------------------------------------------------------------------
// Function prototypes
//------------------------------------------------------------------------------
void TimerA_UART_init(void);
void TimerA_UART_tx(unsigned char byte);
void TimerA_UART_print(char *string);

void delay(unsigned int z)
 {
 	unsigned i,j;
 	for(i=0;i<z;i++)
 	 for(j=0;j<1000;j++);
 }
//------------------------------------------------------------------------------
// Function configures Timer_A for full-duplex UART operation
//------------------------------------------------------------------------------
void TimerA_UART_init(void)
{
    TACCTL0 = OUT;                          // Set TXD Idle as Mark = '1'
    TACCTL1 = SCS + CM1 + CAP + CCIE;       // Sync, Neg Edge, Capture, Int
    TACTL = TASSEL_2 + MC_2;                // SMCLK, start in continuous mode
}
//------------------------------------------------------------------------------
// Outputs one byte using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_tx(unsigned char byte)
{
    while (TACCTL0 & CCIE);                 // Ensure last char got TX'd
    TACCR0 = TAR;                           // Current state of TA counter
    TACCR0 += UART_TBIT;                    // One bit time till first bit
    TACCTL0 = OUTMOD0 + CCIE;               // Set TXD on EQU0, Int
    txData = byte;                          // Load global variable
    txData |= 0x100;                        // Add mark stop bit to TXData
    txData <>= 1;
        txBitCnt--;
    }
}
//------------------------------------------------------------------------------
// Timer_A UART - Receive Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMERA1_VECTOR
__interrupt void Timer_A1_ISR(void)
{
    static unsigned char rxBitCnt = 8;
    static unsigned char rxData = 0;

    switch (__even_in_range(TAIV, TAIV_TAIFG)) { // Use calculated branching
        case TAIV_TACCR1:                        // TACCR1 CCIFG - UART RX
            TACCR1 += UART_TBIT;                 // Add Offset to CCRx
            if (TACCTL1 & CAP) {                 // Capture mode = start bit edge
                TACCTL1 &= ~CAP;                 // Switch capture to compare mode
                TACCR1 += UART_TBIT_DIV_2;       // Point CCRx to middle of D0
            }
            else {
                rxData >>= 1;
                if (TACCTL1 & SCCI) {            // Get bit waiting in receive latch
                    rxData |= 0x80;
                }
                rxBitCnt--;
                if (rxBitCnt == 0) {             // All bits RXed?
                    rxBuffer = rxData;           // Store in global variable
                    rxBitCnt = 8;                // Re-load bit counter
                    TACCTL1 |= CAP;              // Switch compare to capture mode
                    __bic_SR_register_on_exit(LPM0_bits);  // Clear LPM0 bits from 0(SR)
                }
            }
            break;
    }
}
//------------------------------------------------------------------------------
// main()
//------------------------------------------------------------------------------
void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;               // Stop watchdog timer
    P1SEL& ~(BIT0|BIT4|BIT5);            // port 2 all out
 //   P1OUT = 0;//
   // P1DIR = 0xFF;//

    DCOCTL = 0x00;                          // Set DCOCLK to 1MHz
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;

    P1OUT = 0x00;                           // Initialize all GPIO
    P1SEL = UART_TXD + UART_RXD;            // Timer function for TXD/RXD pins
    P1DIR = 0xFF & ~UART_RXD;               // Set all pins but RXD to output
    P2OUT = 0x00;
    P2SEL = 0x00;
    P2DIR = 0xFF;

    __enable_interrupt();
            __delay_cycles(5000);
    TimerA_UART_init();                     // Start Timer_A UART
        __delay_cycles(5000);
        __delay_cycles(5000);

    TimerA_UART_print("AT+CMGF=1\r\n");
        __delay_cycles(5000);
        __delay_cycles(5000);
    TimerA_UART_print("AT+CNMI=1,2,0,0,0\r\n");
        __delay_cycles(5000);
        __delay_cycles(5000);

    for (;;)
    {
        // Wait for incoming character
        __bis_SR_register(LPM0_bits);

	flag=0;i=0;

	while(i<3)
	{
	a[i]=rxBuffer;
	if (a[i]==b[i]){i++; flag=1;}
	else if (a[i]==c[i]){i++; flag=2;}
	else if (a[i]==d[i]){i++; flag=3;}
	}
	//
	    if(flag==1)
	    {

	       pwm1();
	    }
	    if(flag==2)
        {
         pwm2();
        }
      if(flag==3)
	   {
  	    	pwm_gen();
	   }

    }

}

/****************************************************************/
Header file PWM.h


unsigned int x1,i;

unsigned int x1;
void pwm1()
{
	P1OUT ^= 0x31; 		  // green LED on
	_delay_cycles(100000);
	P1OUT ^= 0x10; 		  // green LED on
	_delay_cycles(60000);
	P1OUT ^= 0x20; 		  // green LED on
	_delay_cycles(40000);
	P1OUT ^= 0x31; 		  // green LED on
	_delay_cycles(50000);
	P1OUT ^= 0x01; 		  // green LED on.
	_delay_cycles(500);
	P1OUT ^= 0x31; 		  // green LED on
	_delay_cycles(50);
	P1OUT ^= 0x00;
	P1OUT ^= 0x01; 		  // green LED on
	_delay_cycles(300000);
	P1OUT ^= 0x31;
	_delay_cycles(2000);
	P1OUT ^= 0x20;
	_delay_cycles(10000);
	P1OUT ^= 0x31;
	_delay_cycles(40000);
	P1OUT ^= 0x01;
	_delay_cycles(100000);
	P1OUT ^= 0x00;
}
void led2_fade()
{
	P1OUT ^= 0x10; 		  // green LED on
	_delay_cycles(1000);
	P1OUT ^= 0x20; 		  // green LED on
	_delay_cycles(3000);
	P1OUT ^= 0x01; 		  // green LED on
	_delay_cycles(600);
}
	void led3_fade()
{
	P1OUT ^= 0x20; 		  // green LED on
	_delay_cycles(600);
	P1OUT ^= 0x01; 		  // green LED on
	_delay_cycles(1000);
	P1OUT ^= 0x10; 		  // green LED on
	_delay_cycles(900);
}
	void led4_fade()
{
	P1OUT ^= 0x01; 		  // green LED on
	_delay_cycles(3000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(70000);
}

void led5_fade()
{
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(90);
	P1OUT ^= 0x10; 		  // green LED on
	_delay_cycles(20000);
}

void pwm_gen()
{
for(x1=0;x1<3;x1++)
   {
   	pwm1();
   	_delay_cycles(8000);
   }
  for(x1=0;x1<4;x1++)
   {
   	led2_fade();
   	_delay_cycles(400);
   }

  for(x1=0;x1<3;x1++)
   {
   	led3_fade();
   	_delay_cycles(2000);
   }
  for(x1=0;x1<2;x1++)
   {
   	led5_fade();
   	_delay_cycles(600);
   }
  for(x1=0;x1<1;x1++)
   {
   	pwm1();
   	_delay_cycles(50);
   }
   for(x1=0;x1<5;x1++)
   {
   	pwm1();
   		_delay_cycles(500000);
   }
 for(x1=0;x1<5;x1++)
   {
   	led2_fade();
   		_delay_cycles(50);
   }
 for(x1=0;x1<4;x1++)
   {
   	led2_fade();
   		_delay_cycles(500);
   }
 for(x1=0;x1<3;x1++)
   {
   	led2_fade();
   		_delay_cycles(580);
   }
 for(x1=0;x1<2;x1++)
   {
   	led2_fade();
   		_delay_cycles(9500);
   }
  for(x1=0;x1<1;x1++)
   {
   	led3_fade();
   		_delay_cycles(500);
   }
    for(x1=0;x1<1;x1++)
   {
   	led4_fade();
   	_delay_cycles(1060);
   }
   for(x1=0;x1<1;x1++)
   {
   	led5_fade();
   	_delay_cycles(1000);
   }
}

void pwm2()
 {
  	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(100000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(5000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(900);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(300000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(500000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(12005);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(50080);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(6000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(400000);
	P1OUT ^= 0x30; 		  // green LED on
	_delay_cycles(50000);
	P1OUT ^= 0x31; 		  // green LED on
	_delay_cycles(500000);
 }



Related posts:

  1. GSM SIM300 PCO COIN BOX PROJECT
  2. sim300 GPRS modem C Driver
  3. GSM BASED INDUSTRIAL AUTOMATION
  4. 8051 Embedded ‘C’ Program for Toggle LED’s
  5. Thermocouple Interface with pic16f877a microcontroller with ad595:
Comments are closed.