当前位置:网站首页>STM8S105K4T6------Serial port sending and receiving
STM8S105K4T6------Serial port sending and receiving
2022-08-04 02:35:00 【kick the player】
The last article talked about how to light up the boardLED,这次来讲,stm8s105k4t6的串口发送数据
不会点亮LEDlights can be seen—>stm8点亮LED
Serial port sending part
步骤: 在点亮LEDAdd a light to the baseuart.c和uart.h文件 See my picture below for the code,I explain the code later
记得要#include“uart.h”Header file and initialization serial port configuration function
main.c就几行代码,Just copy me ,下面放uart.c和uart.h的代码
Here is the initialization of the serial port pins
UART.C代码
#include "usart.h"
void Usart2_Config(void)
{
//Send and receive sockets are initialized
GPIO_Init(GPIOD, GPIO_PIN_6, GPIO_MODE_IN_PU_NO_IT);
GPIO_Init(GPIOD, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART2, ENABLE);
UART2_Init((uint32_t)115200, UART2_WORDLENGTH_8D, UART2_STOPBITS_1,UART2_PARITY_NO,UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);
UART2_ITConfig(UART2_IT_RXNE_OR, ENABLE);//开启接收中断
UART2_Cmd(ENABLE);
}
void Usart2_SendByte(u8 Byte)
{
UART2_SendData8(Byte);
while((UART2->SR & 0x80) == 0x00)
{
}
}
void Usart2_SendHalfWord(uint16_t ch)
{
uint8_t temp_h, temp_l;
/* 取出高八位 */
temp_h = (ch&0XFF00)>>8;
/* 取出低八位 */
temp_l = ch&0XFF;
/* 发送高八位 */
Usart2_SendByte(temp_h); /* 发送低八位 */
Usart2_SendByte(temp_l);
}
void Usart2_SendByteArr(u8* Buff, u16 Size)
{
while(Size--)
{
Usart2_SendByte(*Buff++);
}
}
void Usart2_SendHalfWordArr(u16* Buff, u16 Size)
{
while(Size--)
{
Usart2_SendHalfWord(*Buff++);
}
}
void Usart2_SendString(char *str)
{
unsigned int k=0;
Delay_us(100);
do
{
Usart2_SendByte(*(str + k));
k++;
}while(*(str + k)!='\0');
Delay_us(100);
}
这几个函数,It is to encapsulate the sent bytes,数组,字符串的函数,这样封装后,The code can directly call the function to realize the sending function
UART.H代码
#ifndef __USART_H
#define __USART_H
#include "stm8s_conf.h"
#define UART2_FRAME_LENGHT 30
//Interrupt buffer serial port data length
extern u8 Uart2_Buff[UART2_FRAME_LENGHT], Uart2_RecNum;
void Usart2_Config(void);
void Usart2_SendHalfWord(uint16_t ch);
void Usart2_SendByte(u8 Byte);
void Usart2_SendByteArr(u8* Buff, u16 Size);
void Usart2_SendHalfWordArr(u16* Buff, u16 Size);
void Usart2_SendString(char *str);
#endif
Finally, the serial port can send data,I have this because of the poor contact of the Dupont wire, Only when there is signal interference
串口接收部分
Because the function to be implemented here is:What is received by the serial port,We will send something out
只需要在main.cIt is enough to add the code to turn on the total interrupt
This is done in the interrupt code
This will make hair1,LED亮,否则灭
经过测试,都是没问题的,You should also try it now
边栏推荐
- 共n级台阶,每次可以上1级或2级台阶,有多少种上法?
- Zabbix设置邮件告警+企业微信告警
- 单片机C语言->的用法,和意思
- Use of lombok annotation @RequiredArgsConstructor
- Returns the maximum number of palindromes in a string
- Simple record of Flink principle flow chart
- 查看mysql死锁语法
- FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
- [QNX Hypervisor 2.2用户手册]10.3 vdev gic
- STM32-遥感数据处理
猜你喜欢
esp8266-01s刷固件步骤
Utilities of Ruineng Micrometer Chip RN2026
实例037:排序
Detailed analysis of scaffolding content
出海季,互联网出海锦囊之本地化
APP电商如何快速分润分账?
单片机C语言->的用法,和意思
【指针内功修炼】深度剖析指针笔试题(三)
Download install and create/run project for HBuilderX
In the season of going overseas, the localization of Internet tips for going overseas
随机推荐
实例037:排序
Oracle迁移到瀚高之后,空值问题处理
pytorch applied to MNIST handwritten font recognition
Example 039: Inserting elements into an ordered list
Big guys, it takes a long time to read mysql3 million single tables, what parameters can be discounted, or is there any way to hurry up
Engineering drawing review questions (with answers)
[QNX Hypervisor 2.2 User Manual] 10.3 vdev gic
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
自制蓝牙手机app控制stm8/stm32/C51板载LED
返回字符串中的最大回文数
WPE详细教程
ant-design的Select组件采用自定义后缀图标(suffixIcon属性)时,点击该自定义图标没有反应,不会展示下拉菜单的问题
STM8S-----option byte
flinkcdc 消费 mysql binlog 没有 sqltype=delete 的数据是什么原
各位大佬好,麻烦问一下flink cdc oracle写入doris的时候,发现cpu异常,一下下跑
Utilities of Ruineng Micrometer Chip RN2026
There are too many systems, how to realize multi-account interworking?
TOML配置文件格式,YAML最有力的竞争者
MallBook 助力SKT思珂特教育集团,立足变化,拥抱敏捷交易
How many ways do you know about communication between multiple threads?