I2C write failed

11 Dec 2009

Hi,

I want to use I2C write data for controling TDA7418-3 Band car audio procesor, I can use I2CU test program find device address 0x88,

Test program is below.

int count = 0;
for (int address=0x00; address<256; address+=2) {
//int a=i2c.write(address,NULL,0);
if (!i2c.write(address,NULL,0)) { // 0 returned is ok
printf(" - I2C device found at address 0x%x\n", address);
count++;
}
}
printf("%d devices found\n", count);

 

But when I change "NULL" to the code below in my program.

char buf[2];

buf[0]=0x8d;  //register address ,test mode

buf[1]=0x12;  //data

if(!i2c.write(0x88,buf,2)){

printf(" write success");

}else{

printf("write failed");

}

When I execute my program, print failed message "write failed".

I don't know what's wrong.

Please help me.

Thanks,

zhenjiang

 

13 Dec 2009

I don't have a TDA7418 to double check. I had a look a the spec sheet and values you are writing look ok, and the  I2C write( ) call looks fine to me (not sure about the 0x12 though). As you haven't posted the complete code I suggest you double you are using the correct pins (its likely they are correct), and try ensuring your are using a clock frequency of 100kHz (i2c.frequency(100000);), as the mbed documentation doesn't cover the default frequency. If that doesn't work, try a slower clock (the TDA7418 also doesn't mention if this a regular or fast I2C device, etc). At worst the TDA7418 designers are expecting hand crafted I2C assembler to wait more time for each ACK. If you have access to Bus Pirate or a PICKit serial analyser, try that.

Petras

13 Dec 2009

And I forgot to mention: from the mbed handbook "All drivers on the I2C bus are required to be open collector, and so it is necessary for pull up resistors to be used on the two signals. A typical value for the pullup resistors is around 2.2k ohms."

Petras

05 Jul 2010

Iv

You need to programm all control bytes for the first time, like this:

   I2caddr = &H88                                            'address
   I2cdata(1) = &H20                                        'REG0 AUTO INC
   I2cdata(2) = &H01                                        '0-INPUT SELECTOR
   I2cdata(3) = &H80                                        '1-LOUDNESS OFF
   I2cdata(4) = &H80                                        '2-*VOLUME 0DB
   I2cdata(5) = &HCF                                        '3-TREBLE CENTER 15KHZ, 0DB
   I2cdata(6) = &HCF                                        '4-MIDDLE Q=1 0DB
   I2cdata(7) = &H8F                                        '5-BASS Q=1 0DB
   I2cdata(8) = &H0E                                        '6-BASS 200HZ MIDDLE 1,5KHZ
   I2cdata(9) = &HA0                                        '7-*  LEFT FRONT
   I2cdata(10) = &HA0                                       '8-*  LEFT REAR
   I2cdata(11) = &HA0                                       '9-*  RIGHT REAR
   I2cdata(12) = &HA0                                       '10-* RIGHT FRONT
   I2cdata(13) = &H80                                       '11-* SUBWOOFER
   I2cdata(14) = &H01                                       '12-SOFT MUTE SOFT STEP OFF
   I2cdata(15) = &H00                                       '13-IN OPERATION

   I2cstart
   I2csend I2caddr , I2cdata(1) , 15                        'PGM CHIP
   I2cstop

This is a BASCOM sample, but I used this sequence and is working fine

Harald