0
\$\begingroup\$

This question has already be posted but i don't find a solution of my problem.

I have an LCD screen (MC20805A6W-BMLW-V2) with I2C communication and I try to communicate with my controller via I2C (STMS005K6). (4,7K ohm pull up resistors)

First I initialize my port :

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);

Then my Clock :

CLK_DeInit();
CLK_HSECmd(DISABLE); // Enable or not the external oscillator
CLK_LSICmd(DISABLE); // Enables or disables the Internal Low Speed oscillator (LSI).
CLK_HSICmd(ENABLE); // Enables or disables the Internal High Speed oscillator (HSI).

while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE); // Checks whether the specified CLK flag is set or not.   

CLK_ClockSwitchCmd(ENABLE); // Starts or Stops manually the clock switch execution.
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1); // Configures the HSI clock dividers.

CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE,CLK_CURRENTCLOCKSTATE_ENABLE);

CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, ENABLE);

And my I2C :

I2C_DeInit();
I2C_Init(100000, 
             SLAVE_ADRESS, 
             I2C_DUTYCYCLE_2, 
             I2C_ACK_CURR, 
             I2C_ADDMODE_7BIT, 
             16);

I enable the I2C communication and generate a start :

I2C_Cmd(ENABLE);
I2C_GenerateSTART(ENABLE);
while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));

while(!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT)); //It means that the Start condition has been correctly released on the I2C bus 

I2C_Send7bitAddress(SLAVE_ADRESS << 1, I2C_DIRECTION_TX);

PROBLEM : I stay inside the while loop (get flag statut) because the controller thinks that my i2C bus is busy. (I2C->SR3 = 0x02).

I tried a lot of solutions, like resetting the soft with the regiter I2C->CR2 |= I2C_CR2_SWRST (problem with the second while loop) or create a i2c stop manually, but nothing worked.

I have also coded register by register for the clk and I2C but nothing had change.

On my I2C logic analyser we can see that both of my signals are HIGH...... enter image description here

Does anyone have a idea of my problem ?

Thanks

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.