Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

XMEGA EEPROM Gotcha

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

Bascom Member



Joined: 02 Jan 2007
Posts: 76

blank.gif
PostPosted: Fri Dec 03, 2021 2:41 am    Post subject: XMEGA EEPROM Gotcha Reply with quote

I think I found a gotcha using EEPROM

The CONFIG EEPROM statement sets the Mode of Operation to either Quick or Mapped
if that config statement is not present at all then I can't store and retrieve data from EEPROM

ie This does not work:

EE_B = 99
B = EE_B
Print #6, "B= "; B

EE_MySerialNumber = "1234"
Temp_str = EE_MySerialNumber
Print #6, "EE_MySerialNumber= "; Temp_str

But if I include CONFIG EEPROM then it works. I guess I would have thought it would have defaulted to Mapped.


Code:
'*******************************************************************************
' FILENAME:     ATXMEGA128A1 EEPROM Test x.bas
'
' PROCESSOR:    ATXMEGA128A1
' CLOCK:        16Mhz XTAL
' TITLE:
' BOARD:        0420-04 and 0420-01
' MODIFIED:     3-DEC-2021
' AUTHOR:       Frank Thomson

'*******************************************************************************
$regfile = "xm128A1Udef.dat" '"xm128A1Udef.dat" '  "C:\MCS\BASCAVR2082\DAT\xm128A1Udef.dat"
$framesize = 200         ' After global variables then after unused SRAM, grows bottom up, string conversion routines (PRINT, LCD, INPUT) require a buffer in SRAM
$swstack = 200           ' ISR routine parameters and grow top down
$hwstack = 200           ' Return address after routine call (SUB, FUNCTION, GOSUB) and grow top down

$crystal = 16000000

'Config Osc = Enabled , 32mhzosc = Enabled         ' enable 2 MHz and 32 MHz internal oscillators
'Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1

Config osc = enabled , EXTOSC = enabled , 32KHZOSC=DISABLED, pllosc = enabled , range = 12MHZ_16MHZ , startup = XTAL_16KCLK , pllsource = extclock , pllmul = 1
Config Sysclock = PLL , Prescalea = 1 , Prescalebc = 1_1
CONFIG EEPROM=Quick  ' <-- This must be defined as Mapped or Quick.  Leaving this out and eeprom does not work
Disable Jtag
'--------{INITIALSE SOFT I2C}----------------------------------
'$FORCESOFTI2C
'Config I2cdelay = 10
'$lib "i2c.lbx"  ' Software I2C



'----{ INITIALIZE HARDWARE}------------------------------------
' PORTS A,B, C, D, E, F, H, J, K, Q Default to ALL INPUTS on Reset
' Port D which has a LED
'PORT D.0 - 0   0  LED SPARE 2
'     D.1 - 0   0  LED SPARE 1
'     D.2 - 0   0  LED FAIL
'     D.3 - 0   0  LED STATUS
'     D.4 - 0   0  LED TESTING
'     D.5 - 0   0  LED DEVICE
'     D.6 - 0   0  Reserved for USB N
'     D.7 - 0   0  Reserved for USB N
'                76543210
Config PortD = &B00000011
PortD        = &B00000000

'--{SOFTWARE I2C}-------------------------
'config sda = portF.0
'Config SCL = PortF.1
'I2cinit

'---- INITIALISE COMMS ---------------------------------------------------------------------
 Config Com5 = 9600 , mode = ASYNCHRONEOUS, Parity = None , Stopbits = 1 , Databits = 8
 Open "COM5:" For Binary As #6
 Config Serialin6 = Buffered , Size = 10

 '--{VARIABLES}-------------------------
 Dim LEDcounter as word
 Dim B as byte
 Dim Temp_str As String * 16
 Dim Blank As Eram Word At 0
 dim EE_MySerialNumber as ERAM string * 4
 dim EE_B as ERAM Byte


'-----MAIN PROGRAM START---------------------------------------------------------------------
EE_B = 99

B = EE_B
Print #6, "B= "; B
EE_MySerialNumber = "1234"
   Temp_str =  EE_MySerialNumber
   Print #6, "EE_MySerialNumber= "; Temp_str


portd.0 = 1 ' LED SPARE 2 ON
Print #6 ,
print #6, "AT X Mega 128A1U EEPROM Test Program"


loopforever:






' Heartbeat LED
LEDcounter   =    LEDcounter  + 1
if LEDcounter >= 60000 then
    toggle portd.1   'FAIL LED ON OFF
    LEDcounter = 0
end if


goto loopforever


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

Bascom Member



Joined: 22 Aug 2009
Posts: 2262

blank.gif
PostPosted: Fri Dec 03, 2021 5:16 pm    Post subject: Re: XMEGA EEPROM Gotcha Reply with quote

syndetic1 wrote:
I think I found a gotcha

You seem to have gotcha'd your own nose Very Happy
Quote:
But if I include CONFIG EEPROM then it works. I guess I would have thought it would have defaulted to Mapped.

Your guesses for thoughts do not correspond with the help:
Quote:
CONFIG EEPROM
Setup memory mode for EEPROM in XMEGA.

When you use the BASCOM EEPROM routines, you must include this statement before you use the EEPROM.
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