View previous topic :: View next topic |
Author |
Message |
dongags5
Joined: 02 May 2005 Posts: 108 Location: Melbourne Australia
|
Posted: Sat May 28, 2005 1:16 pm Post subject: i2c commands |
|
|
I am having a lot of difficulty trying to use the i2c commands, i2csend and i2creceive. The code below should enable me to see a print of 5 but instead I get 255. Their is no error according to the print. I am using an eeprom type 25lc256 as the target i2c device with the address pins a0, a1 and a2 all grounded. I also have difficulty understanding what happens with multiple writes and reads as there is no obvious method shown how the eeprom storage locations are incremented or decremented. Should I be using the i2cwbyte and i2crbyte commands instead. My application is to record a number of temperature readings in the eeprom memory.Thanks in anticipation of a reply.
Dim X As Byte
Const Slavet = &HA0 'slave address of EEPROM IC send
Const Slaver = &HA1 'slave address of EEPROM IC receive
X = 5 'assign variable to 5
I2csend Slavet , X 'send the value
If Err = 0 Then Print "Write is good"
X = 0 'reset variable
I2creceive Slaver , X 'get the value
If Err = 0 Then Print "Read is good"
Print X 'print it
End |
|
Back to top |
|
|
mr_nanick
Joined: 28 May 2005 Posts: 4
|
Posted: Sat May 28, 2005 4:52 pm Post subject: |
|
|
try an other eeprom!
the 25lc256 seems to be an spi eeprom. this will never work.
regards. |
|
Back to top |
|
|
DToolan
Joined: 14 Aug 2004 Posts: 1384 Location: Dallas / Fort Worth, Texas (USA)
|
Posted: Sat May 28, 2005 7:05 pm Post subject: |
|
|
This is correct. The 25 series are SPI while the 24 series are I2C. |
|
Back to top |
|
|
dongags5
Joined: 02 May 2005 Posts: 108 Location: Melbourne Australia
|
Posted: Sun May 29, 2005 1:56 am Post subject: |
|
|
Sorry, I realised that my eeprom was 24lc256 and not 25lc256....how embarrassing! So the questions asked are still valid.....I hope you'll forgive me and help......please. |
|
Back to top |
|
|
mr_nanick
Joined: 28 May 2005 Posts: 4
|
Posted: Sun May 29, 2005 8:05 am Post subject: |
|
|
hello
dont forgive the datasheet, page 7 you have the sequence to write a byte at a specific address.
try this: (to write a value at address 0 of the eeprom)
i2cstart
i2cwbyte slavet ; slave address
i2cwbyte 0 'address high byte
i2cwbyte 0 'adress low byte
i2cwbyte X 'value to write
i2cstop
waitms 10 ' needed time to write the value
read the current address ' datasheet page 9
I2creceive Slaver , X 'get the value
read a specific address
i2cstart
i2cwbyte slavet ; slave address
i2cwbyte 0 'address high byte
i2cwbyte 0 'adress low byte
i2cstart 'start again
i2cwbyte slaver ' to read the value
i2crbyte x,nack ' end of reading
i2cstop
note that i just discover bascomavr and i'm not sure of the command use.
oh , there i2c.bas in the sample code
good luck. |
|
Back to top |
|
|
dongags5
Joined: 02 May 2005 Posts: 108 Location: Melbourne Australia
|
Posted: Sun May 29, 2005 9:48 am Post subject: |
|
|
Thanks Mr_Nanick but I was really trying to get the commands i2csend and 12creceive to work.
In your sample code, the high and low bytes for the desired address appear to be achieved by repeating the command i2cwbyte 0 followed by another i2cwbyte for the data to be written to this address. How does it differentiate between them?
Don |
|
Back to top |
|
|
mr_nanick
Joined: 28 May 2005 Posts: 4
|
Posted: Sun May 29, 2005 2:43 pm Post subject: |
|
|
i think that i2csend and i2creceive are not usefull here, because you have to specifiate a slave address :
i2csend slave_address, var_to_send
or
i2csend slave_address, var_to_send ,Number_of_byte_to_send
off course if you have a i/o interface like pcf8574 it's very usefull to r/w
the port
i2csend pcf8574_addr, value ; same with i2creceive
the help of bascom is very usefull, dont forgive it.
mr_nanick |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Jun 01, 2005 6:25 pm Post subject: |
|
|
Hi,
I just have the same problem : with the norwal way, see the AN 201 about I2C for AVR
I did a program using an 24C64 with version 1.11.7.4 and everything was allright.
when I transferted it without compilation (same xxx.bin) it was still ok
when I compiled it with 1.11.7.7, I have the same results as you : no error but 255
I save the I2C.lib and I install the old one then everything is perfect
I sent a mail to Mark yesterday about this PB
If you don't have the old .lib I will send you.
Bon courage
JP _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Jun 01, 2005 6:37 pm Post subject: |
|
|
I'm looking for in the forum "I2C" and I see "Bojan" as the same problem
Yes it is a bug _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
|