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 I2C_MSG_READ and I2C_MSG_10BIT_ADDR.
- uint16 length
Message length.
- uint16 xferred
Messages transferred.
- uint8 * data
Data.
I2C device type.
Public Members
- i2c_reg_map * regs
Register map.
- gpio_dev * gpio_port
SDA, SCL pins’ GPIO port.
- 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.
- uint16 msgs_left
Messages left.
- i2c_msg * msg
Messages.
- uint32 timestamp
For internal use.
- uint32 error_flags
Error flags, set on I2C error condition.
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 RM008
Parameters: |
|
---|
Set SCL rise time.
Parameters: |
|
---|
Generate a start condition on the bus.
Parameters: |
|
---|
Generate a stop condition on the bus.
Parameters: |
|
---|
Disable one or more I2C interrupts.
Parameters: |
|
---|
Enable I2C acknowledgment.
Parameters: |
|
---|
Disable I2C acknowledgment.
Parameters: |
|
---|
I2C1 register map base pointer.
I2C2 register map base pointer.