当前位置:网站首页>Swm32 series Tutorial 4 port mapping and serial port application
Swm32 series Tutorial 4 port mapping and serial port application
2022-07-03 17:11:00 【Tianwaifeixian CUG】

Let's introduce today SWM32 Port mapping of single chip microcomputer and application of serial port .
1. Port mapping
As mentioned in the previous article ,SWM32 The port mapping of Series MCU is relatively flexible . A peripheral can be mapped to many different GPIO, about PCB For wiring , A lot of convenience .
Can pass PORTx_SEL Register to configure which port a peripheral is mapped to . Here's the picture :

With PC Take the mouth as an example ,PC0 You can configure the PORTC_SEL register , It maps to FUNMUX0 function ,PC1 It can be mapped to FUNMUX1 function , and FUNMUX0 and FUNMUX1 Functions can correspond to different peripherals . therefore PC0 and PC1 It can be flexibly configured for the functions of various digital peripherals .

But this is not infinitely flexible , Generally, the principle of odd and even distribution is followed , That is, even ports correspond to FUNMUX0 function , Odd ports correspond to FUNMUX1 function .
In actual programming , Directly call relevant functions , Take serial port as an example , To put UART0 Function mapping to PC2 and PC3 port , Call the following functions . The specific parameter description of the function can be seen in the comments .
PORT_Init(PORTC, PIN2, FUNMUX0_UART0_RXD, 1); //GPIOC.2 Configure to UART0 Input pin
PORT_Init(PORTC, PIN3, FUNMUX1_UART0_TXD, 0); //GPIOC.3 Configure to UART0 Output pin 2. Serial port application
A serial port (UART) Is one of the most commonly used interfaces in embedded . The design of the single chip microcomputer UART mouth , Has a depth of 8 Send and receive FIFO, Can reduce the CPU Frequency of interruption , Improve operational efficiency .
In general , We all use interrupt to send and receive data , Here also mainly introduces how to realize interrupt mode to send and receive data . Look directly at the program :
void SerialInit(void)
{
UART_InitStructure UART_initStruct;
PORT_Init(PORTC, PIN2, FUNMUX0_UART0_RXD, 1); //GPIOC.2 Configure to UART0 Input pin
PORT_Init(PORTC, PIN3, FUNMUX1_UART0_TXD, 0); //GPIOC.3 Configure to UART0 Output pin
UART_initStruct.Baudrate = 115200;
UART_initStruct.DataBits = UART_DATA_8BIT;
UART_initStruct.Parity = UART_PARITY_NONE;
UART_initStruct.StopBits = UART_STOP_1BIT;
UART_initStruct.RXThreshold = 3; // receive FIFO Threshold setting
UART_initStruct.RXThresholdIEn = 1; // Enable receive interrupt
UART_initStruct.TXThreshold = 3; // send out FIFO Threshold setting
UART_initStruct.TXThresholdIEn = 0; // Send interrupt
UART_initStruct.TimeoutTime = 10; //10 If no new data is received within a character time, a timeout interrupt is triggered
UART_initStruct.TimeoutIEn = 1; // Enable timeout interrupt
UART_Init(UART0, &UART_initStruct);
UART_Open(UART0);
NVIC_EnableIRQ(UART0_IRQn); // Open the serial port interrupt
}Baud rate and data bits 、 There is no need to say more about the setting of check bits , Mainly look at the settings of the interrupt part later .
Receive and timeout interrupts
First, you need to set reception FIFO threshold RXThreshold, meanwhile RXThresholdIEn=1 Enable receive interrupt . When receiving FIFO Number of data in >RXThreshold Receive interrupt occurs when . Unlike others without FIFO The single chip computer of , Receiving a byte generates an interrupt .
secondly , You also need to set the receiving timeout TimeoutTime, And enable timeout interrupt TimeoutIEn=1. When FIFO Data in the ≤RXThreshold when , And no new data is received after timeout , Timeout interrupt will occur . Two interrupts cooperate to complete the reading of a frame of data .
Sending and sending completion interrupt
Sending interrupt is similar to receiving interrupt , It also needs to be set FIFO threshold TXThreshold And enable interrupt TXThresholdIEn=1. It should be noted that there is no need to enable interrupt during initialization , Enable when you need to send data .
When the data is sent , You can then enable the send completion interrupt , The sending completion is interrupted at 485 It is very useful in half duplex applications .
Complete engineering reference :
link :https://pan.baidu.com/s/1KLbtE_FP1ZPY5UqlZwdY9Q?pwd=5ij6
Extraction code :5ij6
Recommended reading :
SWM32 Series of tutorials 1- Learn about the hardware
UART How high does baud rate require for clock accuracy ?
PCB Introduction to high current design method
Let the buzzer sing a song ~《 People like me 》
Welcome to the official account " Development of Embedded Technology ", You can leave a message for me backstage . If you think the official account is helpful to you , Also welcome to recommend and share with others .
边栏推荐
- LeetCode 1656. Design ordered flow
- kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
- Recommendation of good books on learning QT programming
- Host based intrusion system IDS
- Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
- University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
- C语言按行修改文件
- PHP online confusion encryption tutorial sharing + basically no solution
- 图之深度优先搜索
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Pin搭建和使用
猜你喜欢

Great changes! National housing prices fell below the 10000 yuan mark

kubernetes资源对象介绍及常用命令(四)

Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires

Talk about several methods of interface optimization

New features of C 10

The largest matrix (H) in a brush 143 monotone stack 84 histogram
The way of wisdom (unity of knowledge and action)

跨境电商:外贸企业做海外社媒营销的优势

Prepare for the golden three silver four, 100+ software test interview questions (function / interface / Automation) interview questions. win victory the moment one raises one 's standard

Design e-commerce spike
随机推荐
CC2530 common registers for port interrupts
kubernetes资源对象介绍及常用命令(四)
[2. Basics of Delphi grammar] 2 Object Pascal data type
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
[combinatorics] recursive equation (outline of recursive equation content | definition of recursive equation | example description of recursive equation | Fibonacci Series)
Static program analysis (I) -- Outline mind map and content introduction
Simple configuration of postfix server
New library online | cnopendata complete data of Chinese insurance institution outlets
RF analyze demo build step by step
Fast Ethernet and Gigabit Ethernet: what's the difference?
Leetcode: lucky number in matrix
绝对定位时元素水平垂直居中
RF Analyze Demo搭建 Step by Step
Unity notes unityxr simple to use
How to allow remote connection to MySQL server on Linux system?
27. 输入3个整数,按从大到小的次序输出。要求用指针方法实现。
聊聊接口优化的几个方法
Great changes! National housing prices fell below the 10000 yuan mark
C语言字符串练习
比亚迪、长城混动市场再“聚首”