2022-11-11 11:42 AM
I´m trying read bytes from Adafruit I2C Non-Volatile FRAM Breakout module (ic MB85RC256V from FUJITSU) in my STM32F746IG custom board.
Using FW 1.16.2, I can read 512 bytes using HAL_I2C_Mem_Read_DMA.
Using FW 1.17.0, The I2C stops (clock pin goes down forever) after first attempt using this same command. The problem disappears in FW 1.17.0 if I read only 256 bytes. (code below)
Is it a bug in FW 1.17.0 or only a limitation in library ?
I attached a simple project to show this behavior.
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MPU Configuration--------------------------------------------------------*/
MPU_Config();
/* Enable I-Cache---------------------------------------------------------*/
SCB_EnableICache();
/* Enable D-Cache---------------------------------------------------------*/
SCB_EnableDCache();
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
memset(_Buffer, 0, 512);
HAL_I2C_Mem_Read_DMA(&hi2c1, 0xAE, 0x000, I2C_MEMADD_SIZE_16BIT, _Buffer, 256);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
2022-11-11 01:46 PM
The limit is 255 bytes.
Monitor the return value of HAL_* functions to determine if they succeed or not. Or step through.
> Is it a bug in FW 1.17.0 or only a limitation in library ?
The limitation is in hardware. See I2C_CR2 in the reference manual.
2022-11-12 02:52 PM
Not a limitation of the library. Documentation does not specify a size limit.
Try to read 510 bytes (255+255) and 511 (255+256). Will it work?
2022-11-16 10:51 AM
Hi TDK,
I understand the hardware limitation on the I2C_CR2 register and the library's limitation on the hi2c->XferSize.
However, hi2c->XferCount is not limited in the library (same link above but line 2986) being used in the I2C_Mem_ISR_DMA interrupt handler.
In version 1.16.2, the interrupt handler reconfigured the I2C to re-read the missing bytes (in the case of more than 255) using hi2c->XferCount and I can read 512 byte in one command.
So this behavior no longer exists or is it a bug in the library in 1.17.0?
I need to know whether or not I should modify my firmware to be compatible with new versions.
Thanks
2022-11-16 11:20 AM
Hi pavel,
I also found no limitation in the documentation.
About the recommendation:
1) read 510 bytes: (first read 255 and after more 255):
OK. Success. I can read as many bytes as I want using several 255 bytes read command in sequence.
2) read 511 bytes: (first read 255 and after more 256):
OK: I can read 511 bytes. But If I try read more than 256 bytes in same command, the clock goes low forever and the I2C Stops.
I'm not an expert on HAL Driver but it seems that after reading more than 256 bytes in a command, the interrupt handler is not sending the STOP bit correctly.
this behavior occurs only in version 1.17.0 for F7. In version 1.16.2 it works fine.
I also tested my code for HAL 1.10 for H7 family with success.
2022-11-16 11:21 AM
Similar theme
Watch what other slaves expect. Some of these devices are pretty dumb, so seeing long sustained / continuous bursts of data might be miss interpreted.
2022-11-16 12:02 PM
Hello,
in my case I am using an I2C FRAM (https://www.fujitsu.com/uk/Images/MB85RC256V-20171207.pdf). This slave has no page boundary.
Furthermore, I have a known pattern written and I can read everything correctly. I believe that the problem is with the master that does not release the clock after the communication when I perform readings of more bytes.
look osciloscope images below (I´m sorry .. I dont have a logic analizer)
OK (Blue is Clock .. it goes high after communication)
FAIL (Blue is Clock .. it goes low forever and I2C stops)
I only change the bytes to read using HAL_I2C_Mem_Read_DMA().
2022-11-16 04:51 PM
@ALORE.1 Then you've likely found a bug in the new version (aka regression). You can report it here or on github.
2022-11-17 07:28 AM
following your suggestion and to keep track of the solution here, follow the github link