Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

GSM with 8051F330 C Language

Status
Not open for further replies.

Qrios

Newbie level 6
Newbie level 6
Joined
May 3, 2012
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,356
I am trying to write a program that uses C programming to send sms through a GSM modem. I am confused about the initialization of the micro-controller. (C8051F330)
This is the code I found online **broken link removed**
and this is the modem I'm using https://rainbow.com.ua/upload/files/modemi/Q2403 Application Note.pdf

If I am using C8051F330 instead of at89x51, how should I change the initialization of the program?

Code:
void initialize_serialcommunication(void){
TMOD = 0x20;
SCON = 0x50;        
TH1  = 0xFD;       
TL1  = 0xFD;        
TR1  = 1; 
TI = 1;
}

Another code i found is :

Code:
xdata char tBuff[50], rBuff[150];

void serialInit(void) {
uartInit(96); 
EA= 1;
ES=1;
siInit(50, tBuff, 150, rBuff);(I cannot find the code on this )
T1=1;
 
Last edited by a moderator:

The function initialize_serialcommunication() initialises the USART on 8051 check the hardware and find out the baud rate and you also intilise to the same baud on your microcontroller
 
  • Like
Reactions: Qrios

    Qrios

    Points: 2
    Helpful Answer Positive Rating
I checked the baud rate on my micro controller and adjusted accordingly, it still doesn't work, how else should I change the program?
 

I checked the baud rate on my micro controller and adjusted accordingly, it still doesn't work, how else should I change the program?

First check the voltage of both your microcontroller and GSM, first read the data sheet and using serial cable connect the GSM to the computer. Now verify whether your GSM responds to your AT commands by sending the "AT" from "hyperterminal" if you get it as ok then connect it to your microcontroller or find the baud at which your GSM works by sending the same command at different frequencies.
 
  • Like
Reactions: Qrios

    Qrios

    Points: 2
    Helpful Answer Positive Rating
First check the voltage of both your microcontroller and GSM, first read the data sheet and using serial cable connect the GSM to the computer. Now verify whether your GSM responds to your AT commands by sending the "AT" from "hyperterminal" if you get it as ok then connect it to your microcontroller or find the baud at which your GSM works by sending the same command at different frequencies.

I already did the things that is mentioned and it is most probably functioning.
 

I already did the things that is mentioned and it is most probably functioning.

So check your microcontroller's clock source , Use external clock source or crystal for your microcontroller.
What did you get, when you sent "AT" from hyper-terminal.
 

So check your microcontroller's clock source , Use external clock source or crystal for your microcontroller.
What did you get, when you sent "AT" from hyper-terminal.
I got 'OK' and 'Ready' after AT+CPIN?
 

For future reference the Silicon Labs examples provided in the IDE installation are quite useful.

Example, F33x_UART_STDIO.c:
Code:
//-----------------------------------------------------------------------------
// F33x_UART_STDIO.c
//-----------------------------------------------------------------------------
// Copyright 2006 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program demonstrates how to configure the C8051F330 to use routines
// in STDIO.h to write to and read from the UART interface.  The program
// reads a character using the STDIO routine getkey(), outputs that character
// to the screen, and then outputs the ASCII hex value of that character.
//
//
// How To Test:
//
// 1) Ensure that jumpers are placed on J12 of the C8051F330 target board
//    that connect P0.4 to the TX signal, and P0.5 to the RX field.
// 2) Ensure that the serial cable is connected to the RS232 connector
//    on the target board.
// 3) Specify the target baudrate in the constant <BAUDRATE>.
// 4) Open Hyperterminal, or a similar program, and connect to the target
//    board's serial port. 
// 5) Download and execute code to an 'F330 target board.
//   
//
// FID:            33X000035
// Target:         C8051F33x
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
// Command Line:   None
//
// Release 1.0
//    -Initial Revision (PD)
//    -16 AUG 2006
//

//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------

#include <c8051f330.h>                 // SFR declarations
#include <stdio.h>

//-----------------------------------------------------------------------------
// Global CONSTANTS
//-----------------------------------------------------------------------------

#define SYSCLK      24500000           // SYSCLK frequency in Hz
#define BAUDRATE        9600           // Baud rate of UART in bps


//-----------------------------------------------------------------------------
// Function PROTOTYPES
//-----------------------------------------------------------------------------

void SYSCLK_Init (void);
void UART0_Init (void);
void PORT_Init (void);
void Timer2_Init (int);

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------

void main (void) 
{
   unsigned char inputcharacter;       // Used to store character from UART

   PCA0MD &= ~0x40;                    // WDTE = 0 (clear watchdog timer 
                                       // enable)
   PORT_Init();                        // Initialize Port I/O
   SYSCLK_Init ();                     // Initialize Oscillator
   UART0_Init();

   while (1)
   {
      printf ("\nEnter character: ");
      inputcharacter = getchar ();
      printf ("\nCharacter entered : %c",inputcharacter);
      printf ("\n      Value in Hex: %bx",inputcharacter);

   }
}

//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configure the Crossbar and GPIO ports.
//
// P0.4   digital   push-pull    UART TX
// P0.5   digital   open-drain   UART RX
// 
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
   P0MDOUT |= 0x10;                    // Enable UTX as push-pull output
   XBR0    = 0x01;                     // Enable UART on P0.4(TX) and P0.5(RX)                     
   XBR1    = 0x40;                     // Enable crossbar and weak pull-ups
}

//-----------------------------------------------------------------------------
// SYSCLK_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This routine initializes the system clock to use the internal oscillator
// at its maximum frequency.
// Also enables the Missing Clock Detector.
//-----------------------------------------------------------------------------

void SYSCLK_Init (void)
{
   OSCICN |= 0x03;                     // Configure internal oscillator for
                                       // its maximum frequency
   RSTSRC  = 0x04;                     // Enable missing clock detector
}

//-----------------------------------------------------------------------------
// UART0_Init
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// Configure the UART0 using Timer1, for <BAUDRATE> and 8-N-1.
//-----------------------------------------------------------------------------
void UART0_Init (void)
{
   SCON0 = 0x10;                       // SCON0: 8-bit variable bit rate
                                       //        level of STOP bit is ignored
                                       //        RX enabled
                                       //        ninth bits are zeros
                                       //        clear RI0 and TI0 bits
   if (SYSCLK/BAUDRATE/2/256 < 1) {
      TH1 = -(SYSCLK/BAUDRATE/2);
      CKCON &= ~0x0B;                  // T1M = 1; SCA1:0 = xx
      CKCON |=  0x08;
   } else if (SYSCLK/BAUDRATE/2/256 < 4) {
      TH1 = -(SYSCLK/BAUDRATE/2/4);
      CKCON &= ~0x0B;                  // T1M = 0; SCA1:0 = 01                  
      CKCON |=  0x01;
   } else if (SYSCLK/BAUDRATE/2/256 < 12) {
      TH1 = -(SYSCLK/BAUDRATE/2/12);
      CKCON &= ~0x0B;                  // T1M = 0; SCA1:0 = 00
   } else {
      TH1 = -(SYSCLK/BAUDRATE/2/48);
      CKCON &= ~0x0B;                  // T1M = 0; SCA1:0 = 10
      CKCON |=  0x02;
   }

   TL1 = TH1;                          // Init Timer1
   TMOD &= ~0xf0;                      // TMOD: timer 1 in 8-bit autoreload
   TMOD |=  0x20;                       
   TR1 = 1;                            // START Timer1
   TI0 = 1;                            // Indicate TX0 ready
}

//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------

There are also quite a few informative appnotes available at the website.

BigDog
 
  • Like
Reactions: Qrios

    Qrios

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top