I2C for ESC

04 Aug 2010

Dear All,

I want to control my I2C ESC from my mbed uC. Before I use mbed, I use ATmega uC. This is my AVR code to drive the ESC:

// Make actual write to I2C bus
    Wire.beginTransmission(0x28 + 3);   // transmit to device ADDRESS
    Wire.send(30);             // sends one byte command
    Wire.endTransmission();               // stop transmitting
I try to replace that task by mbed using this code:

#include "mbed.h"

I2C i2c(p9, p10);

int const addr = 0x31; //address of ESC

int main() {
    char bl_1[2];
    
    while(1) {
        bl_1[0] = 0x00;
        bl_1[1] = 30;
        i2c.write(addr, bl_1, 2);        
        wait(0.05);    
    }
}
But it is not works...

Please help me, is there anything wrong with the code??

 

Thank you,

Raharja

04 Aug 2010

I am not familliar with AVR but you might be using the wrong address. In the original code, the address you are using is 0x28 + 3. In the new code, you using the address 0x31.

The 0x prefix in a constant tells us (and the compiler) that the number is represented in hexadecimal (or base 16). The digits for hex range from 0 to F (10 being A, F being 15).

So, (0x28 + 3) is 0x2B in hex or 43 in decimal. You are sending to 0x31 which represents the value 49 in decimal.

To fix this, you can leave the address as (0x28 + 3) in the new code. You can also use 0x2B (hex) or 43 (decimal).

I hope that helps!

05 Aug 2010

Owh.. yeah.

I know it's a mistake, but actually I already try to do so (int const addr = 0x28 + 1), and so also after read your reply I tried to write 0x2B in the address.

but it is still not works.


05 Aug 2010

Hi Raharja,

Also, in your first example you are sending 1 byte to that address, yet on the mbed version you are sending 2 bytes (an extra 0x00 first). That may be the other problem.

I guess your device may also not be connected properly. You could try this pogram to search what is on the bus:

Simon

06 Aug 2010

Hi Simon,

 

Thanks a lot, your code is helpful and finally I found the correct address.

 

Raharja