• Send/Receive SMS with STM32F103C8 and SIM800C GSM Module

QC

Send/Receive SMS with STM32F103C8 and SIM800C GSM Module


Send/Receive SMS with STM32F103C8 and SIM800C GSM Module 



Mô-đun GSM thường được sử dụng trong các dự án IoT vì nó có khả năng gửi và nhận dữ liệu từ xa. Mô-đun GSM không có nhiều phụ thuộc như mô-đun Wi-Fi. Trong khi các mô-đun không dây khác như Wi-Fi hoặc Zigbee có nhược điểm như phạm vi ngắn và chi phí, thì Mô-đun GSM có độ tin cậy, phạm vi dài Vì chỉ cần một thẻ SIM với gói hợp lệ. Mặc dù các mô-đun GSM không thể gửi một lượng lớn dữ liệu do các cảm biến tạo ra, nhưng nó rất lý tưởng cho các ứng dụng cần gửi một lượng dữ liệu hợp lý nhỏ.

Trong hướng dẫn này, mô-đun GSM như vậy sẽ được giao tiếp với vi điều khiển ARM STM32F103C8 để gửi và nhận Tin nhắn Văn bản (SMS) từ số điện thoại di động được định cấu hình trong chương trình. Để hiển thị các tin nhắn đã nhận và đã gửi, một màn hình LCD 16x2 sẽ được sử dụng với hai Nút nhấn sẽ bắt đầu gửi và nhận tin nhắn văn bản sau khi nhấn nút tương đối.

Đã có một số dự án GSM có sẵn giao diện với các loại vi điều khiển khác nhau. Bạn có thể truy cập và kiểm tra tất cả các Dự án GSM tại đây và thử Tự làm bằng cách tham khảo các hướng dẫn trước đây về các mô-đun GSM khác nhau như SIM900, SIM900A, SIM800, v.v. Một số dự án có mô-đun GSM được đưa ra dưới đây:

Components Required

  • STM32F103C8 Cortex-M3 Microcontroller
  • GSM Module (SIM800C is used in the tutorial)
  • 16x2 LCD Display
  • Push Buttons (2)
  • 10k Potentiometer
  • Breadboard
  • Connecting Wires

What is SIM800C GSM Module?





Circuit Diagram



Circuit connections between STM32F103C8 & GSM SIM800C

STM32F103C8GSM SIM800C
PA9 (TX)RX
PA10 (RX)TX
GNDGND

Hai nút Đẩy có điện trở Kéo xuống là 10k được nối với chân PA0 & PA1 của vi điều khiển STM32. Thiết lập hoàn chỉnh sẽ giống như bên dưới:



#include <LiquidCrystal.h>                           //Library for LCD display                    

const int rs = PB11, en = PB10, d4 = PB0, d5 = PB1, d6 = PC13, d7 = PC14;      //Pins that are connected between LCD and STM32

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int receive = 0;

void setup()

{
  
  lcd.begin(16,2);           //LCD set at 16x2 mode
  
  pinMode(PA0,INPUT);       //Push buttons as INPUT pins
  pinMode(PA1,INPUT);
  
  lcd.print("STM32 WITH GSM");   //Display Welcome message
  lcd.setCursor(0,1);
  lcd.print("SIM800C");
  
  Serial1.begin(9600);   // Setting the baud rate of GSM Module 

  delay(1000);

  lcd.clear();

}

void loop()

{
 
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("S to Send sms");
  lcd.setCursor(0,1);
  lcd.print("R to Receive sms");
  delay(100);
  
  
  int a = digitalRead(PA0);          //Read status of the push buttons
  int b = digitalRead(PA1);
  
  if (a == 1)                         // Depeding upon which push button is pressed the respected function is called
       {
         SendMessage();
       } 
       
else if( b == 1)
      {
         RecieveMessage();
      }
       

 
 void SendMessage()      //Function to Send Message
{
  lcd.clear();
  
  lcd.print("Sending sms");
  delay(1000);
  Serial1.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode

  delay(1000);  

  Serial1.println("AT+CMGS=\"+91XXXXXXXXXX\"\r"); // Replace x with mobile number

  delay(1000);

  Serial1.println("Hi Circuit Digest from GSM Module"); // The SMS text you want to send

  delay(100);

  Serial1.println((char)26);// ASCII code of CTRL+Z

  delay(1000);
  lcd.clear();
  lcd.print("SMS SENT");
  delay(1000);
}

 void RecieveMessage()         //Function to Receive Message

{
 
  lcd.clear();
  lcd.print("Receiving sms");

  Serial1.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS

  delay(1000);
  
  while(1)
  {
           if(Serial1.available())
            {
                do

                  {

                     while ( !Serial1.available() );    

                  } while ( '"' != Serial1.read() );

               do

                  {

                      while ( !Serial1.available() );    

                  } while ( '"' != Serial1.read() );

               do

                 {

                      while ( !Serial1.available() );    

                  } while ( '"' != Serial1.read() );

               do

                 {

                    while ( !Serial1.available() );    

                 } while ( '"' != Serial1.read() );

                do
        
                  {

                     while ( !Serial1.available() );  
                         

                  } while ( '"' != Serial1.read() );

                do

                 {
             
                    while ( !Serial1.available() );  
                       

                  } while ( '"' != Serial1.read() );

                  while ( !Serial1.available() );

                  receive = Serial1.read();     

                  while ( !Serial1.available() );

                  receive = Serial1.read();

    
    lcd.clear();

    while(1)

    {

        while ( !Serial1.available() ); 

        receive = Serial1.read();

        if ( receive == '\r' )
           
              break;
           
        else

             lcd.write(receive);
     }
}
}
}



Nap Code vào PY32F003 dùng Stlink

 Nap Code vào PY32F003 dùng Stlink Bước 1: Cài đặt  KeilC v5.39 theo link sau ( chú ý 5.39 keil c mới nạp ok). https://edge07.111.ir.cdn.ir/...