i2c slave block transfer driver library

Dependents:   i2c_slave_block_example i2c_lora_slave

I2C block read/write slave

operates with I2C master using the i2c_smbus_read_i2c_block_data() and i2c_smbus_write_i2c_block_data() calls.

Tested with raspberry pi as master.
STM32Lx nucleo as slave.

signal pinmbed slaveRPi master
GND6
SCLD155
SDAD143
IRQany avail pinany avail pin

IRQ pin is implemented in application, not in this library. (see example)

Up to 32byte length per transfer.
Raspberry pi I2C doesnt support SMBUS block read, so I2C block transfers are supported here.
SMBUS block transfers are variable length. Instead, here in this driver, I2C block length is mapped to command byte by const array cmd_to_length[] (see example)

master write to slave

For i2c_smbus_write_i2c_block_data() from master, this driver lets the main loop on slave take the write request. The main loop on slave calls service_i2c(), which then calls service_i2c_write() upon each write from master. This occurs thru a circular buffer, permitting the slave to take its time doing the request, while the master can issue several back-to-back requests without delays.

clock stretching

For i2c_smbus_read_i2c_block_data(): Since raspberry pi doesnt support clock stretching out the the box, providing transmit data must be done in the interrupt service routine. fill_tx_buf() populates the transmit buffer to be sent to master, which must be done immediately because this occurs inside interrupt handler. If I2C master were to support clock stretching, then transmit buffer work could be done in main loop of slave.
/media/uploads/dudmuck/i2c_rpi_nucleo_sm_.png
An STM32 running at 32MHz is unlikely to operate with 400KHz I2C. Use 100KHz speed with 32MHz CPU, or use faster speed CPU for 400KHz I2C.

History

update HAL state for STM32L4 default tip

2019-02-04, by Wayne Roberts [Mon, 04 Feb 2019 13:42:05 -0800] rev 5

update HAL state for STM32L4


use dma to prevent underrun/overrun

2019-02-03, by Wayne Roberts [Sun, 03 Feb 2019 16:55:29 -0800] rev 4

use dma to prevent underrun/overrun


use dma to prevent underrun/overrun

2019-02-03, by Wayne Roberts [Sun, 03 Feb 2019 16:52:43 -0800] rev 3

use dma to prevent underrun/overrun


prevent denied transfer from being processed

2019-01-24, by Wayne Roberts [Thu, 24 Jan 2019 17:22:37 -0800] rev 2

prevent denied transfer from being processed


cmd_allowed() lets application decide if command is permitted

2019-01-21, by Wayne Roberts [Mon, 21 Jan 2019 16:58:05 -0800] rev 1

cmd_allowed() lets application decide if command is permitted


initial commit

2019-01-18, by Wayne Roberts [Fri, 18 Jan 2019 14:25:26 -0800] rev 0

initial commit