cancel
Showing results for 
Search instead for 
Did you mean: 

Teseo-LIV3F I2C-code explanation (AN5203)

OPush
Associate II

Hi,

I do not understanfd why I2C init (lines 2,3) is included in While(1)? Should not it be used just one time?

1    while (1) {

2     HAL_I2C_DeInit(&hi2c1);

3     HAL_I2C_Init(&hi2c1);

4     if (_read == 1) {

5           _read = 0;

6           Console_Write("Sending commands...");

7           HAL_I2C_Master_Transmit(&hi2c1, 0x3A << 1, (uint8_t *)gpgll_msg, strlen(gpgll_msg), 2000);

8           Console_Write(" got:... \r\n");

9           for (read_buf[180-1] = 0; read_buf[180-1] != 0xff;) {

10                 HAL_I2C_Master_Receive(&hi2c1, 0x3A << 1, read_buf, 180, 2000);

11                 for (i = 0; i < 180; ++i)

12                 if (read_buf[i] != 0xff)

13                 HAL_UART_Transmit(&huart2, &read_buf[i], 1, 1000);

14          }

15          Console_Write("\r\n");

16          }

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 REPLY 1
Francesco Virlinzi
ST Employee

Hi

Lines 2 and 3 are there due to some issue on I2C.IP in some STM32.

To bypass the issue I2C-IP (in STM32) is resetted and restarted.

Hope this helps

Regards

Francesco