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:
/* Configure the system clock */
/* Initialize all configured peripherals */
accl_buff = 'a'; // transmit buffer for I2C
HAL_I2C_Master_Transmit(&hi2c1, 0x18, accl_buff, 1, 10 ); // 0x18 is slave address
accl_buff = accl_buff+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.