当前位置:网站首页>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 .
边栏推荐
- Résolution de l'instance d'assemblage - - affichage à l'écran en mode réel
- 新库上线 | CnOpenData中国观鸟记录数据
- Meituan side: why does thread crash not cause JVM crash
- Necessary ability of data analysis
- Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
- Thread pool: the most common and error prone component of business code
- Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
- Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
- mysql用户管理
- LeetCode 1656. Design ordered flow
猜你喜欢

设计电商秒杀

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

The largest matrix (H) in a brush 143 monotone stack 84 histogram

网络安全web渗透技术

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

線程池:業務代碼最常用也最容易犯錯的組件

Life is still confused? Maybe these subscription numbers have the answers you need!

ucore概述

【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用

静态程序分析(一)—— 大纲思维导图与内容介绍
随机推荐
How to promote cross department project collaboration | community essay solicitation
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
How to delete a specific line from a text file using the SED command?
手把手带你入门 API 开发
新库上线 | CnOpenData中国观鸟记录数据
Redis: operation commands for list type data
Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“
CC2530 common registers for port initialization
One brush 148 force deduction hot question-5 longest palindrome substring (m)
浅谈拉格朗日插值及其应用
[combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
[2. Basics of Delphi grammar] 1 Identifiers and reserved words
大变局!全国房价,跌破万元大关
【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
Simple configuration of postfix server
Network security web penetration technology
Electronic technology 20th autumn "Introduction to machine manufacturing" online assignment 3 [standard answer]
vs code 插件 koroFileHeader
Execute script unrecognized \r
基于主机的入侵系统IDS