I wrote a simple blink program for a stm32f103rbt6 chip, but after a while I noticed that MCU is resetting constantly. When I check RCC-CSR register the PINRSTF flag is high. but I didn't connect anything externally to NRST pin. Has anybody an idea that why this occures? Is it possible that anything internally cause this situation?
It's the program that I've written for debugging. the result is that everytime LED wants to turn on but quickly turns off.
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_i2c.h"
#include "system_stm32f10x.h"
#include "delay.h"
#include "output.h"
int main(void){
RCC_APB2PeriphClockCmd(
RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = PIN_52.pin;
GPIO_Init(PIN_52.port, &GPIO_InitStructure);
GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_SET);
if (RCC_GetFlagStatus(RCC_FLAG_SFTRST)){
//GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
} else if (RCC_GetFlagStatus(RCC_FLAG_PORRST)){
//GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
} else if (RCC_GetFlagStatus(RCC_FLAG_PINRST)){
GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
} else if (RCC_GetFlagStatus(RCC_FLAG_IWDGRST)){
//GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
}else if (RCC_GetFlagStatus(RCC_FLAG_WWDGRST)){
//GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
}else if (RCC_GetFlagStatus(RCC_FLAG_LPWRRST)){
//GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
}else {
//GPIO_WriteBit(PIN_52.port, PIN_52.pin, Bit_RESET);
}
RCC_ClearFlag();
while (1);
}