Serial port data configuration
void macUART4_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(macUART4_RX_GPIO_CLK|macUART4_TX_GPIO_CLK,ENABLE);
RCC_APB1PeriphClockCmd(macUART4_CLK, ENABLE);
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = macUART4_TX_PIN ;
GPIO_Init(macUART4_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = macUART4_RX_PIN;
GPIO_Init(macUART4_RX_GPIO_PORT, &GPIO_InitStructure);
GPIO_PinAFConfig(macUART4_RX_GPIO_PORT,macUART4_RX_SOURCE,macUART4_RX_AF);
GPIO_PinAFConfig(macUART4_TX_GPIO_PORT,macUART4_TX_SOURCE,macUART4_TX_AF);
USART_InitStructure.USART_BaudRate = macUART4_BAUDRATE;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(macUART4, &USART_InitStructure);
USART_Cmd(macUART4, ENABLE);
}
DMA configuration function, please compare with DMA serial port receiving data configuration function
void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure; //
RCC_AHB1PeriphClockCmd(macUART4_DMA_CLK, ENABLE); //
DMA_DeInit(macUART4_TX_DMA_STREAM); //
while (DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != DISABLE){
}
DMA_InitStructure.DMA_Channel = macUART4_TX_DMA_CHANNEL; //
DMA_InitStructure.DMA_PeripheralBaseAddr = macUART4_DR_BASE; //
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)SendBuff; //
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral; //
DMA_InitStructure.DMA_BufferSize = macUART4_SEND_BUFF_SIZE; //
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; //
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium; //
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //
DMA_Init(macUART4_TX_DMA_STREAM, &DMA_InitStructure); //
DMA_Cmd(macUART4_TX_DMA_STREAM, ENABLE);
while(DMA_GetCmdStatus(macUART4_TX_DMA_STREAM) != ENABLE)
{
}
}
Main function, debug serial port and UART4 send data at the same time, without affecting each other
int main(void)
{
int i;
SysTick_Init();
NVIC_Configuration();
Debug_USART_Config();
macUART4_Config();
DMA_Config();
printf("Hello World!nn");
for(i=0;i { SendBuff[i] = 'A'; } USART_DMACmd(macUART4, USART_DMAReq_Tx, ENABLE); while(1) { printf("Hello World!n"); } } There is no interrupt routine involved in this program, and the use of DMA should avoid interrupts as much as possible.
Previous article:STM32 uses HAL library to realize serial communication - detailed explanation of theoretical principles
Next article:STM32F407 Hal Library Serial Port Usage Guide
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- What's so special about Tesla's batteries?
- Why do new boards still include serial ports?
- What good things did everyone buy on Double 11? I bought a pair of "quantum long johns"
- Microsoft's Unbounded Mouse software
- Regarding the LDO operating temperature rise expression, heat generation power and efficiency calculation.
- Share a set of Qinheng MCU CH559/CH554/CH552 and other USB application example source code
- IMX6 development board running and debugging HelloWorld on the simulator
- 【GD32307E-START】+A/D data acquisition and sensor
- [TI Recommended Course] #Wide Input DC/DC Converter to Meet Low Quiescent Current Requirements in Industrial Applications#
- Single Voltage Reference vs. Dual Voltage Reference - III