Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Did anybody use FM24C256 FRAM lib on AVRX?

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR XTINY/MEGAX/AVRX
View previous topic :: View next topic  
Author Message
boeseturbo

Bascom Member



Joined: 23 Jul 2007
Posts: 65

blank.gif
PostPosted: Mon May 05, 2025 9:25 am    Post subject: Did anybody use FM24C256 FRAM lib on AVRX? Reply with quote

Hi Friends,

Did anybody use FM24C256 FRAM lib on AVRX? I looked into the libary and I don't understand it Wink.... How can I change the lib for using it with AVRX128DA32? It has TWI0 and TWI1.... the xmega-lib has TWIC,D,E etc....

Cheers & thanks for help!
Back to top
View user's profile
ok1hdu

Bascom Member



Joined: 10 Sep 2018
Posts: 17

czechrepublic.gif
PostPosted: Mon Jul 14, 2025 7:29 am    Post subject: Reply with quote

I have the same problem.
The fm24c64_256.lib library works perfectly for "classic" AVRs, but I don't know how (if at all) it could be used for AVRX.
I don't know how to define which TWI port to use.
And it would be quite useful for AVRX, because compared to "classic" AVRs, they have a quite small EEprom.
Any ideas for experiments?
Thanks, Jarda
Back to top
View user's profile
maurineri

Bascom Member



Joined: 03 Aug 2006
Posts: 15
Location: Italy

italy.gif
PostPosted: Thu Jul 24, 2025 2:51 pm    Post subject: Reply with quote

Hi,
just written some lines of code to test "sleeping" TWI on relatively old board ; it's elementary, just to undestand "How to.."
Starting from MCS samples I have adapted code for:
- scan I2C net , for all domain
- show result of scanning
- use found Address to write/read one 24F256W on some location
Obviously is not efficient code.. to access multiple byte see 24F256 data sheet
Just my two cents. (apologies for Italian comment on header and thanks to Mark for TWI alternate configuration)

'--------------------------------------------------------------------------------
' 24/07/2025 - testato su TWI0 - pin PA2 e PA3 (default pinout)
' provato a 100Khz,400Khz e 1 Mhz con pullup 4.7k
' e provato anche su PC2 e PC3 (alternative pinout)
' questo codice che gira su AVR128 provvede separatamente a:

' 1) scanner della rete I2C per l'intera estensione (0 to 254 step 2)
' 2) lettura/scrittura di una FRAM in I2C (usata una 256k per test)

' NOTA BENE: non viene usata la libreria $lib "fm24c64_256.lib" ma
' nulla vieta di provarla per efficienza come EEPROM
' vedi esempi specifici con $eepromsize = &H8000
' (!) Per andare a 2 Mhz o 4 Mhz servono buffers sulle linee..

'--------------------------------------------------------------------------------

$regfile = "AVRX128da28.dat"
$crystal = 24000000
$hwstack = 40
$swstack = 40
$framesize = 64

'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1
'set up the COM por/USART
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1

'************************* TWI configuration as master ************************
'Is possible to configure TWI speed at 100 KHz or 400 Khz or 1 MhZ and more..
Config Twi0 = 1000000
'Default Pinout and alternative for TWI:
'PIN FUNCTION
'PA2 SDA PC2 SDA
'PA3 SCL PC3 SCL

' 'Default configuration for TWI on PA2 e PA3
'Config Xpin = Porta.2 , Outpull = Pullup
'Config Xpin = Porta.3 , Outpull = Pullup

' 'Alternate Pins configuration for TWI on PC2 e PC3
Config PORT_MUX=overwrite, twi0=ALT2_SCLSDA_PC3PC2_SLAVE_PC7PC6
Config Xpin = PortC.2 , Outpull = Pullup
Config Xpin = PortC.3 , Outpull = Pullup

'Twi_start must be declared to have error free compilation..
Dim Twi_start As Byte
'Init TWI service
I2cinit
'************************* TWI configuration as master ************************

'Declaration for sample code..
Dim J As Byte , B As Byte ,MNadr As Byte,MNdata As Byte,MNdata1 As Byte,MNnum As Byte ,MNoffset As Byte

'test loop for both function (scanner and FRAM read/write)
do

Print "****** Scan start ******"
MNadr=0

For B = 0 To 254 Step 2 'for all odd addresses
I2cstart 'send start
I2cwbyte B 'send address
If Err = 0 Then 'we got an ack
Print "Slave found at : " ; B ; " hex : " ; Hex(b) ; " bin : " ; Bin(b)
MNadr=B
End If
I2cstop
Next

Print "======= End Scan ======="

wait 1

'If found FRAM ( Caution : must be present ONLY FRAM on I2C net..)
if MNadr > 0 then

MNdata1=0

I2cstart
I2cwbyte MNadr
I2cwbyte MNnum
I2cwbyte MNnum
I2cstart
I2cwbyte MNadr+1
I2crbyte MNdata1,Nack

I2cstop
print "Last data Read << ";MNdata1;" in ";MNadr;" loc ";MNnum

MNnum=MNnum+1

I2cstart
I2cwbyte MNadr
I2cwbyte MNnum
I2cwbyte MNnum
I2cwbyte MNnum
I2cstop

print "Write Data >> ";MNnum;" in ";MNadr;" loc ";MNnum

I2cstart
I2cwbyte MNadr
I2cwbyte MNnum
I2cwbyte MNnum
I2cstart
I2cwbyte MNadr+1
I2crbyte MNdata1,Nack

I2cstop
print "Verify Data << ";MNdata1;" in ";MNadr;" loc ";MNnum

Dim tmp As Byte ,tmp1 As Byte

'Write and Read test Loop
for tmp=1 to 10
tmp1=255-tmp
tmp1=tmp1-MNnum
I2cstart
I2cwbyte MNadr
I2cwbyte 0
I2cwbyte tmp
I2cwbyte tmp1
I2cstop
next tmp

for tmp=1 to 10
tmp1=255-tmp
MNdata1=0

I2cstart
I2cwbyte MNadr
I2cwbyte 0
I2cwbyte tmp
I2cstart
I2cwbyte MNadr+1
I2crbyte MNdata1,Nack
print ">";MNdata1;" ";
next tmp
print




endif

loop
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR XTINY/MEGAX/AVRX All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can 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