2021-09-29 02:14 PM
I tried HAL_I2C_Master_Transmit, HAL_I2C_Master_Receive, HAL_I2C_Mem_Write, HAL_I2C_Mem_Read and even the DMA functions but nothing works - The 8th bit is always 0 and the ACK is always 1.
Due to the fact that I'm trying to read the WHO_AM_I value of a register 0x00 on device with address 0x68, I'm expecting write operation at the beginning, writing the value of the address of the internal register.
This is my function and printf should print 0xEA.
void I2C_readReg(uint16_t Slave_ADRS, uint8_t Reg_ADRS, uint16_t Size, uint8_t *pBufferRead)
{
uint8_t pBufferWrite[1];
uint16_t MovedAdrs = (uint16_t)(Slave_ADRS<<1);
HAL_I2C_Mem_Read(&hi2c1, MovedAdrs, (uint16_t)Reg_ADRS, (uint16_t)1, pBufferRead, (uint16_t)Size, (uint32_t)I2C_READ_TIMEOUT);
printf("val read %x \n\r", pBufferRead[0]);
}
Where's Slave_ADRS=0x68 and Reg_ADRS=0x00
Solved! Go to Solution.
2021-09-30 11:52 PM
Solved.
The problem was that I used pins PB6 and PB7 for I2C (which are the only two other pins for I2C on this MCU aside from PA9 and PA10 - the pins I'm using now) and apparently there's a limitations on these pins when it comes to I2C as mentioned in the comment (2) on the specific Nucleo's datasheet.
It's a poor design let the I2C be connected via single option only (let alone the fact these two pins also share the serial port of the board according to Arduino micro pinout).
2021-09-29 02:23 PM
HAL_I2C_Mem_Read first needs to write to set the memory address, then it will read. So on the first transaction, it should be write.
Your plot shows the chip does not ACK the first transaction, so the memory read attempt stops there and it never attempts a read transaction.
Since you're getting a NACK, there is a hardware problem. The signals look fine, so perhaps the slave address is incorrect, or the slave is misbehaving, or is unpowered, or is otherwise improperly wired.
Get it to work with HAL_I2C_IsDeviceReady first and ensure it returns HAL_OK, then move on to more complex operations.
2021-09-30 11:52 PM
Solved.
The problem was that I used pins PB6 and PB7 for I2C (which are the only two other pins for I2C on this MCU aside from PA9 and PA10 - the pins I'm using now) and apparently there's a limitations on these pins when it comes to I2C as mentioned in the comment (2) on the specific Nucleo's datasheet.
It's a poor design let the I2C be connected via single option only (let alone the fact these two pins also share the serial port of the board according to Arduino micro pinout).