AnsweredAssumed Answered

I2C Problems

Question asked by marmsoler.martin on Oct 11, 2015
Latest reply on Oct 26, 2015 by marmsoler.martin
Hello,

I tried to test the I2C interface on a STM32:
01.#include <stdio.h>
02.#include <stdlib.h>
03.#include "diag/Trace.h"
04.#include "stm32f4xx_hal.h"
05.#include "stdint.h"
06. 
07. 
08.int
09.main(int argc, char* argv[])
10.{
11.    GPIO_InitTypeDef init;
12.    I2C_HandleTypeDef i2c1Handle;
13.    uint8_t data[5] = {1,2,3,4,5};
14. 
15. 
16.    /* CLKs enable only if needed */
17.    __HAL_RCC_GPIOB_CLK_ENABLE();
18.    __HAL_RCC_I2C1_CLK_ENABLE();
19. 
20.    // SDL Port B8
21.    init.Pin = GPIO_PIN_8;
22.    init.Mode = GPIO_MODE_AF_OD;
23.    init.Alternate = GPIO_AF4_I2C1;
24.    init.Pull = GPIO_NOPULL;

26.    HAL_GPIO_Init(GPIOB, &init);
27. 
28.    init.Pin = GPIO_PIN_9;
29.    HAL_GPIO_Init(GPIOB, &init);
30. 
31. 
32.    i2c1Handle.Instance = I2C1;
33.    i2c1Handle.Init.ClockSpeed = 100000; // 100kHz
34.    i2c1Handle.Init.AddressingMode  = I2C_ADDRESSINGMODE_7BIT;
35.    i2c1Handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
36.    i2c1Handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
37.    i2c1Handle.Init.NoStretchMode   = I2C_NOSTRETCH_DISABLED;
38.    i2c1Handle.Init.OwnAddress1 = 0x56;
39.    HAL_I2C_Init(&i2c1Handle);
40. 
41.        //HAL_I2C_Master_Transmit(&i2c1Handle, 0x3C, data, 1, 10000);
42.        // Infinite loop
43.        while (1)
44.        {
45.            // Add your code here.
46.            int i = 0;
47.        }
48.    }
I found out, that when I init the speed variable, the program works. But now my question:
Does the variables don't have an init value, because the registers have init values?

Outcomes