The stm32F030C8 microcontroller serial port uses USART_IT_IDLE to receive a complete frame

Publisher:DelightWish123Latest update time:2018-12-10 Source: eefocusKeywords:stm32F030C8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The USART_IT_RXNE register generates an interrupt when a byte is not received, while the USART_IT_IDLE register generates an interrupt after receiving a complete frame, that is, an interrupt will be generated if no more is received within one byte after receiving a byte.


Here is the source code:


void USART1_Config(void)

GPIO_InitTypeDef GPIO_InitStructure;  

USART_InitTypeDef USART_InitStructure; //Define the serial port initialization structure

NVIC_InitTypeDef NVIC_InitStruct;

  

RCC_AHBPeriphClockCmd(USART1_GPIO_RCC, ENABLE); //Enable GPIOA clock

RCC_APB2PeriphClockCmd(USART1_RCC, ENABLE); //Enable USART clock

GPIO_PinAFConfig(USART1_GPIO_PORT, USART1_TX_GPIO_PinSource, GPIO_AF_1); //Configure PA9 as the second function pin TX

GPIO_PinAFConfig(USART1_GPIO_PORT, USART1_RX_GPIO_PinSource, GPIO_AF_1); //Configure PA10 as the second function pin RX 


/*USART1_TX ->PA9 USART1_RX ->PA10*/   

GPIO_InitStructure.GPIO_Pin = USART1_TX|USART1_RX; //Select the default output pin of the serial port

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //Define the maximum output rate

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStructure.GPIO_Speed ​​= GPIO_Speed_50MHz; //Define the mode of pin 9

GPIO_Init(USART1_GPIO_PORT, &GPIO_InitStructure); //Call the function and input the structure parameters for initialization    


/*Serial port communication parameter settings*/

USART_InitStructure.USART_BaudRate = UART1_BaudRate;//9600; //Baud rate

USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8 data bits

USART_InitStructure.USART_StopBits = USART_StopBits_1; //Stop bit 1

USART_InitStructure.USART_Parity = USART_Parity_No; //No parity bit

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//No flow control

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //Enable receive and transmit pins


USART_Init(USART1, &USART_InitStructure);

    

//USART_ClearFlag(USART1,USART_FLAG_TC);    

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);

USART1->ICR |= 1<<4; //The IDLE interrupt must be cleared first, otherwise it will continue to enter the IDLE interrupt

USART_Cmd(USART1, ENABLE);

    

    

/* NVIC interrupt configuration for USART1 */

NVIC_InitStruct.NVIC_IRQChannel = USART1_IRQn;

NVIC_InitStruct.NVIC_IRQChannelPriority = 0x02;

NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStruct);    

}


/**

* @file USART1_IRQHandler

* @brief USART1 interrupt handling

* @param None

* @retval None

*/

void USART1_IRQHandler(void)

{

uint32_t temp = 0;

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

{

//USART_SendData(USART1,USART_ReceiveData(USART1));

if (uart_recv[UART_1].count < UART_BUF_LEN)

{

//uart_recv_flag = 1;

uart_recv[UART_1].recv_buf[uart_recv[UART_1].count] = USART_ReceiveData(USART1);

uart_recv[UART_1].count++;

}

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

}

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

{

USART1->ICR |= 1<<4;

uart_recv_flag = 1;

UART_send(USART1, "hello", sizeof("hello"));

}


Note that the method to clear the interrupt of F0 chip is to use the ICR register. After enabling the interrupt, you must clear the interrupt immediately, otherwise it will keep entering the interrupt.


Keywords:stm32F030C8 Reference address:The stm32F030C8 microcontroller serial port uses USART_IT_IDLE to receive a complete frame

Previous article:stm32 USART receive bus idle interrupt --USART_IT_IDLE
Next article:Pay attention to the IDLE interrupt of STM32F series USART

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号