Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ATXmega EEPROM problem

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
techknight

Bascom Member



Joined: 21 Apr 2008
Posts: 231

usa.gif
PostPosted: Mon Jan 04, 2016 10:34 pm    Post subject: ATXmega EEPROM problem Reply with quote

I am having a very hard time saving to EEPROM, if I have a byte array as ERAM byte.

Sometimes it works, sometimes it doesnt.

I am storing MD5 data into an array as a password thing on my device. I have a reset password button which writes the default passwords early in the boot, and then hangs until next reboot by pushing a button.

That works fine.

But if I programmatically send the password to write to EEPROM, it fails, and never writes. I am using the exact same code. And this code works on regular ATmegas. Just not the Xmega properly.

My subroutine terminates by doing a software reset on the processor. I even added a 1 second delay after the For loop for writing the bytes to eeprom.

I did the config eeprom thing.

Any ideas?

Edit: I did try adding this into my for loop:
Code:

                     Do
                     Loop Until Nvm_status.7 = 0
 


That didnt seem to help at all. Hmmm....

Here is the full code:
Code:

               Rxmode = Inputbuffer(7)                      'Set the communication mode before we do anything.
               Flags = 0
               Set Flags.3
               Set Ismaster
               Passwordtocheck = "a25e41ad01cf6903af5cXXXXXXXXXXXX"       'Emergency entry when all is lost Wink 'XXed out some to prevent reversal

               I = 1
               For Count = 1 To 16 Step 1
                  A = Count + 7
                  Tempdata = Mid(passwordtocheck , I , 2)
                  M = Hexval(tempdata)
                  I = I + 2
                  If M <> Inputbuffer(a) Then
                     Reset Ismaster
                  End If
               Next

               Passwordtocheck = ""

               For Count = 1 To 16 Step 1
                  A = Count + 7
                  D = Adminbytes(count)
                  If D <> Inputbuffer(a) Then
                     Reset Flags.3
                  End If
               Next

               If Flags.3 = 1 Or Ismaster = 1 Then
                  For Count = 1 To 16 Step 1
                     A = Count + 23
                     Userbytes(count) = Inputbuffer(a)
                  Next

                  Flags = 0
                  Ismaster = 0
                  Call Rsp90
                  waitms 125
'                  Set Vccio
                  Cpu_ccp = &HD8
                  Rst_ctrl.0 = 1
               Else
                  Reset Flags.4
                  Reset Flags.6
                  Call Rsp6f
                  waitms 125
'                  Set Vccio
                  Cpu_ccp = &HD8
                  Rst_ctrl.0 = 1
               End If
 



(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 548

PostPosted: Tue Jan 05, 2016 6:07 am    Post subject: Reply with quote

TechKnight,

when you post to ask for help, you should have the courtesy of posting some code we can compile in order to help you. What you have done here is meaningless.

DIM xxx as eram Byte? Word? Widget??

Config Eeprom = ???

Other???
Back to top
View user's profile
techknight

Bascom Member



Joined: 21 Apr 2008
Posts: 231

usa.gif
PostPosted: Tue Jan 05, 2016 2:23 pm    Post subject: Reply with quote

I did post the code! The whole subroutine block responsible for writing the information to EEPROM is in my first post!

What more do you need? Oh and the "Meaningless" comment was unnecessary, and rude, and automatically causes a raise in my defenses, depicting you as a troll.... Which you may or may not be.

Oh, and I have done alot of troubleshooting on my own, I only come for help online as a very last resort. I have figured out the problem is with ERAM arrays. single bytes have no trouble. But when declaring an ERAM array, thats when the trouble creeps up. As a last ditch effort I decided to use the NVM flag check to make sure I am giving enough time for the EEPROM to complete its write inside my FOR loop... That didnt solve it, as I mentioned in my first post.

Edit: Oops I forgot the important eeprom declarations.

Userbytes(16) as ERam byte
Adminbytes(16) as ERAM byte

And yes, EEPROM is mapped. I learned about that in the very beginning. inputbuffer is my I/O Buffer array that gets populated when I send datapackets to the XMega. There are header/length/addressing word checks which are excluded as they are not necessary, but should be aware of if your curious on the inputbuffer array offsets.
Back to top
View user's profile
techknight

Bascom Member



Joined: 21 Apr 2008
Posts: 231

usa.gif
PostPosted: Tue Jan 05, 2016 4:31 pm    Post subject: Reply with quote

I fixed it. Turns out I made a small mistake which for some strange reason works on all the ATmegas, but NOT the Xmega.

I was using this:

If Configversion <> 2 then
Configversion = 2

Well, my subroutine was running every time I rebooted the processor, reverting all the changes in EEPROM back to defaults. Whoops.

Configversion is an ERAM byte.

Changing it to this:

M = Configversion
If M <> 2 Then 'Check EEPROM for compatible Configuration, if not, Restore defaults


Fixed it. So I guess I cant use ERAM bytes directly in IF statements? Worked on the ATmega1284.
Back to top
View user's profile
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 548

PostPosted: Wed Jan 06, 2016 3:50 am    Post subject: Reply with quote

You just proved my point.

Quote:
Configversion is an ERAM byte.

Changing it to this:

M = Configversion
If M <> 2 Then 'Check EEPROM for compatible Configuration, if not, Restore defaults
Fixed it. So I guess I cant use ERAM bytes directly in IF statements? Worked on the ATmega1284.

This is nowhere in your post. It would have been something many people could have helped you.

And
Quote:
Edit: Oops I forgot the important eeprom declarations.
Userbytes(16) as ERam byte
Adminbytes(16) as ERAM byte
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
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