The project uses stm8l051f3 as the master control and CC2500 for data reception, not sending.
The phenomenon of running away is that it can run at the beginning, but after a period of unknown length of time, which may be 3 minutes or 30 minutes, the indicator light no longer flashes and the interrupt button microcontroller does not respond.
After connecting to the debugger, I found that the program ran to a very large address, which exceeded the internal flash space of the MCU. It can be determined that the program ran away.
The experience is:
If the program runs out of control, check whether all conditional statements have been processed.
The program is running out of control, check for memory overflow.
After checking for a long time, I found out that it was caused by memory overflow.
Because the data sent by the sender is fixed at 32 bytes, only a 32-byte buffer is opened on the receiving end to read the received data.
/***********************************************************************************
* @brief GDO2 interrupt handling function
* @param None
* @retval None
****************************************************************Author:Liming**/
void GDO2_Int(void)
{
uint8_t temp;
unsigned char RecvBuffer[0x20]={0}; //Open a 32-byte buffer
unsigned char RecvLength;
if(EXTI_GetITStatus(EXTI_IT_Pin6) != RESET)
{
EXTI_ClearITPendingBit(EXTI_IT_Pin6);
DelayNms(1); //Wait for receiving to complete
RecvLength = CC2500Recv(RecvBuffer); //Get the length of the received data
temp = ProPacketCheck(RecvBuffer,RecvLength,0x0001,0x0003); //Data integrity check
if((temp == 0x04)||(temp==0xff)) // Local and broadcast information need to be processed
{
//data processing
CC2500SetState(CC2500_STATUS_POWERDOWN_LEVEL2);
}
else
CC2500SetState(CC2500_STATUS_RECEIVE);
}
}
//Receive data
unsigned char CC2500Recv(unsigned char *Buffer,unsigned char Mode)
{
unsigned char Result=0x00,Status=0x00;
switch(CC2500State)
{
case 0x00:
case 0x01:
if(CC2500State) Delayms(0x07);
else Delayus(0x30);
Status=CC2500SpiReadStatus(RXBYTES);
if(Status&0x80) //If the data length exceeds 64 bytes
{
CC2500SpiReadBuffer(FIFO,Buffer,0x40); //Read 64 bytes
Result=0x40;
}
else if(Status&0x7F)
{
CC2500SpiReadBuffer(FIFO,Buffer,Status&0x7F); //Read received data
Result=Status&0x7F;
}
CC2500SetState(Mode);
break;
}
return Result; //Return the length of the data read
}
However, due to interference from wireless signals, CC2500 may receive data larger than 32 bytes (although this is not required by this system).
As a result, when the data is retrieved from cc2500, the length of the buffer stored exceeds the allocated buffer space.
Solution 1: Since we know it is 32 bytes of data, we can
The CC2500Recv receive function only receives 32 bytes.
if(Status&0x80) //If the data length exceeds 64 bytes
{
CC2500SpiReadBuffer(FIFO,Buffer,0x20); //Read 32 bytes
Result=0x20;
}
else if(Status&0x7F)
{
CC2500SpiReadBuffer(FIFO,Buffer,0x20); //Read received data
Result=0x20;
}
Solution 2:
The GDO2_Int function allocates 64 bytes of space so that even if the maximum amount of data is received, the buffer space will not be exceeded.
unsigned char RecvBuffer[0x40]={0}; //Open a 64-byte buffer
With this experience of dealing with program crashes, it is once again confirmed that most program crashes are caused by memory overflow.
Previous article:STVD uses printf to output data error
Next article:STVD Debugging Problems in STM8S
Recommended ReadingLatest update time:2024-11-16 16:51
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Are there step by step instructions for adding a custom service?
- ESP8266 Getting Started Guide
- MSP430FR2355 LaunchPad Development Kit
- DC/DC power supply circuit (MP2562 chip) chip breakdown failure when powering on
- Serial communication of TI MSP430F5438A
- Circuit Problem Analysis
- [Chuanglong TL570x-EVM] Establish startup service - print helloworld
- Chestnut Development Board-TI5708 First Hands-On Exploration
- Review summary: National Technology low-power series, N32L43x is now available for testing
- Some information about mobile power supplies (power banks)