Skip to main content
Visitor II
October 5, 2022
Question

application note AN3281 to implement the I2C bus for the STM8S microcontroller.

  • October 5, 2022
  • 4 replies
  • 2415 views

You have published an application note AN3281 to implement the I2C bus.

Where can we download the example programs described in the note?

Thank you for your answers

    This topic has been closed for replies.

    4 replies

    Technical Moderator
    October 5, 2022

    You can find it on the website of the STSW-STM8004.

    Good luck!

    Regards

    /Peter

    Visitor II
    October 5, 2022

    Thanks

    Technical Moderator
    October 5, 2022

    You're welcome!

    If the problem is solved, please mark this thread as answered by selecting Select as best, as also explained here. This will help other users find that answer faster.

    Regards

    /Peter

    Visitor II
    October 5, 2022

    I managed to download the program. Thanks.

    Have you released an equivalent that uses the SPL library?

    Regards

    Technical Moderator
    October 5, 2022

    The program for the AN3281 was developed many years before the SPL and represents, so to speak, a first approach to working with I2C on the STM8.

    However, the SPL has since supported all functions of the I2C peripheral in the STM8, so the AN3281 should only be considered as a reference.

    Regards

    /Peter

    Visitor II
    October 5, 2022

    My issue is the following :

    I use the nucleo_8s207k8 evaluation kit.

    I am trying to enable I2C bus as master with these functions

    void clock_setup(void) {
     
     CLK_DeInit();
     
     CLK_HSECmd(DISABLE);
     CLK_LSICmd(DISABLE);
     CLK_HSICmd(ENABLE);
     while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);
     
     
     CLK_ClockSwitchCmd(ENABLE);
     CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // HSI à 16 MHz
     CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1); // soit CPU à 16Mhz
     
     CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI,
     DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE);
     
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, DISABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, DISABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);
     CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);
    }
     
    void GPIO_setup(void) {
     GPIO_DeInit(GPIOB);
     GPIO_Init(GPIOB, GPIO_PIN_4, GPIO_MODE_OUT_OD_HIZ_FAST);
     GPIO_Init(GPIOB, GPIO_PIN_5, GPIO_MODE_OUT_OD_HIZ_FAST);
     GPIO_WriteHigh(GPIOB, GPIO_PIN_4);
     GPIO_WriteHigh(GPIOB, GPIO_PIN_5);
    }
     
    void I2C_setup(void) {
     I2C_DeInit();
     I2C_Init(10000,
     BH1750_addr,
     I2C_DUTYCYCLE_2,
     I2C_ACK_CURR,
     I2C_ADDMODE_7BIT,
     16);
     
     I2C_Cmd(ENABLE);
    }

    However the I2C_FLAG_BUSBUSY remains at logical true

    Why ?

     uint16_t time_out = 5000;
     
     /* If I2C bus is busy wait until it is free */
     while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY)&& (--time_out));
     if (!time_out) return 1;

    Do you have an explanation ?

    regards

    Philippe S Teacher