Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Mcucsr: 2.0.8.6 - Does not work, 2.0.8.5 - ALL OK
Goto page 1, 2  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 9:49 am    Post subject: Mcucsr: 2.0.8.6 - Does not work, 2.0.8.5 - ALL OK Reply with quote

Hi all!

How can you find out about the reason for the restart in the version 2.0.8.6 of the BASCOM?
I've read the "change history" but don't understand how to apply this information.

This is a simple example. If power is supplied, the red LED lights up, if there is another reason for the restart, the green LED lights up.

The example does not work in the version 2.0.8.6.
But in the old version 2.0.8.5 everything is fine.

Code:

$regfile = "m16adef.dat"
$crystal = 8000000
$hwstack = 64
$swstack = 64
$framesize = 64


Dim Begunok As Byte
Begunok = Mcucsr: Mcucsr = 0           '

Led_r Alias Portb.3 : Config Led_r = Output                 '
Led_g Alias Portb.2 : Config Led_g = Output                 '


If Begunok.porf = 1 Then                '
  Led_r = 1
Else
  Led_g = 1
End If

End
 


(BASCOM-AVR version : 2.0.8.6 )


Last edited by Alexander-Dan on Thu Feb 22, 2024 1:17 pm; edited 1 time in total
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 22, 2024 10:13 am    Post subject: Reply with quote

check the config watchdog help.
_________________
Mark
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 10:21 am    Post subject: Reply with quote

Mark, I read it of course

I'll change the question: when exactly in the code do I need to read the state of the register?
at what point will the register be cleared by the initialization procedure?

I need the porf bit only, not the watchdog bit

ps
Maybe someone will suggest another method of saving the Mcucsr register before starting the initialization procedure?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 22, 2024 10:42 am    Post subject: Reply with quote

you must do this as soon as possible. in your code.
one way is using $initmicro

also , you say it works in 2085 but that is either a coincidence or not true since it was changed long time ago.

one thing that changed in 2086 : - mcucr register was not properly cleared at start up for old AVR processors. only the WD flag was reset, notice you should not write a 0, since some AVR have other unrelated bit flags in the MCUCR register! processors like that will have an additional mask in the dat file : WD=MCUCSR.WDRF,$E0

so some times, a fix means different behavior. you could rename the DAT file and remark that line if you want the old incorrect behavior.
without this additional mask, the compiler would first save the register in R0 then write a 0 to mcucsr. but while for many chips that is not a problem, some old chips have some other bits in mcucsr.
for those it will perform an AND with the mask to clear just the bits 0-4.
But in all cases the register is saved in r0

only the mask is new in 2086 to fix writing a 0 to other unrelated bits.
you will see that not all DAT files have this.

_________________
Mark
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 22, 2024 10:46 am    Post subject: Reply with quote

beside all that your code is wrong too.
you must not reset mcucsr to 0. the compiler already does that for you.

_________________
Mark
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 11:25 am    Post subject: Reply with quote

Thank you. I'll try different options.

The code was copied from projects that I have been using for more than 9 years... Smile

I will report the test results later.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 22, 2024 11:35 am    Post subject: Reply with quote

but i do not think these projects were using 2085?
anyway since the first version of bascom-avr the compiler clears the watchdog flags, since otherwise a processor could hang.
only later the register was saved in r0 to allow the user to do something with the info if needed.
and only in 2086 for some processors a fix was made not to clear the entire register (like you do in your code) but to clear just the power reset registers.
but it was never needed to clear mcucsr yourself.
your code must be very old.

_________________
Mark
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 11:38 am    Post subject: Reply with quote

2.0.8.1 and oldest version of Bascom.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5922
Location: Holland

blank.gif
PostPosted: Thu Feb 22, 2024 11:49 am    Post subject: Reply with quote

even in 2075 saving mcucsr into r0 existed.

your code never worked since mcucsr was cleared before your code executed.

Code:
Dim Begunok As Byte
Begunok = Mcucsr: Mcucsr = 0  
 

should be :

Code:
Dim Begunok As Byte
Begunok =
R0

so simply said you were under assumption your code worked, but id didnt. it loaded the register which was always 0.

_________________
Mark
Back to top
View user's profile Visit poster's website
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 12:06 pm    Post subject: Reply with quote

Mark,
I don't want to argue with you.

I have been using this method for a long time and successfully.
First I organize the variable, then I read into the status register variable.
And only in the new version I got the problem.

I use analysis of the reason for the launch to create a hidden method for entering the system menu. I usually check the bit and button press. If power is applied and the button is pressed, the device setup mode is activated.

I really don’t want to disable initialization, it’s easier for me to go back to the old version, since I don’t use new chips


Last edited by Alexander-Dan on Thu Feb 22, 2024 2:05 pm; edited 1 time in total
Back to top
View user's profile
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 12:17 pm    Post subject: Reply with quote

I am attaching two files: 2086 and 2085.
You can upload it to MK and check it yourself.
Back to top
View user's profile
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 1:08 pm    Post subject: Reply with quote

I checked this option. Yes, reading data from the register R0 solved this problem.

Code:

Dim Begunok As Byte
Begunok = R0                                                'Mcucsr

If Begunok.porf = 1 Then                                    '  
 
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu Feb 22, 2024 1:31 pm    Post subject: Reply with quote

In regards of ATM16, where I've checked, there is a difference between 2.0.8.5 and 2.0.8.6 with the effect, that BORF, EXTRF, PORF in MCUCSR is not reset in 2.0.8.5 and can be evaluated.
This has changed in 2.0.8.6, there these three flags get cleared.
albertsm wrote:
so simply said you were under assumption your code worked, but id didnt.

Which is not correct, it actually did.
Back to top
View user's profile
Alexander-Dan

Bascom Member



Joined: 13 Mar 2014
Posts: 111
Location: S.Posad

russia.gif
PostPosted: Thu Feb 22, 2024 1:52 pm    Post subject: Reply with quote

thank you for analyzing the code, MWS
I haven’t used assembler for a long time and I was too lazy to look at the codes obtained from different versions of the compiler using a disassembler.
Thanks again for the analysis!
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Thu Feb 22, 2024 2:10 pm    Post subject: Reply with quote

No problem.
As far as I remember there was always the rule to read MCUSR/MCUCSR not directly, but by fetching R0.
It worked for you by chance till 2086.002, history.txt gives a hint there for MCUCR.
Previously MCUCSR was AND-ed with &hF7, after with &hE0, which had the effect you did observe.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
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