STM32F4I2C

Alexander Shiryaev, 2016.09, 2017.04, 2019.10, 2020.12 Modified by Tenko for use with ECS

RM0090, Reference manual,

STM32F4{0,1}{5,7}xx, STM32F4{2,3}{7,9}xx (U1..U8)

RM0383, Reference manual,

STM32F411x{C,E} (U1,U2,U6)

RM0390, Reference manual,

STM32F446xx (U1..U6)

Const

NoError* = BusI2C.NoError;
ErrorTimeout* = BusI2C.ErrorTimeout;
ErrorNoDevice* = BusI2C.ErrorNoDevice;
ErrorArgs* = BusI2C.ErrorArgs;

Types

InitPar* = RECORD
        n* : INTEGER;
        SCLPinPort*, SCLPinN*, SCLPinAF*: INTEGER;
        SDAPinPort*, SDAPinN*, SDAPinAF*: INTEGER;
        PCLK1*: INTEGER;
        freq*: INTEGER;
        timeout*: INTEGER; (* transfere timeout in ms. 0 or lower disable timeout check *)
    END;
Bus* = RECORD (BusI2C.Bus)
        DR, CR1, SR1, SR2 : ADDRESS;
    END;

Procedures

Init

Initialize I2C bus

PROCEDURE Init* (VAR b : Bus; par-: InitPar);

Bus.Transfer

Read or Write data

PROCEDURE (VAR this: Bus) Transfer*(adr : INTEGER; rd : BOOLEAN; VAR buf : ARRAY OF BYTE; start, len : LENGTH; stop : BOOLEAN): LENGTH;

Bus.Probe

Probe address adr for device respons. Return 0 if device responded.

PROCEDURE (VAR this: Bus) Probe*(adr : INTEGER): INTEGER;

Bus.Read

Read into buffer from the peripheral specified by addr. The number of bytes read is length and the data is written to the buffer starting from start index. The function returns the number of bytes that were received.

PROCEDURE (VAR this: Bus) Read*(adr : INTEGER; VAR buffer : ARRAY OF BYTE; start, length : LENGTH): LENGTH;

Bus.Write

Write bytes from the buffer to the peripheral specified by addr. The number of bytes written is length and starting from start index. The function returns the number of bytes that were sent.

PROCEDURE (VAR this: Bus) Write*(adr : INTEGER; VAR buffer : ARRAY OF BYTE; start, length : LENGTH; stop : BOOLEAN): LENGTH;