Skip to main content
alby87
Associate
February 17, 2014
Question

STM32L151RB I2C Busy flag always set

  • February 17, 2014
  • 15 replies
  • 3235 views
Posted on February 17, 2014 at 23:55

Hi!

I've a custom made board with STM32L15RB microcontroller. My I2C1 is not working well: I see the Busy flag going SET when I activate the APB1 Clock (RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);)

With a logic probe, I notice that both CLOCK and DATA are high (pullup resistors installed).

When I set them in alternate function (first I set them using PinAFConfig, and them in mode AF) they goes immediatly low. They are set at 2MHz, pushpull and nopull.

I tested to manualy force a clock signal (going up and down in out mode for CLOCK signal): the logic probe sees the square wave, but the DATA (set in AF I2C mode) wouldn't get up.

If I ignore the Busy flag (STM32 is the only master, there are three slaves), and generate a START, it wouldn't pass this piece of code''while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));'' and no interrupt are generated.

FYI, this is the clock configuration:

HSE=16MHz, PLLMUL 6, PLLDIV 3, SYSCLK 32000 , AHB PRESCALER 2, HCLK 16000, APB1 and APB2 prescaler 1 (PCLK1=PCLK2=16000).

I've configured it by using the system_stm32l1xx.c created by Clock Configuration.xls. I've also set in my preprocessor symbols this ''HSE_VALUE=16000000'' (I'm using KEIL uVision 4). I need to do something else to configure the HSE clock source? I'm using an external 16MHz oscillator.

I know about the errata... I'll configure the DMA... when I2C will start to work :)

Many thanks!

Alberto :)
    This topic has been closed for replies.

    15 replies

    alby87
    alby87Author
    Associate
    February 21, 2014
    Posted on February 21, 2014 at 16:56

    Checked: I've now 3 identical boards, and all with the same problem: there shouldn't be any problems.

    I've checked also the USART1, just to be sure: using the pin as an output works well, sending bytes via USART library put the line low and no more else. So also USART1 don't work.

    Do you have any suggestions to resolve the I2C problem (and maybe this will fix the USART one)?
    chen
    Associate II
    February 24, 2014
    Posted on February 24, 2014 at 10:24

    I am a bit lost now. To recap :

    ''Checked: I've now 3 identical boards, and all with the same problem''

    So, you still have the problem. As soon as the I2C is initialised - both lines go low?

    ''I've checked also the USART1, just to be sure: using the pin as an output works well, sending bytes via USART library put the line low and no more else. So also USART1 don't work.''

    Not sure what you are trying to do here. USART (or RS232) is a completely different comms protocol. It will not work in the same was as I2C. You cannot expect the line (in fact RS232 has Tx and Rx where as I2C has Data and a clock) to behave in the same way!

    ''Do you have any suggestions to resolve the I2C problem''

    Have you tried disconnecting your slave.

    Pajdoom
    Associate
    October 29, 2014
    Posted on October 29, 2014 at 09:26

    I have

    the same problem

    .

    How did you

    solve

    it

    ?

    You

    solve

    it

    ?

    Amel NASRI
    ST Technical Moderator
    October 31, 2014
    Posted on October 31, 2014 at 10:16

    Hi Stanislav,

    It should be better to create a new thread in which you describe exactly what you are facing as problem, used hardware, snippet code...

    Regarding this particular case: I suggest to enable I2C clock after configuring GPIOs.

    If my suggestion doesn't fix your issue, please go back to my first proposal & create a new thread.

    -Mayla-

    To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
    jvankuilenburg
    Associate II
    October 31, 2014
    Posted on October 31, 2014 at 11:32

    Hi,

    I had the same problem with the busyflag after init, there are 2 solutions:

    -start the I2C clock after setting the pins

    RCC->APB1ENR |= (1UL << 21);  // Enable I2C1 clock

    -before init I2C registers, do a reset:

    I2C1->CR1 |= 0x8000;

    I2C1->CR1 &= (uint16_t) ~((uint16_t) 0x8000);