STM32 receives interrupt service function print function and causes errors

Publisher:SereneVoyageLatest update time:2018-12-01 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In the interrupt service function, the printing function must not be used, because the printing function takes too long, which will cause the interrupt service function to not exit for a long time, which will cause some unexpected results.


For example, in the serial port interrupt:


void USART2_IRQHandler(void)

{

    unsigned char res;

    uint16_t uhdata;

    uint16_t uhMask = (&huart2)->Mask;

    //if(USART2->ISR&(1<<5))//?????

    if(((READ_REG((&huart2)->Instance->ISR) & USART_ISR_RXNE) != RESET) && ((READ_REG((&huart2)->Instance->CR1) & USART_CR1_RXNEIE) != RESET))

    {    

        res = 0;

        res = USART2->RDR; 

        printf("\r\n USART2 IRQ....%x %d \r\n",res,cnt2++);        

        if('$' == res)

        {cnt =0;memset(USART2_RMCtmp_BUF,0,256);}

        USART2_RMCtmp_BUF[cnt] = res;

        if((cnt>=3) && (USART2_RMCtmp_BUF[3] == 'R'))

        {

            USART2_RMC_BUF[cnt] = res;

        }    

        cnt++;                                              

    } 


}


result:


You can see that the received result is 0d 0a, and then nothing. Because the printing function takes too long, the value in the RDR register is not read immediately, which will cause an overflow error, and thus the receiving interrupt cannot be entered to process data. When the printing function is removed, everything is normal.


Therefore, do not perform time-consuming operations in the interrupt service function, especially in the receiving interrupt service function.


Keywords:STM32 Reference address:STM32 receives interrupt service function print function and causes errors

Previous article:About SysTick interrupt in interrupt nesting
Next article:stm32 interrupt service function name table quick check

Latest Microcontroller Articles
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号