当前位置:网站首页>Sim900a based on STM32 sends short messages in Chinese and English
Sim900a based on STM32 sends short messages in Chinese and English
2022-07-26 12:07:00 【Steamed bass is not delicious】
Catalog
The first part 、 About SIM900A Basic knowledge of
1、SIM900A Mode of communication
2、SIM900A The power supply mode of the system
3、 Meaning of common instructions
send out SIM Card detection instruction and signal quality detection instruction
One 、 Send English text messages
Two 、 Send Chinese text messages ( a key )
The third part 、STM32 drive SIM900A Send SMS in Chinese and English
1. Wiring mode of module and MCU
The first part 、 About SIM900A Basic knowledge of
1、SIM900A Mode of communication
SIM900A Module adoption A serial port (UART) signal communication , Every SIM900A Development boards contain TTL Interface , The main use is 5VR(RXD) and 5VT(TXD),3VR and 3VT Generally used, rarely used .
Serial chip USB-TTL Modules are recommended ft232>cp2102>ch340
2、SIM900A The power supply mode of the system
It is best to 5V2A The battery , Otherwise, there may be insufficient current to send text messages .5V1A It's fine too .
The following figure for External power supply mode Wiring diagram : The power module in the figure goes to Taobao by itself “ Power conversion module 5V”, Search a lot .

The following figure for USB—TTL Direct power supply The wiring diagram of :

3、 Meaning of common instructions
AT+CPMS // Inquire about SIM Use status of SMS in card
AT+CNMI // The new message indicates the setting
AT+CMGF // Select the SMS format
AT+CSCS // Encoding settings
AT+CSCA // Inquire about 、 Set up SMS Service center number
AT+CSMP // Set SMS text mode parameters
AT+CMGS // Send SMS
AT+CMGR // Read SMS
AT+CMGD // Delete SMS
AT+CMGDA // Delete all short messages
AT&F // Restore factory settings
AT+CSQ // Signal quality The second part 、 Using computers A serial port Assistant implementation SIM900A Send SMS in English and Chinese ( test SIM900A Module function )
Mobile card is recommended !!! I used Unicom card and failed
It is recommended to use the serial port assistant provided by the seller , Otherwise, there may be confusion
send out SIM Card detection instruction and signal quality detection instruction
Be careful : The signal quality value is 0—31 Between , The larger the signal, the stronger .0 Means no signal , Generally, this number should reach 10 above , The module can correctly perform functions such as sending text messages .
AT // Check send new line
OK
AT+CPIN? // Query whether SIM card
+CPIN: READY
OK
AT+CSQ // Query signal quality
+CSQ: 18,0
OKOne 、 Send English text messages
AT+CSCS="GSM"
AT+CMGF=1
AT+CMGS="132******63" // Phone number
>okokok // information content
1A( Check the serial port assistant 16 Base send )Send hexadecimal 0x1A Its meaning is to tell SIM900A Confirm sending , Then wait a few seconds , appear OK Means the delivery is successful. .



Two 、 Send Chinese text messages ( a key )
1、 Examples of mistakes
I believe many people have read the data manual and PPT, Can successfully send English text messages, but can not successfully send Chinese text messages , I also stepped on this pit , According to customer service information PPT Routines given in , Failed to send Chinese SMS , Will be submitted to the ERROR error !!!

as follows : This is my routine of screenshots from the information given by customer service , The code is as follows
AT+CMGF=1
AT+CSCS="UCS2"
AT+CSMP=17,167,0,24
AT+CMGS="00310033003200320035003500360037003200360033" // Of mobile phone number Unicode code
> 4F60597D // Content of short message ( Hello )Unicode code
ox1a // Means to send 
To tell you the truth, it's very stupid here , I spent the afternoon , At first I thought it was on SIM900A The card on is in arrears , It's useless for me to pay money , Then I searched the whole CSDN Community , I found that many old irons encountered the same problems as me , Then I happened to see this brother's blog ,Text Send Chinese SMS in mode (Sim900A R11.0)_boliu218 The blog of -CSDN Blog , A line of code configuration is found to be different from that in the routine , as follows :
AT+CSMP=17,167,0,8 // Represents normal text mode
The difference here is the fourth parameter , Then I looked for the instruction manual for a detailed explanation of this instruction , The most important thing to pay attention to is : The fourth parameter is 0 It means English mode , by 8 Represents Chinese normal text mode .
2、 Send a successful example
AT+CMGF=1
AT+CSCS="UCS2"
AT+CSMP=17,167,0,8 // Normal text mode
AT+CMGS="00310033003200320035003500360037003200360033" // Of mobile phone number Unicode code
> 4F60597D // Content of short message ( Hello )Unicode code
ox1a // Means to send 
Be careful : Here we need to use Chinese Translation Unicode Coded software , The shopkeeper will give it
The third part 、STM32 drive SIM900A Send SMS in Chinese and English
About Unicode code
Unicode Basic introduction
Unicode Generally refers to unified code , It's also called the universal code 、 Single code , It's an industry standard in the field of computer science , Include character set 、 Coding scheme, etc .Unicode It is to solve the limitation of traditional character coding scheme , It sets a uniform and unique binary encoding for each character in each language , To meet cross language needs 、 Cross platform text conversion 、 Handling requirements .
1、 Encoding mode
unicode It is a character coding scheme developed by international organizations that can accommodate all characters and symbols .Unicode Use numbers 0-0x10FFFF To map these characters , Maximum capacity 1114112 Characters , Or there is 1114112 A code bit . A code point is a number that can be assigned to a character .UTF-8、UTF-16、UTF-32 They are all coding schemes that convert numbers to program data .
We put ASCII The string is converted into a double byte Chinese character unicode Code you find 1 This character becomes 0031
this 31 Did you think of something ,1 Of 16 No, it's just 0X31 Do you ? Front complement 2 individual 0 The back is its 16 It's over ?

/**********************************************************************
describe : ASCII turn unicode such as '1' Turn into "0031"
***********************************************************************/
void ASCII_TO_Unicode(char *ASCII,char *Unicode)
{
int length;
int i = 0;
int j = 0;
memset(Unicode,'\0',sizeof(Unicode));
length = strlen(ASCII);
for(i=0;i<length;i++)
{
Unicode[j++] = '0';
Unicode[j++] = '0';
Unicode[j++] = (ASCII[i] / 16) + 0x30;
Unicode[j++] = (ASCII[i] % 16) + 0x30;
}
}

1. Module and Single chip microcomputer Wiring mode
1、 The power supply of the single chip microcomputer is connected to the corresponding power supply
| Single chip microcomputer PB10 | Corresponding to | SIM900A The pins of 5VR |
| Single chip microcomputer PB11 | Corresponding to | SIM900A The pins of 5VT |
| Single chip microcomputer GND | Corresponding to | modular GND |
| Single chip microcomputer 5V | Corresponding to | modular VCC_MCU |
2、 The module is powered separately
| Modular VCC( or VCC5V) | Corresponding to | external DC5V |
| Modular GND | Corresponding to | External power supply GND |
2. Send English text messages
/**************************************************************************/
// Function function : Send English SMS function
// The name of the function :sim900a_send_English_message(char *message,char *phonenumber)(uint8_t number);
// Internal parameters :message phonenumber
// modification date :2022 year 1 month 26 Japan In the morning 2:40、
// author : (CSDN search ) Big fart peach
/**************************************************************************/
void sim900a_send_English_message(char *message,char *phonenumber)
{
Usart_SendString2(USART3,"AT\r\n"); //SIM900A Whether the connection with MCU is successful
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("English_message_OK1\r\n");
Usart_SendString2(USART3,"AT&F\r\n"); //SIM900A Reset
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK")); // String matching function
printf("English_message_OK2\r\n");
Usart_SendString2(USART3,"AT+CSCS=\"GSM\"\r\n"); // English SMS instructions 1
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("English_message_OK3\r\n");
Usart_SendString2(USART3,"AT+CMGF=1\r\n"); // English SMS instructions 2
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("English_message_OK4\r\n");
sprintf(dispbuf,"AT+CMGS=\"%s\"\r\n",phonenumber);
Usart_SendString2(USART3,dispbuf); // English SMS instructions 3
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("English_message_OK5\r\n");
Usart_SendString2(USART3,message); // English SMS instructions 4
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("English_message_OK6\r\n");
Usart_SendHalfWord(USART3,0x1a); // End order
delay_ms(2000); // Two seconds later
while(Find_char((char*)Usart3_buff,"OK"));
printf("English_message_OK7\r\n");
} 2. Send Chinese text messages
The difference between sending Chinese and sending English is that the phone number and content should be used Unicode coded , This requires conversion software , Or use the above conversion code . Secondly, there is one more line of code than sending English Usart_SendString2(USART3,"AT+CSMP=17,167,0,8\r\n");
/**************************************************************************/
// Function function : Send Chinese SMS function
// The name of the function :sim900a_send_Chinese_message(char *message,char *phonenumber)(uint8_t number);
// Internal parameters :message phonenumber
// modification date :2022 year 1 month 26 Japan In the morning 2:40
// author : (CSDN search ) Big fart peach
/**************************************************************************/
void sim900a_send_Chinese_message(char *message,char *phonenumber)
{
Usart_SendString2(USART3,"AT\r\n"); //SIM900A Whether the connection with MCU is successful
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK")); // String matching function
printf("Chinese_message_OK1\r\n");
Usart_SendString2(USART3,"AT&F\r\n"); //SIM900A Reset
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK2\r\n");
Usart_SendString2(USART3,"AT+CSCS=\"UCS2\"\r\n"); // Chinese SMS instructions 1
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK3\r\n");
Usart_SendString2(USART3,"AT+CMGF=1\r\n"); // Chinese SMS instructions 2
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK4\r\n");
Usart_SendString2(USART3,"AT+CSMP=17,167,0,8\r\n"); // Chinese SMS instructions 2
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK5\r\n");
sprintf(dispbuf,"AT+CMGS=\"%s\"\r\n",phonenumber);
Usart_SendString2(USART3,dispbuf); // Chinese SMS instructions 3
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK6\r\n");
Usart_SendString2(USART3,message); // Chinese SMS instructions 4
delay_ms(200);
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK7\r\n");
Usart_SendHalfWord(USART3,0x1a); // Chinese end instruction
delay_ms(2000); // Two seconds later
while(Find_char((char*)Usart3_buff,"OK"));
printf("Chinese_message_OK8\r\n");
} Last
In fact, I'm just an integrator
I have referred to many people's articles
边栏推荐
- El form displays two columns per row, with the bottom button centered
- Li Kai: the interesting and cutting-edge audio and video industry has always attracted me
- 浅谈Web Vitals
- pytest接口自动化测试框架 | pytest之fixture介绍
- [ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
- 三维点云课程(八)——特征点匹配
- 二、容器_
- Pytest interface automation test framework | pytest configuration file
- Use of strjoin function in MATLAB
- 美容院管理系统统一管理制度?
猜你喜欢

Introduction to FPGA (II) - one out of two selector

Harbor2.2 quick check of user role permissions

There are various signs that apple is expected to support AV1

Pytest interface automation test framework | pytest configuration file
![[download attached] a powerful web automated vulnerability scanning tool - Xray](/img/5e/1db72ce9bf758b1e68e8d6d2026302.png)
[download attached] a powerful web automated vulnerability scanning tool - Xray

Use the jsonobject object in fastjason to simplify post request parameter passing

空洞卷积详解(输入输出大小分析)

Is it easy to find a job after programmer training?

Pytoch deep learning quick start tutorial -- mound tutorial notes (II)

el-form 每行显示两列,底部按钮居中
随机推荐
什么是Per-Title编码?
Here blog: running a large language model in a production environment - overview of the reasoning framework
以太网驱动详解之RMII、SMII、GMII、RGMII接口
Flutter 学习之路
网络协议:TCP/IP协议
Mongodn database is connected in the form of URL
基于STM32的SIM900A发送中文和英文短信
【Mysql约束】
FPGA入门学习(二) - 二选一的选择器
Flutter JNI confusion introduction.So file release package flash back
《多线程下ThreadLocal使用场景实例》
Pycharm is really strong
SSJ-21B时间继电器
【2243】module_param.m
Pytoch deep learning quick start tutorial -- mound tutorial notes (I)
浅谈Web Vitals
专访即构科技李凯:音视频的有趣、行业前沿一直吸引着我
An online duplicate of a hidden bug
连锁店收银系统如何帮助鞋店管理好分店?
Pytest interface automated testing framework | confitest.py