Hallo,
Ich versuche von einem blue pill aus einen lis3mdl-kompassensor
anzusprechen. Das ganze wollte ich mit Cubemx und Atollic Studio machen.
Ich habe mit den Tools ein einfaches Beispiel generiert.
Andere i2c-komponenten (eeprom z.b.) erreiche ich problemlos.
Alle Einstellungen im Cubemx sind standard.
Die Hardware selbst funktioniert. Ich habe das gleiche mal mittels
arduino auf der Hardware realisiert. Da läufts.
Aber mit Cubemx/atollic will es nicht. Habe auch schon mal an den
i2c-Parametern gespielt. ergebnislos.
Hat da jemand ne Idee, woran es liegen könnte ?
1 | void MX_I2C1_Init(void)
|
2 | {
|
3 | hi2c1.Instance = I2C1;
|
4 | hi2c1.Init.ClockSpeed = 100000;
|
5 | hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
|
6 | hi2c1.Init.OwnAddress1 = 0;
|
7 | hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
8 | hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
9 | hi2c1.Init.OwnAddress2 = 0;
|
10 | hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
11 | hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
12 | if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
13 | {
|
14 | Error_Handler();
|
15 | }
|
16 | }
|
17 |
|
18 | void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
|
19 | {
|
20 | GPIO_InitTypeDef GPIO_InitStruct = {0};
|
21 | if(i2cHandle->Instance==I2C1)
|
22 | {
|
23 | __HAL_RCC_GPIOB_CLK_ENABLE();
|
24 | /**I2C1 GPIO Configuration
|
25 | PB6 ------> I2C1_SCL
|
26 | PB7 ------> I2C1_SDA
|
27 | */
|
28 | GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
|
29 | GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
|
30 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
31 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
32 | __HAL_RCC_I2C1_CLK_ENABLE();
|
33 | }
|
34 | }
|
35 |
|
36 | int main(void)
|
37 | {
|
38 | HAL_Init();
|
39 | SystemClock_Config();
|
40 | MX_GPIO_Init();
|
41 | MX_I2C1_Init();
|
42 | HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,1);
|
43 | int erg;
|
44 | erg=HAL_I2C_IsDeviceReady(&hi2c1,(0x1e<<1),100,2000);
|
45 | if (erg==HAL_OK)
|
46 | {
|
47 | HAL_GPIO_WritePin(GPIOC,GPIO_PIN_13,0);
|
48 | }
|
49 | while (1)
|
50 | {
|
51 | }
|
52 | }
|