1 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE);
|
2 |
|
3 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1);
|
4 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
|
5 |
|
6 | GPIO_InitTypeDef GPIO_InitStructure;
|
7 |
|
8 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
|
9 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
10 | GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
11 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
12 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
13 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
14 |
|
15 |
|
16 |
|
17 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
|
18 |
|
19 | I2C_InitTypeDef I2C_InitStruct;
|
20 |
|
21 | I2C_InitStruct.I2C_Ack = I2C_Ack_Disable;
|
22 | I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
23 | I2C_InitStruct.I2C_ClockSpeed = 100000;
|
24 | I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
|
25 | I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
|
26 | I2C_InitStruct.I2C_OwnAddress1 = 0;
|
27 |
|
28 | I2C_Init(I2C1, &I2C_InitStruct);
|
29 |
|
30 | I2C_Cmd(I2C1, ENABLE);
|
31 |
|
32 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
33 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
|
34 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
35 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
36 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
37 |
|
38 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
|
39 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
40 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
|
41 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
42 | GPIO_Init(GPIOA, &GPIO_InitStructure);
|
43 |
|
44 | while(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)); //Wait for USER BUTTON
|
45 |
|
46 |
|
47 |
|
48 | GPIO_SetBits(GPIOA, GPIO_Pin_5); //Trigger for analyzer
|
49 | I2C_GenerateSTART(I2C1, ENABLE);
|
50 |
|
51 | I2C_Send7bitAddress(I2C1, 0x3A, I2C_Direction_Transmitter);
|
52 |
|
53 | while(1);
|