I2C write problem !

02 Sep 2009

#include "mbed.h"

I2C i2c(28, 27);
Serial pc(USBTX, USBRX);

const int write_addr=0xC4;    // write_addr is chip address , include a write operation bit
const int read_addr=0xC5;

char addr[2]= {0x00,0x8B};    //addr[0]  is register address and addr[1]  is command

int main() {

    pc.printf("Program Begin ...\n");  // can execute
    i2c.write(write_addr,addr,1);       // can not execute !!!   Why ?

}

 

Could you tell me  why write operation can not execute  ?

and sometime happen errors:

     I2C start W returned incorrect status (0x20) in I2C::write

     SIGABRT: Abnormal termination

Why ?

 

 

 

02 Sep 2009

Hi,

The problem is probably because the library will automatically shift the addrss you supply left by one place, and insert the appropriate bit for read/write.

Try using the address 0x72 in both your read and write calls.

0x72 << 1 = 0xC4, this will be ORed with 0x1 within the library for the read function.

Hope that helps.

Chris

 

02 Sep 2009

The problem is probably because the library will automatically shift the addrss you supply left by one place, and insert the appropriate bit for read/write.

Try using the address 0x72 in both your read and write calls.

0x72 << 1 = 0xC4, this will be ORed with 0x1 within the library for the read function.

I think this should probably be 0x62, not 0x72

 

02 Sep 2009

Hello,Chris

I have tried using the address 0x72 in both read and write calls, but it can not execute .

This is my chip information below, please look at

My chip is TDA7541  which is used to AM/FM radio .

Micro system software communicates with tuner by I2C bus protocol as below.

W: 0xC4
R: 0xC5

Write Operation
S   1 1 0 0 0 1 D 0   ACK   0 0 I A4 A3 A2 A1 A0   ACK   Data Byte   ACK   P
Read Operation
S   1 1 0 0 0 1 D 1   ACK   S7 S6 S5 S4 S3 S2 S1 S0   ACK   P
S = Start
P = Stop
ACK = Acknowledge
D = Device address
I = Auto increment mode
A = Sub address
Sx=Read
Be noted that the register 0~29 can only be written but can’t read back data from these
registers by micro-controller. What can be read back from tuner is only a status byte

Thanks

lv zhenjiang