当前位置:网站首页>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
边栏推荐
- Cohere博客:在生产环境中运行大型语言模型-推理框架概览
- flink 写redis 比较慢,大家有啥思路优化吗?
- 《多线程下ThreadLocal使用场景实例》
- 了解string类
- Here blog: running a large language model in a production environment - overview of the reasoning framework
- 远程ip Debugger(实用干货)
- pytest接口自动化测试框架 | pytest之fixture介绍
- 大量if else判断如何优化?@Valib详解
- Pytest interface automated test framework | fixture call fixture
- 基于 Flink CDC 实现海量数据的实时同步和转换
猜你喜欢

4.1 configure MySQL and register login module

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

Is it easy to find a job after programmer training?

Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum

国内11所“袖珍”大学!在校园跑步,还没加速就出校门了...

使用fastJson中的JSONObject对象简化POST请求传参
![[download attached] a powerful web automated vulnerability scanning tool - Xray](/img/5e/1db72ce9bf758b1e68e8d6d2026302.png)
[download attached] a powerful web automated vulnerability scanning tool - Xray

了解string类

音视频技术开发周刊 | 255

Ga-rpn: recommended area network for guiding anchors
随机推荐
Pycharm is really strong
Is it easy to find a job after programmer training?
What is per title encoding?
Li Kai: the interesting and cutting-edge audio and video industry has always attracted me
网络协议:TCP/IP协议
Audio and video+
Talking about web vitals
FPGA入门学习(三)- 38译码器
一些实用、常用、效率越来越高的 Kubernetes 别名
Flink 在 讯飞 AI 营销业务的实时数据分析实践
Pytest interface automation test framework | use decorators to decorate the use cases that need to be run
种种迹象表明,Apple将有望支持AV1
DS-112时间继电器
连锁店收银系统如何帮助鞋店管理好分店?
Introduction to FPGA (III) - 38 decoder
元宇宙日报|元宇宙社交 App“派对岛”产品下架;广州南沙元宇宙产业集聚区揭牌;数字经济发展部际联席会议制度推出
2022就业季!Adobe助力创意产业工作者,突破技能桎梏,回归能力本源
Pytest interface automation test framework | setup and teardown functions of pytest
【活动早知道】LiveVideoStack近期活动一览
pytest接口自动化测试框架 | conftest.py