First you need to enable I2C to your MCU, and these additional options:
CONFIG_I2C=y
CONFIG_I2C_DRIVER=y
CONFIG_SYSTEM_I2CTOOL=y
CONFIG_I2CTOOL_MINBUS=0
CONFIG_I2CTOOL_MAXBUS=5
CONFIG_I2CTOOL_MINADDR=0x03
CONFIG_I2CTOOL_MAXADDR=0x77
CONFIG_I2CTOOL_MAXREGADDR=0xff
CONFIG_I2CTOOL_DEFFREQ=400000
Also in your board initialization you need to register the right I2C Bus you want to use. For example, I want to use the I2C Bus 3:
rtcinfo("Initialize I2C%d\n", 3);
i2c = sam_i2c_master_initialize(3);
if (!i2c)
{
rtcerr("ERROR: Failed to initialize I2C%d\n", 3);
return -ENODEV;
}
/* Register the I2C to get the "nsh> i2c bus" command working */
ret = i2c_register(i2c, 3);
if (ret < 0)
{
rtcerr("ERROR: Failed to register I2C%d driver: %d\n", bus, ret);
return -ENODEV;
}
If everything compiled fine you will have:
nsh> i2c bus
BUS EXISTS?
Bus 0: NO
Bus 1: NO
Bus 2: NO
Bus 3: YES
Bus 4: NO
Bus 5: NO
nsh>
nsh> i2c dev -b 3 0x00 0x77 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f 70: -- -- -- -- -- -- -- -- nsh>
These two addresses are the EEPROM (0x50) and the RTC (0x6f) that I have on my board.