1 | void i2c_handleEventInterrupt_ReadMethod1(void){
|
2 |
|
3 | if(i2c1_EV_ISR_Count < 25){
|
4 | i2cDebug_EV_ISRanfang[(i2c1_EV_ISR_Count* 2) +1] = I2C_Module->SR2;
|
5 | i2cDebug_EV_ISRanfang[(i2c1_EV_ISR_Count* 2)] = I2C_Module->SR1;
|
6 |
|
7 | i2cDebug_EV_ISRanfang_DebugFlags[i2c1_EV_ISR_Count] = debug32[3];
|
8 | }
|
9 |
|
10 | //const uint16_t readSR1 = I2C_ReadRegister(I2C_Module, I2C_Register_SR1);
|
11 | if(i2cDirectionWrite){
|
12 | debug32[3] |= (1 << 0);
|
13 | if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_SB) == SET){
|
14 | //EV5
|
15 | I2C_ReadRegister(I2C_Module, I2C_Register_SR1);
|
16 | I2C_Send7bitAddress(I2C_Module, deviceAddress, I2C_Direction_Transmitter);
|
17 |
|
18 |
|
19 | debug32[3] |= (1 << 1);
|
20 | }else if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_ADDR) == SET){
|
21 |
|
22 | // EV6
|
23 | I2C_ReadRegister(I2C_Module, I2C_Register_SR1);
|
24 | I2C_ReadRegister(I2C_Module, I2C_Register_SR2);
|
25 | debug32[3] |= (1 << 2);
|
26 |
|
27 | // EV8_1
|
28 | I2C_SendData(I2C_Module, regAddr);
|
29 |
|
30 | if(rxRemainCount != 0){
|
31 | i2cDirectionWrite = 0;
|
32 | debug32[3] |= (1 << 3);
|
33 | }
|
34 |
|
35 | }else if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_TXE) == SET){
|
36 | debug32[3] |= (1 << 4);
|
37 | if(txCount != 0){
|
38 | debug32[3] |= (1 << 5);
|
39 | txCount--;
|
40 | I2C_SendData(I2C_Module, txBuffer[txBufferIndex++]);
|
41 | if(txCount == 0){
|
42 | //letztes byte wurde in DR geschreiben
|
43 | I2C_GenerateSTOP(I2C_Module, ENABLE);
|
44 | debug32[3] |= (1 << 6);
|
45 | }
|
46 | }else if(rxRemainCount != 0){
|
47 | //wird momentan eh nicht ausgeführt
|
48 | debug32[3] |= (1 << 7);
|
49 | i2cDirectionWrite = 0;
|
50 |
|
51 | //I2C_GenerateSTART(I2C_Module, ENABLE);
|
52 | //I2C_SendData(I2C_Module, 0); // um TXE mit Gewalt zu löschen
|
53 | }else if(txCount == 0){
|
54 | debug32[3] |= (1 << 8);
|
55 | i2cBusyFlag = 0;
|
56 | }
|
57 | }
|
58 | }else{
|
59 | debug32[3] |= (1 << 9);
|
60 | if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_SB) == SET){
|
61 | debug32[3] |= (1 << 10);
|
62 | I2C_ReadRegister(I2C_Module, I2C_Register_SR1);
|
63 | I2C_Send7bitAddress(I2C_Module, deviceAddress, I2C_Direction_Receiver);
|
64 | }else if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_ADDR) == SET){
|
65 | debug32[3] |= (1 << 11);
|
66 |
|
67 |
|
68 | //Clear ADDR_Flag
|
69 | I2C_ReadRegister(I2C_Module, I2C_Register_SR1);
|
70 | I2C_ReadRegister(I2C_Module, I2C_Register_SR2);
|
71 | //while(1);
|
72 | //I2C_SendData(I2C_Module, 0); // um TXE mit Gewalt zu löschen
|
73 | //SingleByte Read
|
74 | if(rxRemainCount == 1){
|
75 | debug32[3] |= (1 << 12);
|
76 |
|
77 | I2C_AcknowledgeConfig(I2C_Module, DISABLE);
|
78 | I2C_GenerateSTOP(I2C_Module, ENABLE);
|
79 | }
|
80 |
|
81 |
|
82 | }else if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_BTF) == SET){
|
83 | I2C_GenerateSTART(I2C_Module, ENABLE);
|
84 | //Clear BTF FLag
|
85 | I2C_ReadRegister(I2C_Module, I2C_Register_SR1);
|
86 | I2C_ReceiveData(I2C_Module);
|
87 |
|
88 | }else if(I2C_GetFlagStatus(I2C_Module, I2C_FLAG_RXNE) == SET){
|
89 | debug32[3] |= (1 << 13);
|
90 | rxBuffer[txBufferIndex++] = I2C_ReceiveData(I2C_Module);
|
91 |
|
92 | --rxRemainCount;
|
93 | if(rxRemainCount == 1){
|
94 | debug32[3] |= (1 << 14);
|
95 | I2C_AcknowledgeConfig(I2C_Module, DISABLE);
|
96 | I2C_GenerateSTOP(I2C_Module, ENABLE);
|
97 | }else if(rxRemainCount == 0){
|
98 | debug32[3] |= (1 << 15);
|
99 | i2cBusyFlag = 0;
|
100 | }
|
101 | }
|
102 |
|
103 | }
|
104 | //ledToggle();
|
105 | if(i2c1_EV_ISR_Count < 25){
|
106 | i2cDebug_EV_ISRende[(i2c1_EV_ISR_Count* 2) +1] = I2C_Module->SR2;
|
107 | i2cDebug_EV_ISRende[(i2c1_EV_ISR_Count* 2)] = I2C_Module->SR1;
|
108 |
|
109 | i2cDebug_EV_ISRende_DebugFlags[i2c1_EV_ISR_Count] = debug32[3];
|
110 | }
|
111 |
|
112 | ++i2c1_EV_ISR_Count;
|
113 |
|
114 |
|
115 | }
|