Hallo Leute,
ich habe es nun geschafft, den I2C modul /bus korrekt zu initalisieren
(glaub ich). Allerding bekomme ich nach der ersten sendekation
I2C2->DR=... eine AF im SR1 register (Acknolage failure). ich kann mir
aber nich erklären warum. Die Startcondition funktiomniert, und das DR
register wird auch gesendet (sehe ich am oszi) aber dann wird das AF
flag gesetzt , und ich weiß nich warum. Normalerweiße müsste er nach dem
senden eines Bytes , ja das TxE flag setzen, welches mir signalisiert,
dass ich das nächste byte schicken kann. nun ja, so sieht mein ode aus:
Initialisierung
1 | void I2C_LowLevel_Init(void)
|
2 | {
|
3 | GPIO_InitTypeDef GPIO_InitStructure;
|
4 | I2C_InitTypeDef I2C_InitStructure;
|
5 |
|
6 | //Enable the GPIOs for the SCL/SDA Pins
|
7 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
|
8 |
|
9 | //Configure and initialize the GPIOs
|
10 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; //Pin 10 SCL, Pin 11 SDA
|
11 |
|
12 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
13 | //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
14 |
|
15 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; // EVTL: SPEED RUNTER SETZEN!!
|
16 | GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
|
17 | //GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
18 |
|
19 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;//GPIO_PuPd_UP;
|
20 | GPIO_Init(GPIOB, &GPIO_InitStructure);
|
21 |
|
22 | //Connect GPIO pins to peripheral
|
23 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2);
|
24 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);
|
25 |
|
26 | //Enable the i2c
|
27 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
|
28 |
|
29 | // Enable I2CG reset state
|
30 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, ENABLE);
|
31 | // Release I2CG from reset state
|
32 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C2, DISABLE);
|
33 |
|
34 | I2C_DeInit(I2C2);
|
35 |
|
36 | // I2C Peripheral Enable
|
37 | I2C_Cmd(I2C2, ENABLE);
|
38 |
|
39 | //Configure and Initialize the I2C
|
40 | I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
|
41 | I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
|
42 | I2C_InitStructure.I2C_OwnAddress1 = 0xFE; //We are the master. We don't need this
|
43 | I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
|
44 | I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
|
45 | I2C_InitStructure.I2C_ClockSpeed = 30000; //400kHz (Fast Mode) (
|
46 |
|
47 | //Initialize the Peripheral
|
48 | I2C_Init(I2C2, &I2C_InitStructure);
|
49 | }
|
meine sende test methode
1 | uint16_t I2C2_WrBufTest(void)
|
2 | {
|
3 |
|
4 | uint8_t buf[3]=0;
|
5 | uint32_t TimeOut = HSI_VALUE,i=0,temp=0;
|
6 |
|
7 |
|
8 | //No Ack
|
9 | //I2C2->CR1 &= ~I2C_CR1_ACK;
|
10 |
|
11 | //StartCondition generieren
|
12 | I2C2->CR1 |= I2C_CR1_START;
|
13 |
|
14 | // SR1: = U²C Status Register, SB= StartBit
|
15 | while(((I2C2->SR1) & 0x0001) != 0x0001)
|
16 | {
|
17 | if (!(TimeOut--))
|
18 | {
|
19 | //panic(Flags, "I2C Error\n",2);
|
20 | return 1;
|
21 | }
|
22 | }
|
23 |
|
24 | buf[0]=0xAA;
|
25 |
|
26 | I2C2->DR = buf[0] & 0xFFFE; //Address (HIER KOMMT DAS AF FALG)
|
27 |
|
28 | //StartCondition generieren
|
29 | I2C2->CR1 |= I2C_CR1_STOP;
|
30 |
|
31 | //return 0;
|
32 | // SR1: = U²C Status Register, Busy flag?
|
33 | while(((I2C2->SR1) & 0x0002) != 0x0002)
|
34 | {
|
35 | if (!(TimeOut--))
|
36 | {
|
37 | //panic(Flags, "I2C Error\n",2);
|
38 | return 2;
|
39 | }
|
40 | }
|
41 |
|
42 | return 0;
|
43 | }
|
nach dem ersten aufruf der I2C2->DR, kommt eben das AF flag in SR1..
aber wieso???? Kennt jemand das problem?
GRüße