当前位置:网站首页>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 .
边栏推荐
- Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
- LeetCode 1656. Design ordered flow
- Svn full backup svnadmin hotcopy
- Deep understanding of grouping sets statements in SQL
- 【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
- 定义一个结构体Fraction,表示分数,用于表示 2/3, 5/6这样的分数
- mysql用户管理
- Solution to long waiting time of SSH connection to remote host
- 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
- RedHat 6.2 配置 Zabbix
猜你喜欢
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
Redis:关于列表List类型数据的操作命令
图之深度优先搜索
Atom QT 16_ audiorecorder
人生还在迷茫?也许这些订阅号里有你需要的答案!
Redis: operation commands for list type data
Life is still confused? Maybe these subscription numbers have the answers you need!
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
Build your own website (23)
[JDBC] API parsing
随机推荐
Mysql database DDL and DML
Redis:关于列表List类型数据的操作命令
CC2530 common registers for watchdog
CC2530 common registers
Redis: operation commands for list type data
One brush 148 force deduction hot question-5 longest palindrome substring (m)
The most complete postman interface test tutorial in the whole network, API interface test
Host based intrusion system IDS
Hands on in-depth learning notes (XIV) 3.7 Simple implementation of softmax regression
Open vsftpd port under iptables firewall
[JDBC] API parsing
Atom QT 16_ audiorecorder
Résolution de l'instance d'assemblage - - affichage à l'écran en mode réel
C语言字符串练习
C language string practice
How to allow remote connection to MySQL server on Linux system?
Rsync remote synchronization
MySQL user management
mysql用户管理
Kotlin学习快速入门(7)——扩展的妙用