当前位置:网站首页>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 .
边栏推荐
- JS --- all knowledge of JS objects and built-in objects (III)
- Mysql database (I)
- Cadence physical library lef file syntax learning [continuous update]
- 学习记录:理解 SysTick系统定时器,编写延时函数
- Visual analysis of data related to crawling cat's eye essays "sadness flows upstream into a river" | the most moving film of Guo Jingming's five years
- Medical colposcope Industry Research Report - market status analysis and development prospect forecast
- Mysql database (III) advanced data query statement
- Sorting odd and even subscripts respectively for leetcode simple problem
- 学习记录:使用STM32F1看门狗
- Interface test interview questions and reference answers, easy to grasp the interviewer
猜你喜欢
学习记录:理解 SysTick系统定时器,编写延时函数
Learning record: Tim - capacitive key detection
[200 opencv routines] 98 Statistical sorting filter
ucore lab7
Heap, stack, queue
UCORE lab2 physical memory management experiment report
如何成为一个好的软件测试员?绝大多数人都不知道的秘密
UCORE lab5 user process management experiment report
What are the software testing methods? Show you something different
FSM and I2C experiment report
随机推荐
ucore lab 6
Knowledge that you need to know when changing to software testing
In Oracle, start with connect by prior recursive query is used to query multi-level subordinate employees.
接口测试面试题及参考答案,轻松拿捏面试官
LeetCode#36. Effective Sudoku
ucore lab5
LeetCode#204. Count prime
FSM和i2c实验报告
UCORE lab8 file system experiment report
What are the commonly used SQL statements in software testing?
Introduction to safety testing
Do you know the advantages and disadvantages of several open source automated testing frameworks?
Iterators and generators
Research Report on medical toilet industry - market status analysis and development prospect forecast
ucore lab 2
ucore lab5
What if software testing is too busy to study?
How to become a good software tester? A secret that most people don't know
LeetCode#62. Different paths
ucore lab 2