10 years, 10 months ago.

impossible to write on i2c bus

Hello everybody,

I have to control a DTC PE64905 (digital tuned capacitor) with the LPC1768. I have to use the i2c bus, but there is nothing coming out from the pin i'm using. It is the first i use a mbed and i'm a little bit lost... Is it my code wrong ? or something's missing ?

Any help please :)

Here is my code :

  1. include "mbed.h"

DigitalOut led2(LED2); I2C i2c( p9, p10 ); sda, scl

const int addr = 0x71; DTC address

int main() {

char data [5] = {0x00, 0x01, 0x02, 0x17, 0x1F}; different values of the capacitor

led2 =1;

wait_ms(500);

while(1){

led2=0;

i2c.write(addr, data, 5);

led2=1; }

}

1 Answer

10 years, 10 months ago.

Make sure you have pull-up Resistors on the I2C SDA and SCL lines or the bus wont work and mbed will hang.

Did you check the I2C address. The mbed libs use the 8-bit format. Some datasheets provide the address in 7bit and it needs to be shifted left by one bit. The address you give (0x71) looks like a 7 bit address format.

Thank you Wim. I've got two pull up resistors of 2.2k on the two lines as said in the handbook(or cookbook) i'll try to shift the adress..

posted by Loic Belleguie 19 Jun 2013

I looked up the datasheet. Fig 16 confirms that the PE64905 I2C slaveaddress for the mbed libs should be 0xE0 or 0xE2 depending on the logic level of the addresspin (pin 6, ADDR) on the PE64905.

posted by Wim Huiskamp 19 Jun 2013

thanks for your help ! but i've got another problem the pe64905 always sends back the ack bit on a high state. I've tried the 2 different adresses with the corresponding logic level on the adress pin and there is nothing to do i always have the ack bit at '1' this is my piece of code :

  1. include"mbed.h"

I2C i2c(p28, p27); sda (data), scl(clk) const int addr = 0xE2; DTC address left shifted by 1bit (R/W bit). Initial address is 0x71

int main() {

i2c.frequency(40000); Set the clock frequency char data = 0x1F; data : 0x1F <=> C = 5pF char data [1]= {0x1F}; different values of the capacitor

while(1){ i2c.start();

i2c.write(addr); i2c.write(data); i2c.write(addr,data,2); doesn't work

i2c.stop(); } }

thanks again for your help :)

posted by Loic Belleguie 21 Jun 2013

Quote:

thanks for your help ! but i've got another problem the pe64905 always sends back the ack bit on a high state. I've tried the 2 different adresses with the corresponding logic level on the adress pin and there is nothing to do i always have the ack bit at '1' this is my piece of code

Please use the <<code>> and <</code>> brackets around you posted code to make it readable

#include"mbed.h" 

I2C i2c(p28, p27); //sda (data), scl(clk)
const int addr = 0xE2; //DTC address left shifted by 1bit (R/W bit). Initial address is 0x71
 
int main() {
 
i2c.frequency(40000); //Set the clock frequency
char data = 0x1F; //data : 0x1F <=> C = 5pF
char data [1]= {0x1F}; //different values of the capacitor
 
while(1)
{
  i2c.start();
  i2c.write(addr);
  i2c.write(data); 
  i2c.write(addr,data,2); //doesn't work 
  i2c.stop();
 }

}
 

It is not clear what code you actually used because of the missing comment when you post without the <<code>> brackets.

Some issues in code:

i2c frequency should probably be at 100000 or 400000. Check datasheet for your slavedevice

i2c.write(addr,data,2); //doesn't work 

This method expects a data array with at least 2 elements since you try to send 2 bytes. This method also includes an I2C start and stop. You dont need to generate these separately.

Either use

i2c.start();
i2c.write(addr);
i2c.write(data);
i2c.stop();

or use

i2c.write(addr,data,2); 

Ack bit at 1 means the slave does not respond. Could be missing supply voltage, missing GND, SDA/SCL mixed up or wrong slaveaddress.

posted by Wim Huiskamp 21 Jun 2013