Files
microchip-application-pec93…/Examples/i2c/i2c_slave_transceiver

i2c_slave_transceiver

This example is used to transceive data with I2C-Slave

steps

IIC master: STM32 IIC slave: DUT

  1. STM32 ==> DUT(Transmit data action)
  2. DUT save the data
  3. STM32 ==> DUT(Receive data action)
  4. DUT send data( is consistent with the transmitted data)
  5. DUT compare the save send with the send 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 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

  • 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