View previous topic :: View next topic |
Author |
Message |
Zulander_ Guest
|
Read i2c bytes |
Posted: Mon Dec 04, 2006 4:08 pm |
|
|
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
|
|
Posted: Mon Dec 04, 2006 4:37 pm |
|
|
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 |
Posted: Mon Dec 04, 2006 4:53 pm |
|
|
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
|
PIC |
Posted: Mon Dec 04, 2006 8:16 pm |
|
|
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
|
|
Posted: Tue Dec 05, 2006 2:05 am |
|
|
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
|
|
Posted: Tue Dec 05, 2006 9:06 am |
|
|
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? |
|
|
|