Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

i2c commands

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
dongags5

Bascom Member



Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

australia.gif
PostPosted: Sat May 28, 2005 1:16 pm    Post subject: i2c commands Reply with quote

Sad 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
View user's profile
mr_nanick

Bascom Member



Joined: 28 May 2005
Posts: 4

PostPosted: Sat May 28, 2005 4:52 pm    Post subject: Reply with quote

try an other eeprom!
the 25lc256 seems to be an spi eeprom. this will never work.

regards.
Back to top
View user's profile
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Sat May 28, 2005 7:05 pm    Post subject: Reply with quote

This is correct. The 25 series are SPI while the 24 series are I2C.
Back to top
View user's profile Yahoo Messenger
dongags5

Bascom Member



Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

australia.gif
PostPosted: Sun May 29, 2005 1:56 am    Post subject: Reply with quote

Embarassed 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
View user's profile
mr_nanick

Bascom Member



Joined: 28 May 2005
Posts: 4

PostPosted: Sun May 29, 2005 8:05 am    Post subject: Reply with quote

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 Wink

good luck.
Back to top
View user's profile
dongags5

Bascom Member



Joined: 02 May 2005
Posts: 108
Location: Melbourne Australia

australia.gif
PostPosted: Sun May 29, 2005 9:48 am    Post subject: Reply with quote

Confused 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
View user's profile
mr_nanick

Bascom Member



Joined: 28 May 2005
Posts: 4

PostPosted: Sun May 29, 2005 2:43 pm    Post subject: Reply with quote

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
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 938
Location: France

france.gif
PostPosted: Wed Jun 01, 2005 6:25 pm    Post subject: Reply with quote

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 Very Happy
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
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 938
Location: France

france.gif
PostPosted: Wed Jun 01, 2005 6:37 pm    Post subject: Reply with quote

I'm looking for in the forum "I2C" and I see "Bojan" as the same problem

Yes it is a bug Shocked

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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