CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Read i2c bytes

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zulander_
Guest







Read i2c bytes
PostPosted: Mon Dec 04, 2006 4:08 pm     Reply with quote

Hi,
I am having problem reading an IC sending 8 bytes. I don�t know how I can read all those byte. is this how:

static void read_is(){
int byte0,byte1,byte2,byte3;
i2c_start();
i2c_write(0b11000001);
i2c_write(0x81);
byte0=i2c_read(0);
byte1=i2c_read(1);
byte2=i2c_read(2);
byte3=i2c_read(3);
//etc
printf("msg: TMC REPONSE: %x, %x , %x , %x \r\n", byte0,byte1,byte2,byte3);
i2c_stop();
}

i don't think this is the right way becuase iam getting the same value for all those variable..
thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 04, 2006 4:37 pm     Reply with quote

Your parameters for i2c_read() are wrong.

Post the manufacturer and part number of the i2c device that
you're trying to read from.
Zulander_
Guest







TMC222
PostPosted: Mon Dec 04, 2006 4:53 pm     Reply with quote

It is a Stepper motor contoller :
You can find the spec sheet AT:
avrcard.com/Documents/datasheets/tmc222.pdf
Zulander



Joined: 04 Dec 2006
Posts: 14

View user's profile Send private message

PIC
PostPosted: Mon Dec 04, 2006 8:16 pm     Reply with quote

This is my screen shot of the control setting that i am going to be reading the 8 bytes of data:

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 05, 2006 2:05 am     Reply with quote

You need to do a read operation. The TMC222 data sheet shows how
to do this in Figure 20, on page 27. Look at the following code and
see how it follows the diagrams in the data sheet.
Quote:

i2c_start();
i2c_write(0xC0);
i2c_write(0x81);
i2c_stop();

i2c_start();
i2c_write(0xC1);
byte0=i2c_read();
byte1=i2c_read();
byte2=i2c_read();
byte3=i2c_read();
byte4=i2c_read();
byte5=i2c_read();
byte6=i2c_read();
byte7=i2c_read(0);
i2c_stop();

Normally the i2c_stop() that's shown in bold above, is not included
in a read operation. For example, EEPROMs don't require it.
But this data sheet says to do it, so you should at least try it their way.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 05, 2006 9:06 am     Reply with quote

Also the I2C address might not be what you think. The spec talks about only having one device on the I2c chain and then "Programming" 2 of the address bits. Kind of a interesting way of doing it. But it might be causing troubles.

What simple "read" can you do that will be a know value? to check that the
I2C address is what you think?
Do you have your pull-ups on sda,scl?
Is this the only chip on the I2C bus?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
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


Powered by phpBB © 2001, 2005 phpBB Group