Posted: Tue Oct 28, 2014 7:20 pm Post subject: XMEGA RST_STATUS
The BASCOM example code shown in "XM128-reset.bas" demonstrates that reading the register RST_STATUS provides the indication/reason of the last restart.
Code:
'-------------------RESET STATUS------------------------------------------------ PrintBin(rst_status)'print reason for reset If Rst_status.0 =1Then Print"Power On Reset" Set Rst_status.0 'clear it End If If Rst_status.1 =1Then Print"External Reset" Set Rst_status.1 'clear it End If If Rst_status.2 =1Then Print"Brown out Reset" Set Rst_status.2 'clear it End If If Rst_status.3 =1Then Print"Watchdog Reset" Set Rst_status.3 'clear it End If If Rst_status.4 =1Then Print"Program and Debug Interface Reset" Set Rst_status.4 'clear it End If If Rst_status.5 =1Then Print"Software Reset" Set Rst_status.5 'clear it End If
My experience is that the value of RST_STATUS is always 0 - whether accessed from the Bootloader or Main Flash memory areas.
Is there a different way to determine the reason for the re-start?
Looks like the sample is wrong. the reset status register Rst_status is cleared in the course of startup, so it makes no sense to read it.
Try it this way:
Code:
'... $swstack=40 $framesize=40
Dim r_stat asByte
!STS {r_stat}, R0
'... Print"test reset" '-------------------RESET STATUS------------------------------------------------ PrintBin(r_stat)'print reason for reset If r_stat.0 =1Then Print"Power On Reset" End If '...
yes this sample is not right anymore. It was working right till the moment rst_status was reset at startup. (same as in normal AVR).
I have added this to the sample :
dim bReset as Byte 'reset byte
bReset=Getreg(r0)
complete sample :
Code:
'---------------------------------------------------------------- ' (c) 1995-2014, MCS ' xm128-reset.bas ' This sample demonstrates how to read out the reson for reset '-----------------------------------------------------------------
ConfigPortd.0=Output ConfigPortd.1=Output SetPortd.0' special xmega handling for set,reset and toggle Waitms1000 ResetPortd.0 Waitms1000 TogglePortd.0
Print"test reset" '-------------------RESET STATUS------------------------------------------------ PrintBin(bReset)'print reason for reset If bReset.0 =1Then Print"Power On Reset" End If If bReset.1 =1Then Print"External Reset" End If If bReset.2 =1Then Print"Brown out Reset" End If If bReset.3 =1Then Print"Watchdog Reset" End If If bReset.4 =1Then Print"Program and Debug Interface Reset" End If If bReset.5 =1Then Print"Software Reset" End If '-------------------------------------------------------------------------------
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum