I2C: allow static redefinition of I2C buffer size by ABOSTM · Pull Request #853 · stm32duino/Arduino_Core_STM32

Summary

I2C: allow static redefinition of I2C buffer size.
Default buffer size is still 32, but it is now possible to redefine compilation switch: I2C_TXRX_BUFFER_SIZE
It's maximum value is 255

Now it is possible to transfer up to 255 bytes for all following cases:

  • Master read
  • Master write
  • Slave read
  • Slave write

Warning: a bug in STM32 cube HAL currently prevents, in Master mode, to send/receive exactly 255 bytes.
Issue is tracked internally, and fix should come in later release.

Nevertheless, if required, it is possible to patch the STM32 cube HAL:
for example, when working on NUCLEO_L476RG in file stm32l4xx_hal_i2c.c (adapt file name to the STM32 familly you are working on), replace all occurrences of
if (hi2c->XferCount < MAX_NBYTE_SIZE)
by
if (hi2c->XferCount <= MAX_NBYTE_SIZE)