AnsweredAssumed Answered

I2C peripheral not working with CubeMx generated code (HAL driver)

Question asked by Jane Sk on Jun 28, 2017
Latest reply on Mar 5, 2018 by Yuri Fedkin

I am using CubeMx (HAL driver)for initialization code generation and using HAL libraries/functions after that. The MCU is STM32F042 I am having problem with the I2C peripheral. It is a custom board and for the time being, no external device is attached to the I2C pins. The pins are just pulled up using pull-up resistors. I am trying to use it in master transmit/receive mode. After MX_I2C1_Init() is executed : -

Observations: Using an oscilloscope, i can see that there is no clock signal on SCL pin. The voltage at the SCL pin is always LOW. The voltage on the SDA pin is always HIGH. And I2C1 -> ISR-> BUSY flag is SET.

 

Below I have copied portion of the code from main() function:

 

int main(void)
{

  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

 

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CAN_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();
   MX_I2C1_Init();

 

accl_buff[0] = 'a';              //       transmit buffer for I2C

 

  while (1)
  {
    HAL_I2C_Master_Transmit(&hi2c1, 0x18, accl_buff, 1, 10 );         // 0x18 is slave address
    
    accl_buff[0] = accl_buff[0]+1;         //    update I2C transmit buffer
       
    for(i=0;i<10000;i++);      //       delay function

   }

   }

 

All I have done is add HAL_I2C_Master_Transmit() to the while loop in main(). Otherwise, the code is as generated by CubeMx. But the I2C peripheral DOES NOT generate any clock signal on SCL pins(always held LOW) & neither give out any data on the SDA pins(held HIGH).

Where am I mistaken ?

 

I think my problem is similar to I2C - generated CubeMX , though a different MCU. I did not find any I2C example for this MCU to test. I have also tried generating code with LowLevel Driver from CubeMx, and the BUSY flag is in reset condition after initialization.

 

Thanks in advance.

Outcomes