I need to communicate STM32L062 with MC3413 accelerometer, but communication only works when uC clock settings are default (16MHz HSI) and generated by CubeMX. Any change (for example changing source to ~4MHz MSI) causes slave to not give ACK. Im beginner and i've tried many combinations of prescalers etc. and i have no clue what is wrong. Here is my main loop code:
while (1) {
uint8_t config1;
config1 = 0xC0;
status[0]=HAL_I2C_Mem_Write(&hi2c1, 0x98, 0x07, 1, &config1, 1, 100); // 0xC0 konfiguruje akcelerometr w tryb standby
config1 = 0x78;
status[1]=HAL_I2C_Mem_Write(&hi2c1, 0x98, 0x08, 1, &config1, 1, 100); // 0x7A wlacza wykrywanie tapniec we wszystkich osiach i 256Hz sampling
config1 = 0x05;
status[2]=HAL_I2C_Mem_Write(&hi2c1, 0x98, 0x20, 1, &config1, 1, 100); // 0x05 powinno ustawic rozdzielczosc 14bit i zakres 2g
config1 = 0xC1;
status[3]=HAL_I2C_Mem_Write(&hi2c1, 0x98, 0x07, 1, &config1, 1, 100); // 0xC1 konfiguruje akcelerometr w tryb aktywny
status[4]=HAL_I2C_Mem_Read(&hi2c1, 0x98, 0x11, 1, &polozenie_l, 1, 100);
status[5]=HAL_I2C_Mem_Read(&hi2c1, 0x98, 0x12, 1, &polozenie_h, 1, 100);
polozenie = ((polozenie_h << 8) | polozenie_l);
HAL_Delay(100);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
https://i.stack.imgur.com/sgBnY.png
https://i.stack.imgur.com/itOLC.png