If the HAL_I2C_Mem_Write function wasn't getting an acknowledgement back within the timeout period wouldn't it return a HAL_ERROR of some kind? It always returns HAL_OKAY. 0 Kudos Reply TDK Guru In response to EPala.2 2023-10-19 05:57 PM > It alw...
if (retval != 2) { printf("CMD_I2C_READ error!\n"); return -1; } if (data_width == 2) { data = buf[1] | (buf[0] << 8); } else { data = buf[0]; } } *val = (unsigned char)(data & 0xff); retval = 0; return retval; } 1. 2. 3. 4. 5. 6. 7. 8. 9....
hi2c->Mode = HAL_I2C_MODE_MEM; hi2c->ErrorCode = HAL_I2C_ERROR_NONE; /* Prepare transfer parameters */ hi2c->pBuffPtr = pData; hi2c->XferCount = Size; hi2c->XferSize = hi2c->XferCount; hi2c->XferOptions = I2C_NO_OPTION_FRAME; /* Send Slave Address and Memory Address */ ...
我看代码 有两种方式 一种是软件模拟IIC时序 一种是库函数IIC 跟你说的是一回事儿吗?
the starting address and read back the data does not work; the starting address can be sent correctly, but a stop condition will be inserted on the I2C bus before the read transaction is sent by the recv() command, so it does not get acknowledged and i2c.recv() exits with an error: ...
return HAL_ERROR; } 在调试中发现如果使用模拟IIC,可以与从机正常通信,但是使用硬件IICHAL库函数读取从机,超时返回HAL_ERROR,对比发现模拟IIC,管脚配置为推挽输出,硬件I2C则是开漏,所以在从机和主机都没有接上拉电阻的情况下,硬件I2C通信失败。 解决办法: ...