STM8 serial port receive interrupt cannot enter the problem (STM8L051/101F3)

Publisher:QingfangLatest update time:2022-07-11 Source: csdnKeywords:STM8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Preface

I recently got a STM8L051/101F3 development board and planned to play around with it. After I found that the IO and timer were all OK, I started to configure the serial UART and found that the receive interrupt could not be entered, but the send interrupt was OK. Then I started a two-day troubleshooting, and checked almost all possible problem points.

STM8L051/101F3 Development Board

Code

The MCU here is STM8L051F3, and the STM8 library is used for development. The code is as follows for reference only:

main.c


#include "stm8l15x.h"

 

void Clock_Config(void) 

{

    CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1); //System clock divider

    CLK_SYSCLKSourceSwitchCmd(ENABLE); //Turn on the system clock switch

    CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI); //Set the system clock source to the internal high-speed clock 16MHz

    

    while(CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI); //Wait for clock switching

    

}

 

void GPIO_Config(void)

{

    //USART GPIO

    GPIO_Init(GPIOC, GPIO_Pin_6, GPIO_Mode_In_PU_No_IT);

    GPIO_Init(GPIOC, GPIO_Pin_5, GPIO_Mode_Out_PP_High_Fast);

    SYSCFG_REMAPPinConfig(REMAP_Pin_USART1TxRxPortC, ENABLE);

}

 

void Usart_Config(void)

{

    CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);

    USART_Init(USART1, (uint32)9600, USART_WordLength_8b, USART_StopBits_1, USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));

    USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

    USART_ITConfig(USART1, USART_IT_TC, ENABLE);

    USART_Cmd(USART1, ENABLE);

}

 

void main( void )

{

    Clock_Config();

    GPIO_Config();

    Usart_Config();

    enableInterrupts();

    USART_SendData8(USART1, 0x55);

    while(1)

    {

 

    }

}

 

void Usart1_RX_Callback(uint8_t data)

{

    USART_SendData8(USART1, data);

}

stm8l15x_it.c


extern void Usart1_RX_Callback(uint8_t data);

 

/**

  * @brief USART1 RX / Timer5 Capture/Compare Interrupt routine.

  * @param None

  * @retval None

  */

INTERRUPT_HANDLER(USART1_RX_TIM5_CC_IRQHandler,28)

{

    /* In order to detect unexpected events during development,

       it is recommended to set a breakpoint on the following instruction.

    */

    if(USART_GetITStatus(USART1, USART_IT_RXNE))

    {

// USART_ClearITPendingBit(USART1, USART_IT_RXNE);

        Usart1_RX_Callback(USART_ReceiveData8(USART1));

    }

}

Troubleshooting

First of all, I can be sure that there is no problem with the code. I have checked the registers during simulation with the specification sheet, and all the configurations are correct.

Then I accidentally discovered that the development board can burn programs via the USB serial port, and the burning port used is exactly the serial port IO I use. Then I wondered if there was a conflict between the onboard USB to serial port chip and the external USB to serial port?

Finally I unplugged the onboard RXD jumper, and the serial port receive interrupt came into play...

Remove the RXD jumper

Summarize

If the development board has a USB to serial port, do not insert a USB to serial port module (this is nonsense), otherwise it may affect the serial port transmission and reception, resulting in an inability to receive serial port data.

Keywords:STM8 Reference address:STM8 serial port receive interrupt cannot enter the problem (STM8L051/101F3)

Previous article:STM8 comes with BootLoader serial port burning program
Next article:STM8L USART+DMA configuration, using DMA to complete serial port transmission and reception

Recommended ReadingLatest update time:2024-11-22 22:14

【STM8】SPI communication
: Introducing how to wire SPI, name explanation, and communication precautions : SPI pin locations relative to STM8, as well as pin settings, and some initialization code : Use registers to make some settings, such as baud rate, SPI on or off, SPI interrupt, transmission mode... There are too many to list, you need
[Microcontroller]
【STM8】SPI communication
stm8 halt low power mode
  STM8   The STM8 series is an 8-bit microcontroller produced by STMicroelectronics. This type of microcontroller is divided into three series: STM8A, STM8S, and STM8L. STM8A: automotive-grade application STM8S: standard series STM8L: ultra-low power MCU   Core Advanced STM8 core, Harvard architecture with 3-stage p
[Microcontroller]
stm8 halt low power mode
Download the official routines of STM8/32 from ST official website
01. Enter ST official website           Reference website: https://www.st.com 02. Refer to the following picture 03. Refer to the following picture 04. Refer to the following figure 05. Refer to the following picture 06. Refer to the following figure 07. Refer to the following figure 08. Refer to the foll
[Microcontroller]
Download the official routines of STM8/32 from ST official website
STM8 development environment construction (STVD + COSMIC)
1. STM8 Development IDE 1. STVD + COSMIC ST Visual Develop (STVD) only supports assembly language development. For C language development, you need to install COSMIC and use them together. 2. IAR IAR can also be used to develop STM8 The following is an introduction to the construction of STVD + COSMIC 2. Environme
[Microcontroller]
STM8 development environment construction (STVD + COSMIC)
STM8-Use the timing function of TIM2 to make the light flash every 1S
Purpose: To familiarize yourself with the use of the timer function (automatic reload) #include"stm8s.h" #include "stm8s_gpio.h" #include "stm8s_tim2.h" void CLK_Configuration(); void TIM2_Configuration_set_1ms(void); void GPIO_Configuration(); void main() {     CLK_Configuration();     TIM2_Configuration_s
[Microcontroller]
Implementing absolute address jump in STM8 FOR IAR
//Use function pointer to implement typedef   void(*PFUN)(void); pFun  =(PFUN)0x8000;         (*pFun)();     #define  GotoHere(a)   ((void (*)(void))a)()  GotoHere(0X8000);     asm("JP $8000");
[Microcontroller]
STM8 Learning Notes (I) Building the First Project
I built the first STM8 project according to the tutorial (Qingfeng Electronics) and the following error occurred. Appear: Fatal Error : cannot open source file "stm8s_gpio.h" D:stm8testdriverled.h 16  The header file cannot be found. Solution: Modify the header file path. The original path is: The original pat
[Microcontroller]
STM8 Learning Notes (I) Building the First Project
Connection error occurs when stm8 is downloaded using ST-Link
错误信息:Connection error (usb://usb): gdi-error : can't access configuration database Solution: Win7 solution: Reinstall Program Files (x86)/STMicroelectronics/st_toolset/stvd/dao/ST Toolset.msi and install it under administrator privileges Solution found on Baidu Knows: http://zhidao.baidu.com/link?url=_ft7AOwaWeKLK
[Microcontroller]
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号