Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

XMEGA RST_STATUS

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 537

PostPosted: Tue Oct 28, 2014 7:20 pm    Post subject: XMEGA RST_STATUS Reply with quote

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------------------------------------------------
Print Bin(rst_status)                                       'print reason for reset
If Rst_status.0 = 1 Then
   Print "Power On Reset"
   Set Rst_status.0                                         'clear it
End If
If Rst_status.1 = 1 Then
   Print "External Reset"
   Set Rst_status.1                                         'clear it
End If
If Rst_status.2 = 1 Then
   Print "Brown out Reset"
   Set Rst_status.2                                         'clear it
End If
If Rst_status.3 = 1 Then
   Print "Watchdog Reset"
   Set Rst_status.3                                         'clear it
End If
If Rst_status.4 = 1 Then
   Print "Program and Debug Interface Reset"
   Set Rst_status.4                                         'clear it
End If
If Rst_status.5 = 1 Then
   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?

Thank-you.

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Tue Oct 28, 2014 8:20 pm    Post subject: Reply with quote

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 as  Byte
!STS  {r_stat}, R0
'...
Print "test reset"
'-------------------RESET STATUS------------------------------------------------
Print Bin(r_stat)                                       'print reason for reset
If r_stat.0 = 1 Then
   Print "Power On Reset"
End If
'...
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 537

PostPosted: Tue Oct 28, 2014 8:33 pm    Post subject: Reply with quote

Thank-you MWS for taking the time to help.


As expected, your solution worked perfectly - incredible.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Tue Oct 28, 2014 8:44 pm    Post subject: Reply with quote

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
'-----------------------------------------------------------------

$regfile = "xm128a1def.dat"
$crystal = 32000000
$hwstack = 64
$swstack = 40
$framesize = 40

dim bReset as Byte 'reset byte
bReset=Getreg(r0)       ' reset is in R0 so get it early at startup

'first enable the osc of your choice
Config Osc = Enabled , 32mhzosc = Enabled

'configure the systemclock
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

Config Com1 = 19200 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8


Config Portd.0 = Output
Config Portd.1 = Output
Set Portd.0                                                 ' special xmega handling for set,reset and toggle
Waitms 1000
Reset Portd.0
Waitms 1000
Toggle Portd.0

Print "test reset"
'-------------------RESET STATUS------------------------------------------------
Print Bin(bReset)                                       'print reason for reset
If bReset.0 = 1 Then
   Print "Power On Reset"
End If
If bReset.1 = 1 Then
   Print "External Reset"
End If
If bReset.2 = 1 Then
   Print "Brown out Reset"
End If
If bReset.3 = 1 Then
   Print "Watchdog Reset"
End If
If bReset.4 = 1 Then
   Print "Program and Debug Interface Reset"
End If
If bReset.5 = 1 Then
   Print "Software Reset"
End If
'-------------------------------------------------------------------------------


Do
   Waitms 5000                                              'wait 5 secs

   Cpu_ccp = &HD8                                           ' write protecion register
   Rst_ctrl.0 = 1                                           ' software reset
Loop


End

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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