cancel
Showing results for 
Search instead for 
Did you mean: 

I2C NOT WORKING

Gojo
Associate II

Hello everyone,

I'm coming back to you regarding a synchronization problem between master and slave in I2C.

I'm making an I2C/UART debug interface, what I want to do is display a menu in a terminal-> When we receive an address from the master (sent in I2C) to the slave we authorize the user to enter his choice in the terminal-> after reading the choice we display it in the terminal and transmit it to the master (slave->master) -> then at the master level according to RxData = which normally should contain the choice sent by the slave except that this is not the case -> according to RxData if = 'b' lights green led, if = 'l' yellow led, else lights orange led.

To debug since it doesn't work as expected, when I receive all the address sent by the master, I send it to a process_data function and to force the issue, I send the 'b' character directly to the choice location, except that I receive nothing from the master and I get stuck in this loop:

while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXIS) == RESET)
{
/* Check if an error is detected */
if (I2C_IsErrorOccurred(hi2c, Timeout, Tickstart) != HAL_OK)
{
return HAL_ERROR;
}

/* Check for the Timeout */
if (Timeout != HAL_MAX_DELAY)
{
if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
{
if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXIS) == RESET))
{
hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
hi2c->State = HAL_I2C_STATE_READY;
hi2c->Mode = HAL_I2C_MODE_NONE;

/* Process Unlocked */
__HAL_UNLOCK(hi2c);

return HAL_ERROR;
}
}
}
}
return HAL_OK;
}

except that by commenting on the two lines in process_data():

// HAL_I2C_DisableListen_IT(&hi2c1);
// __HAL_UART_CLEAR_OREFLAG(&hi2c1);

I manage to get out of the loop with a RxData = '\0'; and the orange led lights up despite the fact that I've transmitted the letter 'b' knowing that at slave level the return value of HAL_I2C_Slave_Transmit is HAL_BUSY

So I thought of setting breakpoints, and when I set them, I realized that the red LED was ON on the master, which corresponds to error_handler, which makes more sense because the return value of HAL_I2C_Slave_Transmit is HAL_BUSY.

I really need your help to move forward with my project.

PS: you'll find the code attached: i2c.c for the master and i2c_slave for the slave for me master it's an MCU: STM32L562VET6Q and for the slave it's a nucleo-L476RG board.

Thanks in advance for your answers.

Have a nice day!

2 REPLIES 2
SofLit
ST Employee

Hello,

Please post in English as it's an international community.

Also there is no reason to tag all these products. You need only to tag the products you're using.

Thank you for your understanding.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I will change it, thanks a lot for your response. for the taging i was thinking the more people i tag the more reach i'll have. 

Have a good day !