I am trying to learn how to write a driver using the datasheet for a component. Using MB85RC16 FRAM in this case. Datasheet = https://www.fujitsu.com/ca/en/Images/MB85RC16-DS501-00001-8v0-E.pdf - Page 9
I am able to write any address I want using HAL_I2C_Master_Transmit but can't get the reading back part to work without using HAL_I2C_Mem_Read.
The first four bits are fixed to 1010 and then the three bits are the device address configuration (000 in my case) resulting in 0x50 as the complete device address. This is then followed by the last eighth bit which is R/W.
Using HAL I write 0xCE to address 0x05.
uint8_t buff[10] = {0x05, 0xCE};
HAL_I2C_Master_Transmit(&hi2c1, (0x50 << 1), buff, 2, HAL_MAX_DELAY);
Then to read back I use the datasheet and first send 0x05 as the address to read from and try to use HAL_I2C_Master_Receive to complete the second part where I was hoping to read data back.
uint8_t buff2[1];
HAL_I2C_Master_Transmit(&hi2c1, (0x50 << 1), 0x05, 1, HAL_MAX_DELAY);
stat = HAL_I2C_Master_Receive(&hi2c1, (0x50 << 1) | 0x01, buff2, 1, 1000);
stat shows HAL_OK but I dont get 0xCE back in buff2. It just reads 0.
Could you please guide me what I am doing wrong because when I use HAL_I2C_Mem_Read like below it works fine.
HAL_I2C_Mem_Read(&hi2c1, (0x50 << 1) | 0x01, 0x05, 1, buff2, 1, 1000);
I tried using an oscilloscope I just havnt understood the differences between the Master_recieve signal and Mem_read signal yet.
Which STM32?
Third parameter is supposed to be pointer to data buffer, not a number. See description of this function in Cube's manual, or directly in the Cube/HAL sources:
Similarly, read description of HAL_I2C_Mem_Read() in the same sources and compare that to above description of HAL_I2C_Master_Transmit() to understand the difference.