Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

How to Write and Read XMega User Signatures
Goto page Previous  1, 2
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 454

https://www.mcselec.com/c
PostPosted: Wed Jan 09, 2019 10:22 pm    Post subject: Reply with quote

.

This code works perfectly to access the XMega User Signature:

Code:
$regfile = "xm192A3Udef.dat"
$hwstack = 80
$swstack = 80
$framesize = 80

$crystal = 32000000
Config Osc = Disabled , 32mhzosc = Enabled
Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1


$loader = $18000                                            'Bootloader START Address


Disable Interrupts

Config Submode = New

Config Com7 = 56700 , Mode = Asynchroneous , Parity = None , Stopbits = 1 , Databits = 8
Open "COM7:" For Binary As #1

Const Bascom = "BASCOM"

Dim B_io As Byte , W As Word , Z As Dword , Ss As String * 6 , Buf(6) As Byte At Ss Overlay
Ss = Bascom

Declare Sub User_sig(byval Rd_wr_er As Byte , Byval Offset As Word , Byref B_io As Byte)
Sub User_sig(byval Rd_wr_er As Byte , Byval Offset As Word , Byref B_io As Byte)

     Z = Offset

     Pushall

     !lds r30,{Z}                                           'Will not accept Local Variables
     !lds r31,{Z+1}                                         'Global DIM Z is used

     Select Case Rd_wr_er
          Case 0
               Nvm_cmd = &H01                               'read
               Cpu_ccp = &H9D
               !lpm

          Case 1

               Nvm_cmd = &H1A                               'write
               Cpu_ccp = &H9D
               !spm

          Case 2
               Nvm_cmd = &H18                               'erase
               Cpu_ccp = &H9D
               !spm

          Case 3
               Nvm_cmd = &H23                               'move data to Flash Buffer
               Cpu_ccp = &H9D
               !spm
     End Select

Nvm_wait:

     !lds r23, NVM_STATUS
     !sbrc r23,7
     !rjmp nvm_wait

     If Rd_wr_er = 0 Then !sts {b_io} , R0      'contents of User Signature

     Popall
End Sub

'MAIN

     Call User_sig(2 , &H0000 , B_io)                       'Erase - This erases the
                                                            'complete 512 User Signature
                                                            'byte-space
     For W = 1 To 6 Step 2
          R0 = Buf(w)                                       'move data to r0 and r1 registers
          R1 = Buf(w + 1)

          Call User_sig(3 , W , B_io)                       'move to Flash Buffer
     Next

     Call User_sig(1 , &H0000 , B_io)                       'Write User Signature
                                                            'This was confirmed with ATMEL Studio
For W = 0 To 5
          Call User_sig(0 , W , B_io)                       'READ
          Print #1 , Chr(b_io) ;
Next

End


Thanks to Laborratte, Mark Alberts and Netzman.

[ NOTE: the description given in AVR1316 about "byte" access to the User Signature is only true for READ operations. ]

E
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 Previous  1, 2
Page 2 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