0

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

https://i.stack.imgur.com/4Y7Kp.png

https://i.stack.imgur.com/5PlLW.png

  • Just a guess ... Your original `SYSCLK` was 16. The modifed one is 4.169 How about something easily divisible by 2? (e.g.) Try 8 and see if that works. Then, you can try 4 – Craig Estey Sep 09 '21 at 20:03
  • I tried 8,6,4 nothing works, only default 16 and 16 from PLL – Konrad Hryniewicki Sep 10 '21 at 04:58
  • I STM32CubeMX setting up the I2C_TIMINGR register for you? – TRPh Sep 13 '21 at 17:48
  • Do you mean you can configure this register for me ? I'm currently investigating it because i noticed that when i change internal clock Cube calculates something wrong in this register and SCL frequency is 26kHz. – Konrad Hryniewicki Sep 14 '21 at 16:02
  • Sorry i misunderstood you, yes Cube is setting up TIMINGR register for me. I need to sit for a moment to understand this register. – Konrad Hryniewicki Sep 14 '21 at 16:06

0 Answers0