当前位置:网站首页>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 .
边栏推荐
- 跨境电商:外贸企业做海外社媒营销的优势
- 新库上线 | CnOpenData中国保险机构网点全集数据
- 匯編實例解析--實模式下屏幕顯示
- C language string practice
- What is your income level in the country?
- [2. Basics of Delphi grammar] 2 Object Pascal data type
- MySQL Basics
- RedHat 6.2 配置 Zabbix
- Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
- 免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
猜你喜欢

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

网络安全web渗透技术

Mysql database DDL and DML

线程池:业务代码最常用也最容易犯错的组件

建立自己的网站(23)

静态程序分析(一)—— 大纲思维导图与内容介绍

Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
![[JDBC] API parsing](/img/75/0f69a4e246a571688355bb13e2cd73.jpg)
[JDBC] API parsing

新库上线 | CnOpenData中国保险机构网点全集数据
The way of wisdom (unity of knowledge and action)
随机推荐
Talk about several methods of interface optimization
[combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
Apache服务挂起Asynchronous AcceptEx failed.
One brush 142 monotone stack next larger element II (m)
免费数据 | 新库上线 | CnOpenData中国保险中介机构网点全集数据
Leetcode13. Roman numeral to integer (three solutions)
kubernetes资源对象介绍及常用命令(四)
New features of C 10
An example of HP array card troubleshooting
[combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
ANOVA example
网络安全web渗透技术
执行脚本不认\r
Examination questions for the assignment of selected readings of British and American Literature in the course examination of Fujian Normal University in February 2022
Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
vs code 插件 koroFileHeader
[combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
聊聊接口优化的几个方法
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6