Files
microchip-application-pec93…/Examples/i2c/i2c_mster_transceiver/readme.md
T

79 lines
1.9 KiB
Markdown

## I2C_master_transceiver
> This example is used to transceive data with STM32 I2C-Master
### steps
> IIC master: `DUT` IIC slave: `STM32`
1. `DUT` ==> `STM32`(Transmit data action)
2. `STM32` save the data
3. `DUT` ==> `STM32`(Receive data action)
4. `STM32` send the saved data
5. `DUT` save the read data
6. `DUT` compare the Transmitted data with the Received data, if consistent, proceed to the next loop, and inconsistent, enter while(1) loop
### Configuration
+ select transmit mode
```
//in main.c
/**
* if defined, transfer data using interrupt mode
* if not, transfer data using polling mode
*/
#define CONFIG_USE_I2C_INTERRUPT
```
+ Select IIC DIV Clock
```
//in main.c
#define IIC_DIV_CLOCK I2C_CLK_Div60 // I2C clock division
```
+ Select IIC pin
```
//in main.c
/**
* Select I2C SCL and SDA pin
*/
#define IIC_SCL_PORT GPIOA
#define IIC_SCL_PIN GPIO_Pin_00
#define IIC_SCL_AF GPIO_AF_4
#define IIC_SDA_PORT GPIOA
#define IIC_SDA_PIN GPIO_Pin_01
#define IIC_SDA_AF GPIO_AF_4
```
> SCL_PIN: `PA00` `PA01` `PB02` `PB01` `PB03` `PA15`
>
> SDA_PIN: `PA01` `PA00` `PB01` `PB02` `PB05` `PB00`
---
Note:
+ Select UART log pin
```
// in syslog.c
#define CONFIG_LOG_DEVICE_TX_IO_PORTx GPIOA
#define CONFIG_LOG_DEVICE_TX_IO_PINx GPIO_Pin_15
#define CONFIG_LOG_DEVICE_TX_IO_AF GPIO_AF_1
```
+ If you want to use `PB1` as an I2C pin, set IO to normal IO.(RST pin by default)
```
SYSCFG_SetRstPin2NormalIO(true); // set RST IO to normal IO
```
+ If you want to use `PB[2:5]` as an I2C pin, set IO to normal IO, and Restore IO to JTAG IO at the end.(JTAG pin by default)
```
SYSCFG_SetICEPin2NormalIO(true); // set JTAG IO to normal IO
SYSCFG_SetICEPin2NormalIO(false); // set normal IO to JTAG IO
```