View previous topic :: View next topic |
Author |
Message |
JamesAus
Joined: 08 Aug 2007 Posts: 50 Location: Australia

|
Posted: Fri Apr 29, 2022 7:17 am Post subject: AVR DB series EEPROM write? |
|
|
Hi All,
I have gone down the path of changing over some code from ATMEGA324PB to AVR128DB48, and wow, that isn't such a simple task. One issue I have is that I need to write to the EEPROM at runtime to store user configurable parameters. Before I try to solve that little problem I was wondering if anyone had already done so and would like to share some of their code?
Thanks in advance,
James
(BASCOM-AVR version : 2.0.8.5 ) |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6125 Location: Holland

|
Posted: Fri Apr 29, 2022 8:27 am Post subject: |
|
|
when you never used Xmega, it is indeed harder.
it is a good idea to inform us what problems you encountered.
the eeprom is supported so it should work the same as always.
so why you dont show some code that gives problems?
i must add to this that recently i found that between platforms xtiny,megax and DB/DA there are differences in eeprom handling for the UPDI programming. So maybe this applies to internal write as well.
but last time i checked it was good.
so code like this :
Code: | dim eByte as ERAM byte
dim btest as byte
btest=ebyte 'read
print btest
btest=100
ebyte=btest
btest=ebyte 'read
print btest
end
|
should work. _________________ Mark |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6125 Location: Holland

|
Posted: Fri Apr 29, 2022 11:46 am Post subject: |
|
|
it works perfect for me.
Code: |
'--------------------------------------------------------------------------------
'name : AVRX128db28-test.bas
'copyright : (c) 1995-2021, MCS Electronics
'purpose : demonstrates AVR128DB28
'micro : AVR128DB28
'suited for demo : no
'commercial addon needed : yes
'--------------------------------------------------------------------------------
$regfile = "AVRX128db28.dat"
$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 40
'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1
'configure comparator
Config Ac0 = On , Hysmode = 10 , Mux_pos = Ainp1 , Dacref = &H55
'Some interrupts have multiple trigger options. There is however just one interrupt vector
On Zcd0_falling Isr_zcd
Enable Zcd0_falling 'different settings are possible but there is just 1 interrupt !
Disable Zcd0_both ' you best use the same trigger name but you can use different ones
Enable Zcd0_both
'The REGMODE option is for some statements implicit. Like for PORT_MUX.
Config Port_mux = Overwrite , Evouta = Alt1_pa7 , Ac0 = Alt1_pc6 , Lut0 = Alt1_pa6 , Spi0 = None
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
'new config VREG POWER option
Config Vregpwr = Auto
'voltage ref
Config Vref = Dummy , Ac = 1v024 , Adc0 = 2v048 , Dac0 = 2v048 , Force_adc0 = Disabled , Force_ac = Enabled
'zero cross detector
Config Zcd0 = Enabled , Runmode = Disabled , Invert = Enabled , Out_enable = Enabled
'brown out detector
Config Bod_vlm = Dummy , Bod_sleep = Disabled , Vlm_threshold = 5above
'opamp
Config Opamp = Enabled , Inp_range = Rail_to_rail , Opamp0_always_on = Enabled , Opamp0_muxbot = Inp , Opamp0_muxneg = Wip , Opamp0_muxwip = R1_6r_r2_10r
'DA converter ,out_enable will set the port direction to output
Config Dac0 = Enabled , Out_enable = Enabled , Runmode = Enabled
'dimension a variable
Dim B As Byte
dim eB as eram byte
eb=10 'write to eeprom
Print "Test USART"
Do
b=eb 'read eeprom
print "ERAM : "; b
Print "Hello" ; Spc(3) ; B
Waitms 1000
Incr B
Loop
Isr_zcd:
Zcd0_status = Bits(zcd_crossif_bp) 'reset the interrupt flag
Return
|
normally the byte is increased in the loop but because of the reading, it is stuck to its value : 10
works in real hardware. _________________ Mark |
|
Back to top |
|
 |
JamesAus
Joined: 08 Aug 2007 Posts: 50 Location: Australia

|
Posted: Fri Apr 29, 2022 1:15 pm Post subject: |
|
|
Thanks Mark,
I was using Readeeprom & Writeeeprom. I'll change to Dim as Eram variables and hopefully that will solve the problem. Will post an update after I've done so.
Regards
James |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6125 Location: Holland

|
Posted: Fri Apr 29, 2022 1:22 pm Post subject: |
|
|
readeeprom/writeeeprom should work as well. but will test that too.
eeprom is a bit tricky in this platform as the memory is mapped different and the mechanism to write is also different.
i do notice that the simulator does not show the eeprom memory correct (due the offset in memory). _________________ Mark |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6125 Location: Holland

|
Posted: Fri Apr 29, 2022 1:32 pm Post subject: |
|
|
no problem either :
Code: |
'--------------------------------------------------------------------------------
'name : AVRX128db28-eeprom.bas
'copyright : (c) 1995-2022, MCS Electronics
'purpose : demonstrates AVR128DB28 EEPROM
'micro : AVR128DB28
'suited for demo : no
'commercial addon needed : yes
'--------------------------------------------------------------------------------
$regfile = "AVRX128db28.dat"
$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 40
'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
'dimension a variable
Dim B As Byte, s as string * 40
dim eb as eram byte
dim eS as eram string * 40
Print "Test ERAM"
Do
input "R/W? ",s
if s="W" then
s="This is eeprom test"
es=s
b=100
eb=b
elseif s="w" then
b=101
WriteEEprom b,0
elseif s="R" then
s=es: print s
b=eb:print b
elseif s="r" then
readeeprom b,0
print b
end if
Loop
|
_________________ Mark |
|
Back to top |
|
 |
JamesAus
Joined: 08 Aug 2007 Posts: 50 Location: Australia

|
Posted: Sat Apr 30, 2022 10:45 am Post subject: |
|
|
Hi Mark,
I've tried your code, and still no luck. No data is witten to the EEPROM. After writing either way all cells are still &HFF confirmed by downloading eeprom data from micro. There are a couple of changes I've made as below.. (Usart3 used, and AVR128DB48 used) as far as I can see the .dat is correct, certainly the NVM sections that matter in this case.
Code: |
'--------------------------------------------------------------------------------
'name : AVRX128db28-eeprom.bas
'copyright : (c) 1995-2022, MCS Electronics
'purpose : demonstrates AVR128DB28 EEPROM
'micro : AVR128DB28
'suited for demo : no
'commercial addon needed : yes
'--------------------------------------------------------------------------------
' Changes made...
' AVRX128DB48, not AVRX128DB28
'USART3 used instead
$regfile = "AVRX128db48.dat"
$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 40
'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1
Config Com4 = 19200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1
Open "COM4:" For Binary As #4
'dimension a variable
Dim B As Byte, s as string * 40
dim eb as eram byte
dim eS as eram string * 40
Print #4 , "Test ERAM"
Do
Input #4 , "R/W? " , S
if s="W" then
s="This is eeprom test"
es=s
b=100
eb=b
Elseif S = "w" Then
b=101
WriteEEprom b,0
Elseif S = "R" Then
S = Es : Print #4 , S
B = Eb : Print #4 , B
Elseif S = "r" Then
readeeprom b,0
Print #4 , B
end if
Loop
Close #4
End
|
Thanks for your input. .dat file attached.
I've also encountered a couple of other little issues which I've overcome. I'll create additional threads for these when I get all my notes together.
Regards James |
|
Back to top |
|
 |
JamesAus
Joined: 08 Aug 2007 Posts: 50 Location: Australia

|
Posted: Sat Apr 30, 2022 10:46 am Post subject: |
|
|
Okay...looks like I'm not allowed to attached the .dat  |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6125 Location: Holland

|
Posted: Sat Apr 30, 2022 7:22 pm Post subject: |
|
|
when you post non image files, ZIP them.
ZIP is accepted.
but why would you post the DAT if we supply that?
what version is the compiler build? _________________ Mark |
|
Back to top |
|
 |
JamesAus
Joined: 08 Aug 2007 Posts: 50 Location: Australia

|
Posted: Sat Apr 30, 2022 8:48 pm Post subject: |
|
|
There is (or was) no .dat for the 48 pin
Compiler version :2.0.8.5
Compiler build :2.0.8.5.003
IDE version :2.0.8.5.002
.dat attached
Regards
James |
|
Back to top |
|
 |
JamesAus
Joined: 08 Aug 2007 Posts: 50 Location: Australia

|
Posted: Mon May 09, 2022 2:54 am Post subject: |
|
|
I was looking at this issue again over the weekend.
It seems that EEERWR is never enabled in NVMCTRL.CTRLA. I'm definitely no expert at assembly, but, is it possible there is a problem in the xtiny.lib as below...
_WriteEEPROM_ClearPage:
Ldi R22,$9D ; ccp spm
Rcall _CheckEpromReady ; check
Ldi R23,4 ; clear page
_WriteEEPROM_Write:
Out CPU_CCP,R22 ;
sts nvmctrl_ctrla,r23 ; command to clear page
Should actually be.....
_WriteEEPROM_ClearPage:
Ldi R22,$9D ; ccp spm
Rcall _CheckEpromReady ; check
Ldi R23,$13 ; clear page
_WriteEEPROM_Write:
Out CPU_CCP,R22 ;
sts nvmctrl_ctrla,r23 ; command to clear page
Regards,
James |
|
Back to top |
|
 |
albertsm
Joined: 09 Apr 2004 Posts: 6125 Location: Holland

|
Posted: Tue May 10, 2022 7:58 pm Post subject: |
|
|
the lib has this :
#IF _XTINY<3
..code for xtiny and megax
#else
'code for DB/DA series
ldi r23,&H13 ; command to write
etc.
so it depends on the used platform which code is used.
so maybe you do not have the latest version of the lib?
in that case, contact support. _________________ Mark |
|
Back to top |
|
 |
cable
Joined: 26 Nov 2012 Posts: 1
|
Posted: Sat Feb 25, 2023 6:15 pm Post subject: EEPROM Write |
|
|
I also have the problem that I cannot write to the EEprom. Is there already a solution. |
|
Back to top |
|
 |
matjazs
Joined: 08 Nov 2016 Posts: 100
|
Posted: Sun Feb 02, 2025 1:42 pm Post subject: |
|
|
I have the same problem.
Where can I get new *.LIB? |
|
Back to top |
|
 |
|
|
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
|
|