STM8S MCU serial port debugging

Publisher:剑戟辉煌Latest update time:2020-02-24 Source: eefocusKeywords:STM8S Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    I recently encountered some problems in debugging on the STM8S microcontroller, so I shared them with you!


    Question: When debugging STM8S with the IAR compiler, the program was paused and found that it could not run normally and was stuck in the serial port receive interrupt function.


    Analysis: It is suspected that the serial port receiving interrupt function did not clear the flag bit, but the function does have a corresponding clear interrupt statement, which is as follows:   


uint8_t tmp;

UART3_ClearFlag(UART1_FLAG_RXNE);

tmp = UART3_ReceiveData8();

    Enter the UART3_ClearFlag(UART1_FLAG_RXNE) function to view the code:


void UART3_ClearFlag(UART3_Flag_TypeDef UART3_FLAG)

{

    /* Check the parameters */

    assert_param(IS_UART3_CLEAR_FLAG_OK(UART3_FLAG));

 

    /*Clear the Receive Register Not Empty flag */

    if (UART3_FLAG == UART3_FLAG_RXNE)

    {

        UART3->SR = (uint8_t)~(UART3_SR_RXNE);

    }

    /*Clear the LIN Break Detection flag */

    else if (UART3_FLAG == UART3_FLAG_LBDF)

    {

        UART3->CR4 &= (uint8_t)(~UART3_CR4_LBDF);

    }

    /*Clear the LIN Header Detection Flag */

    else if (UART3_FLAG == UART3_FLAG_LHDF)

    {

        UART3->CR6 &= (uint8_t)(~UART3_CR6_LHDF);

    }

    /*Clear the LIN Synch Field flag */

    else

    {

        UART3->CR6 &= (uint8_t)(~UART3_CR6_LSF);

    }

}

    It was found that the receive interrupt flag was indeed cleared, so I went to the STM8S reference manual to look at the description of the UART3->SR register and found that in addition to the receive interrupt, the serial port communication also had an overload error interrupt.




    The receive interrupt is described as follows:


    RXNE: Read data register not empty

    This bit is set by hardware when the data in the RDR shift register is transferred to the UART_DR register.

    If the RXNEIE bit in the register is 1, an interrupt is generated. A read operation on UART_DR can clear this bit. The RXNE bit can also be

    For UART2 and UART3, this bit can also be cleared by writing 0.

    0: data not received;

    1: Data received and can be read.




    The overload error interrupt is described as follows:


    RXNE: Read data register not empty

    This bit is set by hardware when the data in the RDR shift register is transferred to the UART_DR register.

    If the RXNEIE bit in the register is 1, an interrupt is generated. A read operation on UART_DR can clear this bit. The RXNE bit can also be

    For UART2 and UART3, this bit can also be cleared by writing 0.

    0: data not received;

    1: Data received and can be read.




    Therefore, it is found that UART3_ClearFlag (UART1_FLAG_RXNE) only clears the receive interrupt, but does not clear the overload error interrupt, because to clear the overload error interrupt, UART_SR must be read first, and then UART_DR.


    The statement executed in the UART3_ClearFlag(UART1_FLAG_RXNE) function only writes UART->SR but does not read UART->SR.   


 UART3->SR = (uint8_t)~(UART3_SR_RXNE);

    Solution: Therefore, use UART3->SR &= 0xDF instead of UART3_ClearFlag(UART1_FLAG_RXNE), which can clear both the receive interrupt and the overload error interrupt. In this way, if you pause during debugging, the program will not die in the interrupt.   


uint8_t tmp;

UART3->SR &= 0xDF;

tmp = (uint8_t)UART3->DR;

    


    Question: During STM8S debugging, sometimes some statements cannot hit breakpoints.


    Analysis: I have read articles about optimization before and felt that it was related to optimization. After trying it, it turned out to be true.


    Solution: Because the optimization level in the program configuration is too high, change it to no optimization, and breakpoints can be successfully set during debugging.

Keywords:STM8S Reference address:STM8S MCU serial port debugging

Previous article:STM 8 AD conversion problem
Next article:STM8S003F uses I/O port to simulate serial port (I) to send data

Recommended ReadingLatest update time:2024-11-16 07:51

Introduction to MS8005 parameters and features General 8051 Core MCU 256-byte RAM core
MS8005 is a general-purpose 1T 8051 Core MCU. Under the same system clock, it runs faster and has superior performance than the traditional 8051. The instruction code is fully compatible with the traditional 8051; it retains the main features of the standard 8051, including 256 bytes of RAM and two 16-bit timers; the
[Microcontroller]
Introduction to RJM8L series ultra-low power MCU based on 8051 enhanced microcontroller
For some battery-powered products that need to work continuously for several years without changing the battery, the system's low-power design is particularly important. The low-power design of the MCU microcontroller determines the success or failure of the system. The low-power technology of MCU microcontrollers inv
[Microcontroller]
Introduction to RJM8L series ultra-low power MCU based on 8051 enhanced microcontroller
C8051F350 microcontroller realizes the design of gas flow meter detector
Gas flow meter is a commonly used instrument equipment. The bell-type gas flow standard device is a measurement standard device that uses air as the medium to verify, calibrate and detect gas flow meters. It is mainly suitable for the verification, calibration and type evaluation of speed, volumetric and differential
[Microcontroller]
C8051F350 microcontroller realizes the design of gas flow meter detector
Competing on the microcontroller track with unique product design, ADI low-power MCU accelerates the implementation of IoT applications
Competing on the microcontroller track with unique product design, ADI low-power MCU accelerates the implementation of IoT applications Whether it is the orderly operation of equipment in a black light factory, the automatic sensing of electrical appliances in a warm home, or the collection of physical signal data i
[Internet of Things]
Competing on the microcontroller track with unique product design, ADI low-power MCU accelerates the implementation of IoT applications
Design of solar parameter tester based on AT89S52 microcontroller
introduction In order to ensure that the solar power generation system can work normally, it is necessary to measure various environmental parameters of the solar power generation system to effectively control its operation. This article introduces a solar parameter tester based on a single-chip microcomputer, which p
[Microcontroller]
Design of solar parameter tester based on AT89S52 microcontroller
How to design a thermostatic box temperature control system based on STC89C52 microcontroller
1. System design This system is based on the application development of the classic C51 series microcontroller. It is a digital control system that integrates ambient temperature signal acquisition, data processing, temperature maintenance control, etc. At the same time, the system is designed with a friendly human-co
[Microcontroller]
How to design a thermostatic box temperature control system based on STC89C52 microcontroller
Is it easy to find a job with a microcontroller? How to learn microcontroller without knowing English?
When I just graduated, I searched for a job for more than a month. Several of our classmates who graduated from the school's electronics laboratory also failed to find suitable jobs. They switched careers to other industries, some went to sales, and some Others went into management... I was the only one who persisted.
[Microcontroller]
Basic knowledge for getting started with 51 microcontroller
Introduction to microcontroller 1.What is a microcontroller The microcontroller is an integrated circuit chip that uses very large scale integrated circuit technology to combine a central processing unit (CPU) with data processing capabilities, random access memory RAM, read-only memory ROM, various I/O ports and inte
[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号