STM32 SPI receiving stuck problem

Publisher:德州小孙Latest update time:2019-04-08 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When calling the following SPI function during debugging, the following two problems were found:


1. If you set a breakpoint at the third line while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);, it will get stuck in this while statement and cause the watchdog to reset;


2. Running at full speed will trigger the watchdog reset program. The program only calls spi without interruption. It is determined that it is caused by spi. The SPI rate drops from 16M to 2M, and there is no reset in a short time.


uint8_t SPI2_SendOneByte(uint8_t u8Data) //SPI2 sends one byte


{

/* Wait for the send buffer to be empty, TXE event*/

while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);


/* Write the data register and write the data to be written into the send buffer*/

SPI_I2S_SendData(SPI2, u8Data);


/* Wait for the receive buffer to be non-empty, RXNE event*/

while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);


/* Read the data register and get the receive buffer data*/

return SPI_I2S_ReceiveData(SPI2);

}


After testing and consulting online information, it was found that it was caused by tracking the SPI register during debugging. The solution is to close the corresponding SPI register tracking window during debugging. The specific reason was not found in the official document. I saw such a paragraph on the Internet, which can explain this imagination:


During the debugging process, the status of peripheral registers can be easily viewed using the register or memory display window of the debugging software.


Many friends have encountered this problem: during single-step debugging, they can never see changes in certain flag bits in the display window. When these flag bits should be set, they are displayed as 0 in the window. Many people mistakenly believe that this is a chip problem.


We know that the status register bits of many STM32 peripherals can be cleared by reading certain registers (such as many flag bits in I2C_SR1 of I2C). During the debugging process, whenever the program stops at a set breakpoint or single-step stop, the debugging software will automatically read out the contents of all specified registers and memories and refresh the window display. This read operation of the debugging software happens to clear those flag bits, resulting in the phenomenon described above.


There are several simple ways to solve this problem: 1. Close the register or memory display window. 2. Do not display these sensitive registers in the register or memory display window. 3. Do not place breakpoints before the operation of these sensitive register bits to ensure that these register bits are not accidentally operated by the debugging software.

Keywords:STM32 Reference address:STM32 SPI receiving stuck problem

Previous article:STM32 IIC Detailed Explanation: STM32 IIC Slave Mode (Interrupt Mode to Send and Receive Data)
Next article:STM32F103RC hardware I2C from the pit to the pit

Recommended ReadingLatest update time:2024-11-23 04:47

What is the specific meaning of I/O Level FT in the STM32 technical documentation?
Five volt tolerant means compatible with 5V signal voltage. According to the technical manual, the maximum voltage tolerated is VDD+4.0 = 3.3+4.0=7.3V
[Microcontroller]
What is the specific meaning of I/O Level FT in the STM32 technical documentation?
Introduction to signals and message mailboxes of STM32 running ucosII system
Written in front: "Signal" can be simply understood as a semaphore (used for triggering by triggering). If a signal is passed from task 1 to task 2, then task 2 will receive this signal and continue to execute. "Message mailbox" can also be understood as a semaphore, except that the message can carry content: such
[Microcontroller]
STM32 startup file selection and macro definition and chip model change IAP summary
startup_stm32f10x_cl.s Interconnect devices, STM32F105xx, STM32F107xx startup_stm32f10x_hd.s Large capacity STM32F101xx, STM32F102xx, STM32F103xx startup_stm32f10x_hd_vl.s Large capacity STM32F100xx startup_stm32f10x_ld.s Small capacity STM32F101xx, STM32F102xx, STM32F103xx startup_stm32f10x_ld_vl.s Small capacity STM
[Microcontroller]
STM32 key scan/key interrupt/external interrupt
I have been in contact with STM32 for a while, and I have a simple introduction to it. However, due to some reasons, I am only writing this entry-level key-related program today, which is divided into scan mode and interrupt mode. MCU:STM32F334C8 1. Scan mode First, configure the button pin to pull-up input mode. Ac
[Microcontroller]
STM32 key scan/key interrupt/external interrupt
stm32 learning notes (nine) PWM output
#include "pwm.h" #include "led.h" //////////////////////////////////////////////////////////////////////////////////   //This program is for learning purposes only and may not be used for any other purpose without the author's permission. //ALIENTEK Mini STM32 Development Board //PWM driver code     //Atom on point @
[Microcontroller]
STM32 LED water light analysis (library function version)
Based on stm32 F401 discovery library function, light up LED 3,4,5,6 1. Attached is a schematic diagram: The corresponding GPIOs are PD12, PD13, PD14, and PD15. 二.Memory and bus architecture  #define PERIPH_BASE          ((uint32_t)0x40000000) /*! Peripheral base address in the aliasregion  #define APB1PERIP
[Microcontroller]
STM32 LED water light analysis (library function version)
The concept of priority in STM32 (Cortex-M3)
There are two priority concepts in STM32 (Cortex-M3) - preemptive priority and response priority. Some people call response priority 'sub-priority' or 'sub-priority'. Each interrupt source needs to be assigned these two priorities.   An interrupt with a high preemptive priority can be responded to during the interru
[Microcontroller]
STM32 output comparison mode and PWM mode
1. The relationship between the two: In fact, it can be completely understood that the PWM mode is a special form of the output comparison mode. The frequencies generated by the four channels on the corresponding timer in the PWM mode are synchronized (that is, the same), while the output comparison mode can generate
[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号