i2c_slave_transceiver
This example is used to transceive data with I2C-Slave
steps
IIC master:
STM32IIC slave:DUT
STM32==>DUT(Transmit data action)DUTsave the dataSTM32==>DUT(Receive data action)DUTsend data( is consistent with the transmitted data)DUTcompare the save send with the send data, if consistent, proceed to the next loop, and inconsistent, enterwhile(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 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_4SCL_PIN:
PA00PA01PB02PB01PB03PA15SDA_PIN:
PA01PA00PB01PB02PB05PB00 -
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
PB1as 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