I2C write error

01 Oct 2010

I am a hardware guy and C++ totally confuses me. I know this is a stupid question but it looks like my i2c.write is the same as one of the examples but I get this compiler error???

"No instance of overloaded function "mbed::I2C::write" matches the argument list (E304)" in file "/ACTester2/main.cpp"

"      i2c1.write(0x70,i2c1_data,2); (E0)" in file "/ACTester2/main.cpp"

"           ^ (E0)" in file "/ACTester2/main.cpp"

#include "mbed.h"
AnalogOut dac(p18);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
Serial pc(USBTX, USBRX);
I2C i2c1(p9, p10);
I2C i2c2(p28, p29);
unsigned char i2c1_data[8], i2c2_data[8];
unsigned int dac_value;
int main() {
    i2c1.frequency(100000);              //set I2C interface 1 to 100 Khz
    i2c2.frequency(400000);              //set I2C interface 2 to 400 Khz
    i2c1_data[0] = 0x00;
    i2c1_data[1] = 0xFF;   
    i2c1.write(0x70,i2c1_data,2);    
    dac_value = 0;    
    while(1)
     {
        led1 = 1;
        wait(0.2);
        led1 = 0;
        wait(0.2);
        led2 = 1;
        wait(0.2);
        led2 = 0;
        wait(0.2);
        led3 = 1;
        wait(0.2);
        led3 = 0;
        wait(0.2);
        led4 = 1;
        wait(0.2);
        led4 = 0;
        wait(0.2);
        if(dac_value < 0xFFFF)
            {
            dac.write_u16(dac_value);
            dac_value += 0x1000;
            }
        else
            dac_value = 0;
        pc.printf("dac_value  %4x\n\r", dac_value);
        
        
    }
}

 

01 Oct 2010

I2C::write() expects char * while you're trying to pass an unsigned char *. Either add a cast to char * or change the definition of i2c1_data.

01 Oct 2010

That fixed it.  THANKS!