View previous topic :: View next topic |
Author |
Message |
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 9:07 am Post subject: using $eepromsize for at2cc08 |
|
|
Hi
is it possible to use $eepromsize directive to use at24c08 instead of internal eeprom?
i search help and froum,but dont find a bright answer. also i tested it by hardware and see that it use internal eeprom after using this instruction:
Code: | $regfile = "m128def.dat"
$crystal = 16000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comf.6:9600,8,n,1" For Output As #1
'---------------------------At24c08 configuration-------------------------------
$lib "i2c_extended.lib"
$eepromsize = &H1000
Config Scl = Portg.0
Config Sda = Portg.1
I2cinit
'-------------------------------------------------------------------------------
Dim Eb As Eram Byte
Dim B As Byte
Dim C As Byte
B = 135
Eb = B
C = Eb
'-------------------------------------------------------------------------------
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'------------------------------------------------------------------------------- |
resault:
b=135
eb=135
even when i disconnect at24c08 from uc!
Regards
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jul 01, 2016 9:25 am Post subject: |
|
|
i advise to read the help again.
When you use an external EEPROM and an alternative EEPROM library such as FM24C16 or FM25C256
See also
FM24C16, FM25C256 _________________ Mark |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 9:44 am Post subject: |
|
|
thanks Mark
i add $lib "fm24c16.lib" directive also, and it did not work.
Code: | $regfile = "m128def.dat"
$crystal = 16000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comf.6:9600,8,n,1" For Output As #1
'---------------------------At24c08 configuration-------------------------------
$lib "i2c_extended.lib"
$lib "fm24c16.lib"
$eepromsize = &H1000
Config Scl = Portg.0
Config Sda = Portg.1
I2cinit
'-------------------------------------------------------------------------------
Dim Eb As Eram Byte
Dim B As Byte
Dim C As Byte
B = 135
Eb = B
C = Eb
'-------------------------------------------------------------------------------
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'------------------------------------------------------------------------------- |
it seems that the library work just with Frams like Ramtorn chips, not ordinary eeprom chips like atmel at24c08.
do you confirm it?
Regards |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jul 01, 2016 9:53 am Post subject: |
|
|
it will also work with normal i2c. but when you read the help and have a look at the provided sample, you will notice that the lib s for 24C16. And more important : it uses i2c/twi.
there is also a lib for 24c04.
i did not check but the lib could work with soft i2c too.
you should however first test if your i2c works. (address lines correct connected, pull up etc.)
then try the provided sample, and make sure the correct scl/dta pins are pvovided with config. _________________ Mark |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 10:11 am Post subject: |
|
|
[/quote]you should however first test if your i2c works. (address lines correct connected, pull up etc.)
then try the provided sample, and make sure the correct scl/dta pins are pvovided with config[/quote]
this code work on my pcb for last 1 year and i am sure about hardware issue.
Code: | $regfile = "m128def.dat"
$crystal = 16000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comf.6:9600,8,n,1" For Output As #1
'-------------------------------------------------------------------------------
Dim Adres As Byte , Value As Integer
Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Integer)
Declare Sub Read_eeprom(byval Adres As Byte , Value As Integer)
'-------------------------------------------------------------------------------
$lib "i2c_extended.lib"
Config Scl = Portg.0
Config Sda = Portg.1
Const Addressw = 160 'slave write address
Const Addressr = 161 'slave read address
I2cinit
'-------------------------------------------------------------------------------
Dim B As Integer
Dim C As Integer
'-------------------------------------------------------------------------------
B = 135
Call Write_eeprom(100 , B)
Waitus 220
Call Read_eeprom(100 , C)
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'-------------------------------------------------------------------------------
Sub Write_eeprom(byval Adres As Byte , Byval Value As Integer)
Local Lowbyte As Byte
Local Highbyte As Byte
Lowbyte = Low(value)
Highbyte = High(value)
I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte Adres 'asdress of EEPROM
I2cwbyte Lowbyte 'value to write
I2cwbyte Highbyte
I2cstop 'stop condition
End Sub
'-------------------------------------------------------------------------------
Sub Read_eeprom(byval Adres As Byte , Value As Integer)
Local Lowbyter As Byte
Local Highbytew As Byte
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Lowbyter , Ack 'read byte
I2crbyte Highbytew , Nack 'read byte
I2cstop 'generate stop
Value = Makeint(lowbyter , Highbytew )
End Sub
'------------------------------------------------------------------------------- |
so from your guidance i understand that my problem is using softeare i2c.
i will test it with hardware and send the resault here.
Regards |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jul 01, 2016 10:18 am Post subject: |
|
|
you use bad pins which require a special lib already.
i have no idea why one would not use the dedicated hardware pins for i2c but ok.
in this case you have to include both libs in the right order.
first the extended lib, then the FM lib. _________________ Mark |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 11:09 am Post subject: |
|
|
the test resualts are as below:
test 1: for confirm that my hardware are ok on mega32:
Code: | $regfile = "m32def.dat"
$crystal = 12000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'-------------------------------------------------------------------------------
Dim Adres As Byte , Value As Integer
Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Integer)
Declare Sub Read_eeprom(byval Adres As Byte , Value As Integer)
'-------------------------------------------------------------------------------
Config Scl = Portc.0
Config Sda = Portc.1
I2cinit
Const Addressw = 160 'slave write address
Const Addressr = 161 'slave read address
I2cinit
'-------------------------------------------------------------------------------
Dim B As Integer
Dim C As Integer
'-------------------------------------------------------------------------------
B = 135
Call Write_eeprom(100 , B)
Waitms 10
Call Read_eeprom(100 , C)
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'-------------------------------------------------------------------------------
Sub Write_eeprom(byval Adres As Byte , Byval Value As Integer)
Local Lowbyte As Byte
Local Highbyte As Byte
Lowbyte = Low(value)
Highbyte = High(value)
I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte Adres 'asdress of EEPROM
I2cwbyte Lowbyte 'value to write
I2cwbyte Highbyte
I2cstop 'stop condition
End Sub
'-------------------------------------------------------------------------------
Sub Read_eeprom(byval Adres As Byte , Value As Integer)
Local Lowbyter As Byte
Local Highbytew As Byte
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Lowbyter , Ack 'read byte
I2crbyte Highbytew , Nack 'read byte
I2cstop 'generate stop
Value = Makeint(lowbyter , Highbytew )
End Sub
'------------------------------------------------------------------------------- |
resault:
start
b=135
eb=135
so my hardware is ok
and software i2c work fine |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 11:12 am Post subject: |
|
|
test 2:
Code: | $regfile = "m32def.dat"
$crystal = 12000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'-------------------------------------------------------------------------------
Dim Adres As Byte , Value As Integer
Declare Sub Write_eeprom(byval Adres As Byte , Byval Value As Integer)
Declare Sub Read_eeprom(byval Adres As Byte , Value As Integer)
'-------------------------------------------------------------------------------
$lib "i2c_twi.lbx"
Config Scl = Portc.0
Config Sda = Portc.1
I2cinit
Config Twi = 100000
Const Addressw = 160 'slave write address
Const Addressr = 161 'slave read address
I2cinit
'-------------------------------------------------------------------------------
Dim B As Integer
Dim C As Integer
'-------------------------------------------------------------------------------
B = 135
Call Write_eeprom(100 , B)
Waitms 10
Call Read_eeprom(100 , C)
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'-------------------------------------------------------------------------------
Sub Write_eeprom(byval Adres As Byte , Byval Value As Integer)
Local Lowbyte As Byte
Local Highbyte As Byte
Lowbyte = Low(value)
Highbyte = High(value)
I2cstart 'start condition
I2cwbyte Addressw 'slave address
I2cwbyte Adres 'asdress of EEPROM
I2cwbyte Lowbyte 'value to write
I2cwbyte Highbyte
I2cstop 'stop condition
End Sub
'-------------------------------------------------------------------------------
Sub Read_eeprom(byval Adres As Byte , Value As Integer)
Local Lowbyter As Byte
Local Highbytew As Byte
I2cstart 'generate start
I2cwbyte Addressw 'slave adsress
I2cwbyte Adres 'address of EEPROM
I2cstart 'repeated start
I2cwbyte Addressr 'slave address (read)
I2crbyte Lowbyter , Ack 'read byte
I2crbyte Highbytew , Nack 'read byte
I2cstop 'generate stop
Value = Makeint(lowbyter , Highbytew )
End Sub
'------------------------------------------------------------------------------- |
resault:
start
b=135
eb=135
so hardware i2c is ok also |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 11:17 am Post subject: |
|
|
test 3:
Code: | $regfile = "m32def.dat"
$crystal = 12000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'---------------------------At24c08 configuration-------------------------------
Config Scl = Portc.0
Config Sda = Portc.1
I2cinit
$eepromsize = &H8000
$lib "fm24c64_256.lib"
'-------------------------------------------------------------------------------
Dim Eb As Eram Byte
Dim B As Byte
Dim C As Byte
B = 135
Eb = B
Waitms 10
C = Eb
'-------------------------------------------------------------------------------
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'------------------------------------------------------------------------------- |
resault:
start
b=135
eb=135
so $eepromsize work fine with software i2c also |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 11:22 am Post subject: |
|
|
test 4:
Code: | $regfile = "m32def.dat"
$crystal = 12000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'---------------------------At24c08 configuration-------------------------------
$lib "i2c_twi.lbx"
Config Scl = Portc.0
Config Sda = Portc.1
I2cinit
Config Twi = 100000
$eepromsize = &H8000
$lib "fm24c64_256.lib"
'-------------------------------------------------------------------------------
Dim Eb As Eram Byte
Dim B As Byte
Dim C As Byte
B = 135
Eb = B
Waitms 10
C = Eb
'-------------------------------------------------------------------------------
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'------------------------------------------------------------------------------- |
resault:
start
b=135
eb=135
so $eeprom size work fine with hardware i2c also |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 11:28 am Post subject: |
|
|
in test 3 if i disconnect chip from uc the resault is:
start
it mean uc wait for resopone from chip in a loop
------------------------------------------------------
in test 4 if i disconnect chip from uc the resault is:
start
b=135
eb=161
it mean that without any error , uc return a wrong value!
------------------------------------------------------------
all test done by atmel at24c08 |
|
Back to top |
|
|
karlos
Joined: 03 Apr 2015 Posts: 107
|
Posted: Fri Jul 01, 2016 12:00 pm Post subject: |
|
|
test 5:
Code: | $regfile = "m128def.dat"
$crystal = 12000000
$hwstack = 256
$swstack = 256
$framesize = 256
'-------------------------------------------------------------------------------
Open "comd.6:9600,8,n,1" For Output As #1
Print #1 , "start"
'---------------------------At24c08 configuration-------------------------------
'Config I2cdelay = 17
$lib "i2c_extended.lib"
$eepromsize = &H1000
$lib "fm24c16.lib"
Config Scl = Portg.0
Config Sda = Portg.1
I2cinit
'-------------------------------------------------------------------------------
Dim Eb As Eram Byte
Dim B As Byte
Dim C As Byte
B = 135
Eb = B
Waitus 250
C = Eb
'-------------------------------------------------------------------------------
Print #1 , "b=" ; B
Print #1 , "eb=" ; C
End
'-------------------------------------------------------------------------------
|
the resault when chip connected:
start
b=135
eb=135
the resault when chip disconnected:
start
b=135
eb=255
so it work fine also!
but most important thing that should be considered is that :
1-minimum 220 us needed wait between writing and reeding, i insert 250 us for sure, if you delete waitus 250 from program,you will see that returned value is wrong!
i am sure that Mark can san say me to polling some bit to be sure of completing writing.
or may be better that it combine with the codes that run in behind with $eepromsize directive, for more Reliablty and safety.
2-if i put Config I2cdelay = x and x be less than 17 the writing will be wrong! while in help mentiond that defalut is 5, but if i delete this command,it work fine!
if i delete it, it would refer to default value of 5, but it work!
and if i put it with value of less than 17, it dont work
thanks a lot Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Jul 01, 2016 12:22 pm Post subject: |
|
|
you need to understand that the lib is for a RAMTRON FRAM chip. This chip has no delay. It is like RAM but then non volatile. A super chip if you ask me.
The normal i2c eeprom REQUIRES a delay after each write. So you either need to alter/fork the lib and add some delay or add it in your code. _________________ Mark |
|
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
|
|