[Jihai APM32F4xx Tiny] Jihai APM32F407__IIC_STH30 (1)
[Copy link]
This post was last edited by Yin Xiaozhou on 2023-6-19 14:55
In this post, we will introduce the IIC function of APM32F4. In this post, we will use the I2C of APM32F407 to collect the temperature data of the external SHT30 and transmit the result to the computer through the serial port.
APM32F405xGw407xExG products have 3 hardware IICs inside, all of which can work in multi-master mode or slave mode, support 7-bit or 10-bit addressing, support dual slave address addressing in 7-bit slave mode, and support standard mode (up to 100kbit/s) and fast mode (up to 400kbit/s) communication rates; built-in hardware CRC generator/checker; they can use DMA operations and support SMBus bus version 2.0/PMBus bus.
Configurable I2C GPIO
- I2C1
- I2C2
- SDA PF0 PH5 PB11
- SCL PF1 PH4 PB10
- I2C3
Block Diagram
Library function introduction
I2C_Config_T structure
typedef struct
{
uint32_t clockSpeed; /*!< I2C clock speed /
I2C_MODE_T mode; /!< I2C mode /
I2C_DUTYCYCLE_T dutyCycle; /!< I2C duty cycle /
uint16_t ownAddress1; /!< I2C own address /
I2C_ACK_T ack; /!< Acknowledge /
I2C_ACK_ADDRESS_T ackAddress; /!< I2C acknowledged address */
} I2C_Config_T;
member
|
Functional Description
|
clockSpeed
|
I2C Clock Speed
|
mode
|
Specify the working mode, optional I2C mode and SMBUS mode
|
dutyCycle
|
Specify the clock duty cycle, optional low/high = 2:1 and 16:9 modes
|
ownAddress1
|
Specify its own I2C device address
|
ack
|
Enable or disable response (usually enabled)
|
ackAddress
|
Specifies the length of the address, which can be 7 or 10 bits.
|
Function Prototype
|
void I2C_Reset(I2C_T* i2c)
|
Functional Description
|
Reset peripheral I2C
|
Input parameters {in}
|
i2c
|
I2C1 or I2C2, I2C3
|
Function Prototype
|
void I2C_Config(I2C_T* i2c, I2C_Config_T* i2cConfig)
|
Functional Description
|
Configure I2C via I2C_Config_T
|
Input parameters {in}
|
|
|
Function Prototype
|
void I2C_ConfigStructInit(I2C_Config_T* i2cConfig)
|
Functional Description
|
Fill each I2C_InitStruct member with default values.
|
Input parameters {in}
|
|
|
Function Prototype
|
void I2C_Enable(I2C_T* i2c)
|
Functional Description
|
Implementing I2C
|
Input parameters {in}
|
|
|
Function Prototype
|
void NVIC_EnableIRQRequest(IRQn_Type irq, uint8_t
preemptionPriority, uint8_t subPriority)
|
Functional Description
|
Enable NVIC request
|
Input parameters {in}
|
|
|
Example: /* NVIC configuration */ NVIC_EnableIRQRequest(I2C1_EV_IRQn, 1, 0);
Function Prototype
|
void I2C_DisableDualAddress(I2C_T* i2c)
|
Functional Description
|
Disables the specified I2C dual addressing mode.
|
Input parameters {in}
|
|
|
Function Prototype
|
void I2C_EnableInterrupt(I2C_T* i2c, uint16_t interrupt)
|
Functional Description
|
Enable the specified I2C interrupt.
|
Input parameters {in}
|
|
|
Function Prototype
|
uint8_t I2C_ReadIntFlag(I2C_T* i2c, I2C_INT_FLAG_T flag)
|
Functional Description
|
Check if I2C interrupt is set
|
Input parameters {in}
|
|
|
I2C_INT_FLAG_T flag value
I2C_INT_FLAG_T
|
describe
|
I2C_INT_FLAG_SMBALT
|
SMBus Alert Flag
|
I2C_INT_FLAG_TTE
|
Timeout or Tlow error flag
|
I2C_INT_FLAG_PECE
|
PEC error in receive flags
|
I2C_INT_FLAG_OVRUR
|
Overflow/Underload Flag (Slave Mode)
|
I2C_INT_FLAG_AE
|
Confirm error flag
|
I2C_INT_FLAG_AL
|
Arbitration lost flag (master mode)
|
I2C_INT_FLAG_BERR
|
Confirm error flag
|
I2C_INT_FLAG_TXBE
|
Transmitter data register empty flag
|
I2C_INT_FLAG_RXBNE
|
Receiver data register not empty flag
|
I2C_INT_FLAG_STOP
|
Stop detection flag (slave mode)
|
I2C_INT_FLAG_ADDR10
|
0-bit header sending flag (host mode)
|
I2C_INT_FLAG_BTC
|
Byte transfer complete flag
|
I2C_INT_FLAG_ADDR
|
Address send flag (host mode)
|
I2C_INT_FLAG_START
|
Start bit flag (host mode)
|
Function Prototype
|
uint8_t I2C_ReadStatusFlag(I2C_T* i2c, I2C_FLAG_T flag)
|
Functional Description
|
Check if the I2C flag is set
|
Input parameters {in}
|
|
|
|