Backup register not working on STM32F105RC
I am using STM32F105RC microcontroller on a custom designed board, the microcontroller runs at 72MHz, no crystal (& its decoupling caps) is connected for RTC, CR2032 3V battery is connected to Vbat directly (no other circuit like diode between Vbat & Vdd is present). I am using IAR embedded workbench.
The code is as follows:
&sharpinclude ''stm32f10x.h''
&sharpinclude <intrinsics.h>
&sharpinclude ''global.h''
&sharpinclude ''stm32f10x_rtc.h''
&sharpinclude ''stm32f10x_bkp.h''
int main()
{
GPIO_InitTypeDef GPIO_InitStructure;
SystemInit();
&sharpifndef EMB_FLASH
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
&sharpelse /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x1000);
&sharpendif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD,
ENABLE);
RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC |
RCC_APB2Periph_GPIOD,
DISABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_WriteBit(GPIOA,GPIO_Pin_0 ,Bit_RESET);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
PWR_BackupAccessCmd(ENABLE);
/* if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
BKP_DeInit();
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
}*/
while(1)
{
if (BKP_ReadBackupRegister(BKP_DR1) == 0xA5A5)
{
GPIO_WriteBit(GPIOA,GPIO_Pin_0 ,Bit_SET);
}
}
}
I test it as follows:
When the commented code is uncommented (the code beginning with if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)), then program is compiled & run in debug mode, the LED connected to GPIO_Pin_0 glows. When the board is not powered off, code is commented again (as shown above) & code is run in debug mode, the LED still glows. But if the board is powered off & turned on again, the LED does not glow. It seems the backup registers are not working.
Can you please help me to solve this problem?
Thanks in advance!
#stm32 #backup-register