The I2C scanner code in arduino does not work right. The scanner code does this.
for (byte i = 1; i < 127; i++)
{
Wire.beginTransmission (i);
// Begin I2C transmission Address (i)
cnt = Wire.endTransmission ();
if ( cnt == 0) // Receive 0 = success (ACK response)
{
Serial.print (“Found address: “);
Serial.print (i, DEC);
Serial.print (” (0x”);
Serial.print (i, HEX);
Serial.println (“)”);
count++;
}
/////////////////////////////////////////////////
output on serial is
////////////////////////////////////////////////
I2C scanner. Scanning …
Found 0 device(s).
//////////////////////////////////////////////
I think because there is no write or read operation it fails. If I add a write then it works but finds a device at every address.
for (byte i = 1; i < 127; i++)
{
Wire.beginTransmission (i);
Wire.write(0xff);
cnt = Wire.endTransmission ();
if ( cnt == 0) // Receive 0 = success (ACK response)
{
Serial.print (“Found address: “);
Serial.print (i, DEC);
Serial.print (” (0x”);
Serial.print (i, HEX);
Serial.println (“)”);
count++;
}
///////////////////////////////////
output is this
/////////////////////////////////////
I2C scanner. Scanning …
Found address: 1 (0x1)
Found address: 2 (0x2)
Found address: 3 (0x3)
Found address: 4 (0x4)
Found address: 5 (0x5)
.
.
.
Found address: 121 (0x79)
Found address: 122 (0x7A)
Found address: 123 (0x7B)
Found address: 124 (0x7C)
Found address: 125 (0x7D)
Found address: 126 (0x7E)
Found 126 device(s).
I think the problem is here.
int32_t csi_iic_master_send(csi_iic_t *iic, uint32_t devaddr, const void *data, uint32_t size, uint32_t timeout, bool stop)
{
CSI_PARAM_CHK(iic, CSI_ERROR);
CSI_PARAM_CHK(data, CSI_ERROR);
csi_error_t ret = CSI_OK;
uint32_t timecount;
int32_t send_count = size;
uint8_t *send_data = (uint8_t *)data;
uint8_t iic_idx = HANDLE_DEV_IDX(iic);
dw_iic_regs_t *iic_base = (dw_iic_regs_t *)HANDLE_REG_BASE(iic);
// aos_mutex_lock(&iic_list[iic_idx].tx_mutex, AOS_WAIT_FOREVER);
//////////////////////////////////////////////////////////////////////////////////////////
//since size is 0 it fails. which it will be when
//Wire.beginTransmission (i);
//cnt = Wire.endTransmission ();
//is used.
////////////////////////////////////////////////////////////////////////
if (!send_data || !size) {
ret = CSI_ERROR;
goto SEND_ERROR;
}
/////////////////////////////////////////////////////////////////////
it does work in linux.
[root@milkv-duo]~# i2cdetect -r -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: – – – – – – – – – – – – –
10: – – – – – – – – – – – – – – – –
20: – – – – – – – – – – – – – – – –
30: – – – – – – – – – – – – – – – –
40: – – – – – – – – – – – – – – – –
50: – – – – – – – – – – – – – – – –
60: – – – – – – – – – – – – – – – –
70: 70 – – – – – – –
my i2c mux is at 0x70. This is right.