View previous topic :: View next topic |
Author |
Message |
balou
Joined: 14 Apr 2007 Posts: 36
|
Posted: Sat Nov 28, 2020 3:38 pm Post subject: Eeprom AT24C32 problem |
|
|
Want to write and read Eeprom AT24C32 from RTC Module DS3231.
Address AT24C32 = HA6, read with I2C Locator.
The output is 255,255,255,255,74.255,255,255,82,255,255
I can't manage with the attached program.
What am I doing wrong ?
'****************************************************
'********* Adress AT24C32 = &HA6 / 174 *************
'******** Address of DS3231 = &D0 / 208 ************
'****************************************************
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 150
$swstack = 150
$framesize = 150
$baud = 9600
'********** Config I2C SD1306*****************************
Config Scl = Portb.0
Config Sda = Portb.1
Config Twi = 100000
Config I2cdelay = 10
I2cinit
'********************* Config Bluetooth ****************
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 254
Config Serialout = Buffered , Size = 254
Enable Interrupts '** Bluetooth **
'************** Variable *************************
Dim X As Byte
Dim Address_mem As Byte
Dim R_eepr As Byte
Const At24c32w = &HA6 '** Address AT24C32 * &HA6 **
Const At24c32r = &HA7 '** Address AT24C32 * &HA7 **
'************************** Version *********************
Print Version(1)
Print Version(3)
Print "Bleutooth"
Wait 1
'*************** Program **********************
'****** Write AT24C32 *****
For Address_mem = 0 To 10
I2cstart '** Start I2C
I2cwbyte At24c32w '** Slave Address &HAE
I2cwbyte Address_mem '** Write address to EEprom
I2cwbyte 1
I2cstop
Waitms 100
Next
''****** Read AT24C32 *****
For Address_mem = 0 To 10
X = X + 1
I2cstart '** start I2C
I2cwbyte At24c32w '** Slave Address &HAE
I2cwbyte Address_mem
I2cstart
I2cwbyte At24c32r '** Slave Address + 1 &HAF
I2crbyte R_eepr , Nack '** Read Adresse from EEprom
I2cstop
Print "Read EEprom = " ; X ; " : " ; R_eepr ; " "
Waitms 100
Next
End
(BASCOM-AVR version : 2.0.8.3 ) _________________ Bascom-AVR 2.0.8.5 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Nov 28, 2020 8:07 pm Post subject: |
|
|
The 24c32 does not expect a one byte address. |
|
Back to top |
|
|
balou
Joined: 14 Apr 2007 Posts: 36
|
Posted: Sat Nov 28, 2020 8:50 pm Post subject: |
|
|
I am a new one in Bascom.
What do you mean with one byte address.
Balou _________________ Bascom-AVR 2.0.8.5 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Nov 28, 2020 9:08 pm Post subject: |
|
|
balou wrote: | I am a new one in Bascom. |
Hasn't to do with Bascom, but with the memory chip you use.
I suggest to read the datasheet.
Isn't there a working sample for this chip in the Bascom samples folder?
Quote: | What do you mean with one byte address. |
You send a one byte address to a chip which holds at minimum 4096 bytes.
To address 4096 memory cells a byte of 256 isn't enough, didn't this become obvious to you? |
|
Back to top |
|
|
balou
Joined: 14 Apr 2007 Posts: 36
|
Posted: Sun Nov 29, 2020 12:41 pm Post subject: |
|
|
Solution found on the internet.
Balou. _________________ Bascom-AVR 2.0.8.5 |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Sun Nov 29, 2020 4:49 pm Post subject: |
|
|
Hi balou
when you find a solution to your question, it's nice to post this solution so that other participants can benefit from it.
thank you.
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Nov 29, 2020 6:57 pm Post subject: |
|
|
Duval JP wrote: | when you find a solution to your question, it's nice to post this solution so that other participants can benefit from it.
thank you. |
I will answer it, as the TOs answer:
Quote: | Solution found on the internet. |
shows he is snotty because I gave him hints to use his own brain, instead of a pre-chewed solution.
The AT24C32 is a 4096x8Bit EEProm, to address 4096 memory cells, it needs a word- and not a byte-address, as described in the data sheet.
Here's part of the TOs code:
Code: | Dim Address_mem As Byte
' ...
I2cstart '** Start I2C
I2cwbyte At24c32w '** Slave Address &HAE
I2cwbyte Address_mem '** Write address to EEprom
I2cwbyte 1
I2cstop |
The TO defined only a byte (Address_mem) for the address, while the EEProm expects first an MSByte and then a LSByte.
Thus the EEProm took the following data value of '1' for the lower address byte.
But instead of receiving actual data then, it received a I2cstop, of course the result was garbage.
Here is an excerpt of ...\MCS Electronics\BASCAVR2082\Samples\I2C\I2C.BAS:
Code: | ' when you want to control a chip with a larger memory like the 24c64 it requires an additional byte
' to be sent (consult the datasheet):
' Wires from the I2C address that are not connected will default to 0 in most cases!
' I2cstart 'start condition
' I2cwbyte &B1010_0000 'slave address
' I2cwbyte H 'high address
' I2cwbyte L 'low address
' I2cwbyte Value 'value to write
' I2cstop 'stop condition
' Waitms 10 |
Also this hint to look up the Bascom samples was ignored.
Even talking with tongues of angels would not persuade a dulled mind. |
|
Back to top |
|
|
balou
Joined: 14 Apr 2007 Posts: 36
|
|
Back to top |
|
|
|