cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I'm using STM32L031K6 (Nucleo) and I'm trying to read register on ICM-20948 via I2C but it seems like the master never sends the write bit at the end of the address byte.

YBCH.1
Associate II

0693W00000FAxQwQAL.pngI 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

1 ACCEPTED SOLUTION

Accepted Solutions
YBCH.1
Associate II

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).

View solution in original post

2 REPLIES 2
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
YBCH.1
Associate II

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).