stm32 quick learning 5-serial port interrupt reception

Publisher:RadiantEyesLatest update time:2016-09-26 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Serial port sends and receives

Set the serial port clock

Set pin function

Interrupt Priority

Set up the serial port

 

Main file

#include "stm32f10x.h"

 

void RCC_Configuration(void);

void GPIO_Configuration(void);

void USART_Configuration(void);

void NVIC_Configuration(void);

 

int main(void)

{

  RCC_Configuration();

 

  GPIO_Configuration();

 

  NVIC_Configuration();

 

  USART_Configuration();

 

  while(1);

}

 

void RCC_Configuration(void)

{    

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA, ENABLE);

}

 

 

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

 

 

void USART_Configuration(void)

{

  USART_InitTypeDef USART_InitStructure;

 

  USART_InitStructure.USART_BaudRate = 115200;

  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_Tx | USART_Mode_Rx;

 

  USART_Init(USART1 , &USART_InitStructure);

  USART_Cmd(USART1, ENABLE);

 

  USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); /*Receive interrupt enable*/

}

 

 

void NVIC_Configuration(void) 

  NVIC_InitTypeDef NVIC_InitStructure;

 

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); 

 

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; /*3.4 library does not use USART1_IRQChannel, see stm32f10x.h*/

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; 

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 

 

  NVIC_Init(&NVIC_InitStructure); 

}

 

Stm32f10x_it.c added

 

void USART1_IRQHandler(void) 

    unsigned int i; 

    if(USART_GetFlagStatus(USART1,USART_IT_RXNE)==SET) 

    {               

        i = USART_ReceiveData(USART1); 

        USART_SendData(USART1,i); 

        while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) ;              

    }

 

    if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) 

    { 

        /* Clear receive interrupt flag */ 

        USART_ClearITPendingBit(USART1, USART_IT_RXNE);

    }

 

}

Keywords:stm32 Reference address:stm32 quick learning 5-serial port interrupt reception

Previous article:STM32 Quick Learning 7-LED Flashing (TIM2 Query)
Next article:stm32 quick learning 4 - serial port sending characters

Recommended ReadingLatest update time:2024-11-17 00:33

STM32 debugging support (DBG)
The STM32F10xxx uses the Cortex™-M3 core, which contains a hardware debug module that supports complex debugging operations. The hardware debug module allows the core to stop when fetching instructions (instruction breakpoints) or accessing data (data breakpoints). When the core stops, the internal state of the core
[Microcontroller]
STM32 debugging support (DBG)
STM32 independent watchdog (IWDG) and window watchdog (WWDG)
  There was a very popular game called "Watch Dogs". The game used a very new engine technology to create a vast world. The content is that the player Aiden Pearce (the protagonist) is a master of hacker technology. At that time, the world was in a state where all objects were controlled by electronic devices, and the
[Microcontroller]
STM32 independent watchdog (IWDG) and window watchdog (WWDG)
Advanced use of STM32 timers
[Microcontroller]
STM32 implements DAC output related settings
Introduction to STM32 DAC         The large-capacity STM32F103 has an internal DAC. The battleship STM32 selected is the STM32F103ZET6, which is a large-capacity product, so it has a DAC module. The DAC module (digital/analog conversion module) of STM32 is a 12-bit digital input, voltage output DAC. The DAC can be con
[Microcontroller]
STM32 implements DAC output related settings
STM32 Learning - AD single channel and multi-channel conversion (DMA)
Chapter 3 AD Conversion This chapter is divided into two parts. The first is the single channel conversion of AD, and the second is the multi-channel conversion of AD. First, convert the single channel.  The maximum conversion frequency of the AD built into STM32 is 14MHZ. There are 16 conversion channels in total. Th
[Microcontroller]
STM32 timer---Detailed explanation of quadrature encoder mode
Encoder classification:  According to the working principle: photoelectric, magnetoelectric and contact brush  type According to the hole engraving method of the code disk: incremental and absolute  Since the blogger's contact surface is not very wide, he has used two types of encoders in total, both of which are phot
[Microcontroller]
STM32 FSMC control LCD function explanation
I encountered this problem while doing the project. I think the article is well written. I would like to share it with my colleagues who have doubts about the use of FSMC! LCD has the following control lines: CS: Chip Select, low level valid RS: Register Select WR: Write signal, low level valid RD: Read signal, low l
[Microcontroller]
STM32 key part
What is a pull-up resistor? Why is the pull-up resistor of a button 10k ohm? Answer: A pull-up resistor connects an uncertain signal to the power supply VCC through a resistor and fixes it at a high level. effect: 1) Increase the drive capability of the output pin (actually increase the current of the current wi
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号