当前位置:网站首页>Learning records: serial communication and solutions to errors encountered
Learning records: serial communication and solutions to errors encountered
2022-07-06 15:33:00 【Bitter tea seeds】
List of articles
Learning notes : The concept of serial communication and programming to realize serial communication .
Encountered …\OBJ\Project.axf: Error: L6200E: Symbol USART1_IRQHandler multiply defined (by usart.o and main.o). Error resolution !
List of articles
- List of articles
- Preface
- One 、 Basic knowledge of serial communication
- Two 、 Programming
- 3、 ... and 、..\OBJ\Project.axf: Error: L6200E: Symbol USART1_IRQHandler multiply defined (by usart.o and main.o). Error resolution
- summary
Preface
I've been reading 《 The embedded C Self cultivation of language 》 Learned a lot of knowledge , Especially compilation and C Function call for , This is also used in learning serial communication C Language calls assembly functions and NVIC Writing of interrupt program .
The following is my summary of knowledge, as well as how to write serial communication programs and NVIC Interrupt the procedure ( It mainly refers to the reference manual of punctual atoms ).
One 、 Basic knowledge of serial communication
1. There are two ways for the processor to communicate with external devices :
Parallel communication
- Transmission principle : All bits of data are transmitted at the same time .
- advantage : Fast
- shortcoming : It takes up a lot of pin resources
serial communication
- Transmission principle : Data transmission in bit order .
- advantage : Less pin resources
- shortcoming : Relatively slow
1.1 serial communication
According to the data transmission direction , It is divided into :
Simplex :
Data transmission only supports data transmission in one direction .
Half duplex :
Allows data to be transmitted in both directions , however , At some point , Only number allowed
It is transmitted in one direction , It's actually a kind of direction switching simplex communication ;
full duplex :
Allows data to be transmitted in both directions at the same time , therefore , Full duplex communication is two
Combination of simplex communication , It requires that both the sending device and the receiving device have independent
Ability to receive and send .
There are three transmission modes of serial communication :
1.2 Communication mode of serial communication
Synchronous communication : With clock Synchronous signal transmission .
-SPI,IIC communication interface ;
asynchronous communication : Without clock Synchronous signal .
-UART( Universal asynchronous transceiver ), Single bus ;
2. Common serial communication interface
Communication standards | Pin description | communication mode | Direction of communication |
---|---|---|---|
UART( Universal asynchronous transceiver ) | TXD: The sender ;RXD: The receiving end ;GND: In public | asynchronous communication | full duplex |
Single bus (1-wire) | DQ: send out / The receiving end | asynchronous communication | Half duplex |
SPI | SCK: Synchronous clock ;MISO: Host input , Slave output ;MOSI: Host output , Slave input | Synchronous communication | full duplex |
IIC | SCL: Synchronous clock ;SDA: data input / Output terminal | Synchronous communication | Half duplex |
2.1、STM32 Serial communication interface
UART: Universal asynchronous transceiver ;
USART: Universal synchronous asynchronous transceiver ;
2.2、UART Asynchronous communication mode pin connection method :
-RXD: Data input pin . Data reception .
-TXD: Data transmission pin . Data sending .
2.3、UART Characteristics of asynchronous communication mode :
- Full duplex asynchronous communication .
- Fractional baud rate generator system , Provide accurate baud rate .
- Send and receive common programmable baud rate , Up to 4.5Mbits/s - Programmable data word length (8 Bits or 9 position );
- Configurable stop bits ( Support 1 perhaps 2 Bit stop bit );
- Configurable use DMA Multi buffer communication .
- Separate transmitter and receiver enable bits .
- Detection marks :① Accept buffer ② Send buffer empty ③ End of transmission flag
- Multiple interrupt sources with flags . Trigger interrupt .
- other : Calibration control , Four error detection flags .
3.STM32 Parameters to be defined for serial asynchronous communication
- Start bit
- Data bits (8 Bits or 9 position )
- Parity bit ( The first 9 position )
- Stop bit (1,15,2 position )
- Baud rate setting
USART block diagram
Two 、 Programming
1. Writing steps
1. Serial clock enable ,GPIO Clock enable :RCC_APB2PeriphClockCmd();
2. Serial reset :USART_DeInit(); This step is not necessary
3.GPIO Port mode settings :GPIO_Init(); The mode is set to GPIO_Mode_AF_PP
4. Initialization of serial port parameters :USART_Init();
5. Turn on interrupt and initialize NVIC( If you need to turn on interrupt, you need this step )
NVIC_Init();
== USART_ITConfig();==
6. Enable serial port :USART_Cmd();
7. Write interrupt handling functions :USARTx_IRQHandler();
8. Serial data transmission :
void USART_SendData();// Send data to serial port ,DR
uint16_t USART_ReceiveData();// Receive data , from DR Read the received data
9. Serial port transmission state acquisition :
FlagStatus USART_GetFlagStatus
(USART_TypeDef* USARTx, uint16_t USART_FLAG);
void USART_ClearITPendingBit
(USART_TypeDef* USARTx, uint16_t USART_IT);
2. Program instance
The code is as follows ( Shown ):
#include "stm32f10x.h"
void Bitter_USART_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
USART_InitTypeDef USART_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// Can make GPIOA
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);// Enable serial port one
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
USART_InitStruct.USART_BaudRate=115200;// Baud rate
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;// Hardware flow control
USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;// Send and receive
USART_InitStruct.USART_Parity=USART_Parity_No;// Parity check
USART_InitStruct.USART_StopBits=USART_StopBits_1;// Stop bit
USART_InitStruct.USART_WordLength=USART_WordLength_8b;// The word is long
USART_Init(USART1,&USART_InitStruct);// Serial initialization
USART_Cmd(USART1,ENABLE);// Serial port enable function
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);// Turn on the interrupt service function ; Receive interrupt
NVIC_InitStruct.NVIC_IRQChannel=USART1_IRQn;// Interrupt channel
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;// Open interrupt channel
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=1;// Set preemption priority
NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;// Sub priority
NVIC_Init(&NVIC_InitStruct);
}
void USART1_IRQHandler(void)
{
u8 tea;
if(USART_GetITStatus(USART1,USART_IT_RXNE))// Determine the interrupt type
{
tea=USART_ReceiveData(USART1);// Read the data received by the serial port ;
USART_SendData(USART1,tea);// send data
}
}
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// Interrupt priority , Two people preempt priority , Two response priorities
Bitter_USART_Init();
while(1);
}
3、 ... and 、…\OBJ\Project.axf: Error: L6200E: Symbol USART1_IRQHandler multiply defined (by usart.o and main.o). Error resolution
stay usart.c Found in and USART1_IRQHandler Same function , Just comment it out .
summary
Writing serial port can also use HAL Library to achieve serial port configuration and use methods .. stay HAL In the library , The functions and definitions related to serial port are mainly in the file stm32f1xx_hal_uart.c and stm32f1xx_hal_uart.h in .
边栏推荐
- LeetCode#2062. Count vowel substrings in strings
- 自动化测试你必须要弄懂的问题,精品总结
- The latest query tracks the express logistics and analyzes the method of delivery timeliness
- 安全测试入门介绍
- Maximum nesting depth of parentheses in leetcode simple questions
- UCORE lab5 user process management experiment report
- ArrayList set
- What if software testing is too busy to study?
- Currently, mysql5.6 is used. Which version would you like to upgrade to?
- How to build a nail robot that can automatically reply
猜你喜欢
JS --- all knowledge of JS objects and built-in objects (III)
Do you know the advantages and disadvantages of several open source automated testing frameworks?
The wechat red envelope cover designed by the object is free! 16888
Video scrolling subtitle addition, easy to make with this technique
软件测试需求分析之什么是“试纸测试”
ucore lab5
Interview answering skills for software testing
ucore Lab 1 系统软件启动过程
Crawling cat's eye movie review, data visualization analysis source code operation instructions
学习记录:USART—串口通讯
随机推荐
Jupyter installation and use tutorial
Threads and thread pools
全网最详细的postman接口测试教程,一篇文章满足你
软件测试需求分析之什么是“试纸测试”
Lab 8 文件系统
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
MySQL数据库(二)DML数据操作语句和基本的DQL语句
JS --- JS function and scope (II)
MySQL数据库(五)视 图 、 存 储 过 程 和 触 发 器
Maximum nesting depth of parentheses in leetcode simple questions
ucore lab 2
LeetCode#118. Yanghui triangle
Mysql database (II) DML data operation statements and basic DQL statements
STM32 learning record: input capture application
Iterators and generators
csapp shell lab
線程及線程池
Research Report on market supply and demand and strategy of China's Medical Automation Industry
Research Report on medical toilet industry - market status analysis and development prospect forecast
A method and implementation of using VSTO to prohibit excel cell editing