Inter-Integrated Circuit (I2C) peripheral support.
Contents
There are some important known problems with the built-in I2C peripherals. For more information, see STM32F10xx8 and STM32F10xxB Errata sheet (ST Doc ID 14574 Rev 8), Section 2.11.1, 2.11.2. An important consequence of these problems is that the I2C interrupt must not be preempted. Consequently, (by default) Wirish uses an I2C interrupt priority which is the highest in the system (priority level 0). Other interrupt priorities are set lower.
I2C register map type.
Public Members
- __io uint32 CR1
Control register 1.
- __io uint32 CR2
Control register 2.
- __io uint32 OAR1
Own address register 1.
- __io uint32 OAR2
Own address register 2.
- __io uint32 DR
Data register.
- __io uint32 SR1
Status register 1.
- __io uint32 SR2
Status register 2.
- __io uint32 CCR
Clock control register.
- __io uint32 TRISE
TRISE (rise time) register.
I2C device states.
Values:
Disabled.
Idle.
Done with transfer.
Busy.
Error occurred.
I2C message type.
Public Members
- uint16 addr
Address.
- uint16 flags
Bitwise OR of:
- uint16 length
Message length.
- uint16 xferred
Messages transferred.
- uint8 * data
Data.
I2C device type.
Public Members
- struct i2c_reg_map * regs
Register map.
- struct i2c_msg * msg
Messages.
- uint32 error_flags
Error flags, set on I2C error condition.
- uint32 timestamp
For internal use.
- struct gpio_dev * gpio_port
Deprecated.
Use .scl_port or .sda_port instead. If non-null, this will be used as SDA, SCL pins’ GPIO port. If null, then .sda_port will be used for SDA, and .sda_port for SDA.
- struct gpio_dev * sda_port
SDA GPIO device (but see .gpio_port).
- struct gpio_dev * scl_port
SCL GPIO device (but see .gpio_port).
- uint16 msgs_left
Messages left.
- uint8 sda_pin
SDA bit on gpio_port.
- uint8 scl_pin
SCL bit on gpio_port.
- rcc_clk_id clk_id
RCC clock information.
- nvic_irq_num ev_nvic_line
Event IRQ number.
- nvic_irq_num er_nvic_line
Error IRQ number.
- i2c_state state
Device state.
Initialize an I2C device and reset its registers to their default values.
Parameters: |
|
---|
Initialize an I2C device as bus master.
Parameters: |
|
---|
Process an i2c transaction.
Transactions are composed of one or more i2c_msg‘s, and may be read or write tranfers. Multiple i2c_msg‘s will generate a repeated start in between messages.
Parameters: |
|
---|---|
Return: | 0 on success, I2C_ERROR_PROTOCOL if there was a protocol error, I2C_ERROR_TIMEOUT if the transfer timed out. |
Reset an I2C bus.
Reset is accomplished by clocking out pulses until any hung slaves release SDA and SCL, then generating a START condition, then a STOP condition.
Parameters: |
|
---|
Disable an I2C device.
This function disables the corresponding peripheral and marks dev’s state as I2C_STATE_DISABLED.
Parameters: |
|
---|
Turn on an I2C peripheral.
Parameters: |
|
---|
Turn off an I2C peripheral.
Parameters: |
|
---|
Fill transmit register.
Parameters: |
|
---|
Set input clock frequency, in MHz.
Parameters: |
|
---|
Set I2C clock control register.
See the chip reference manual for the details.
Parameters: |
|
---|
Set SCL rise time.
Parameters: |
|
---|
Generate a start condition on the bus.
Parameters: |
|
---|
Generate a stop condition on the bus.
Parameters: |
|
---|
Enable one or more I2C interrupts.
Parameters: |
|
---|
Disable one or more I2C interrupts.
Parameters: |
|
---|
Enable I2C acknowledgment.
Parameters: |
|
---|
Disable I2C acknowledgment.
Parameters: |
|
---|
STM32F1 I2C1 register map base pointer.
STM32F1 I2C2 register map base pointer.