当前位置:网站首页>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 .
边栏推荐
- One brush 146 force buckle hot question-3 longest substring without repeated characters (m)
- Take you to API development by hand
- Static program analysis (I) -- Outline mind map and content introduction
- [2. Basics of Delphi grammar] 2 Object Pascal data type
- [combinatorial mathematics] counting model, common combinatorial numbers and combinatorial identities**
- RF analyze demo build step by step
- Depth first search of graph
- CC2530 common registers for port initialization
- 手把手带你入门 API 开发
- Thread pool: the most common and error prone component of business code
猜你喜欢
Unity notes unityxr simple to use
[error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
C language modifies files by line
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
What is your income level in the country?
Talk about several methods of interface optimization
[JDBC] API parsing
Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing
Fast Ethernet and Gigabit Ethernet: what's the difference?
随机推荐
Electronic Science and technology 20th autumn "Microcomputer Principle and application" online assignment 2 [standard answer]
深入理解 SQL 中的 Grouping Sets 语句
执行脚本不认\r
What is your income level in the country?
Define a structure fraction to represent a fraction, which is used to represent fractions such as 2/3 and 5/6
CC2530 common registers for timer 1
基于主机的入侵系统IDS
[combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
CC2530 common registers for crystal oscillator settings
Kotlin学习快速入门(7)——扩展的妙用
CC2530 common registers for port initialization
MySQL Basics
大消费企业怎样做数字化转型?
UCORE overview
[JDBC] API parsing
美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
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 (constant coefficient linear homogeneous recursive equation | constant coefficient, linear, homogeneous concept description | constant coefficient linear homogeneous
Fast Ethernet and Gigabit Ethernet: what's the difference?
Solution to long waiting time of SSH connection to remote host