Hello,
I am using the I2C Motor Driver from Grove and I am experiencing issues while I try to write data.
I am using this function:
int I2C_write_bytes(uint8_t addr, uint8_t reg, uint8_t length, uint8_t *data)
{
int res = 0;
int i2c_fd = open(I2C_BUS_DEV_PATH, O_RDWR);
/*******************************CHECK******************************/
if (i2c_fd < 0)
{
LE_ERROR("I2C_write_bytes() failed to open %s | Error: %m\n", I2C_BUS_DEV_PATH);
close(i2c_fd);
return -1;
}
/******************************************************************/
LE_INFO("I2C_write_bytes() succeed to open %s\n", I2C_BUS_DEV_PATH);
/*******************************CHECK******************************/
if (ioctl(i2c_fd, I2C_SLAVE_FORCE, addr) < 0)
{
LE_ERROR("I2C_write_bytes() could not set address to 0x%02x: %m", addr);
close(i2c_fd);
return -1;
}
/******************************************************************/
LE_INFO("I2C_write_byte() succeed to set address 0x%02X\n", addr);
res = i2c_smbus_write_i2c_block_data(i2c_fd, reg, length, data);
/*******************************CHECK******************************/
if (res < 0)
{
LE_ERROR("I2C_write_bytes() failed to write | Error: %m\n");
}
else
{
LE_INFO("I2C_write_bytes() succeed to write\n");
}
/******************************************************************/
close(i2c_fd);
return res;
}
I can open the i2c-5 file and send the ioctl command but when I am writing I get this error:
Transport endpoint is not connected
I don’t really know why this isn’t working because I used this function before and the operation to write was successful:
int i2c_hub_select_port(uint8_t hub_address, uint8_t port)
{
int res = 0;
int i2c_fd = open(I2C_BUS_DEV_PATH, O_RDWR);
/*******************************CHECK******************************/
if (i2c_fd < 0)
{
LE_ERROR("i2c_hub_select_port() failed to open %s | Error: %m\n", I2C_BUS_DEV_PATH);
close(i2c_fd);
return -1;
}
/******************************************************************/
LE_INFO("i2c_hub_select_port() succeed to open %s\n", I2C_BUS_DEV_PATH);
/*******************************CHECK******************************/
if (ioctl(i2c_fd, I2C_SLAVE_FORCE, hub_address) < 0)
{
LE_ERROR("i2c_hub_select_port() could not set address to 0x%02X | Error: %m\n", hub_address);
close(i2c_fd);
return -1;
}
/******************************************************************/
LE_INFO("i2c_hub_select_port() succeed to set address 0x%02X\n", hub_address);
int writeResult = i2c_smbus_write_byte(i2c_fd, port);
/*******************************CHECK******************************/
if (writeResult < 0)
{
LE_ERROR("i2c_hub_select_port() failed to write | Error: %m\n");
res = -1;
}
else
{
LE_INFO("i2c_hub_select_port() succeed to write 0x%02X\n", port);
res = 0;
}
/******************************************************************/
close(i2c_fd);
return res;
}
Here is the i2cdetect
:
root@swi-mdm9x28-wp:~# i2cdetect -y -r 5
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- 04 05 06 07 -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- UU -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- UU -- -- -- -- -- --
Can you help me?
Thank you!