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

const int addr = 0x2E; // define the I2C Address
 
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(0);
        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);
    }
    
/*
    pc.printf("starting...\r\n");
    char cmd[1];
    while(1) {
        cmd[0] = 0x60;
        int a = i2c.write(addr, cmd, 1);
        wait(0.07);        
        printf("%d",a);
        wait(0.1);
    }
*/
  
}

I always get 0 as an ack. I was just wondering if I using the I2C interface in a proper way. Here the tram:

/media/uploads/RFID/doc.png

thanks.