I2C - TPL0401A

02 Feb 2013

Hello,

I am trying to interface with a TPL0401A potentiometer using I2C.

#include "mbed.h"
 
I2C i2c(p9, p10);        // sda, scl
Serial pc(USBTX, USBRX); // tx, rx

int main() {

    pc.printf("starting...\r\n");
    int a;
        
    while(1){
        i2c.start();
        i2c.write(0x5c);
        wait(0.02);

        i2c.read(a);
        pc.printf("%d\r\n",a);
        wait(0.02);
        
        i2c.write(0x45);    
        
        wait(0.02);
        
        i2c.read(a);
        pc.printf("%d\r\n",a);
        
        i2c.stop();
        
        wait(1);
    }
    
  
}

I always get 0 as an ack. It is the first time a use the I2C interface and I was just wondering if I use it in a proper way. Here is the tram:

/media/uploads/RFID/doc.png

thanks.