Rev 23 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | Rev 171 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include "main.h" |
57 | #include "main.h" |
58 | 58 | ||
59 | u8 I2C_RxBufferSize, I2C_TxBufferSize; |
59 | u8 I2C_RxBufferSize, I2C_TxBufferSize; |
60 | u8 *I2C_TxBuffer, *I2C_RxBuffer; |
60 | u8 *I2C_TxBuffer, *I2C_RxBuffer; |
61 | u8 Tx_Idx=0, Rx_Idx=0, I2C_Direction; |
61 | u8 Tx_Idx=0, Rx_Idx=0, I2C_Direction; |
62 | u8 I2C_Command; |
62 | u8 I2C_Command; |
63 | 63 | ||
64 | struct str_I2C_Heading I2C_Heading; |
64 | struct str_I2C_Heading I2C_Heading; |
65 | struct str_I2C_WriteNickRoll I2C_WriteNickRoll; |
65 | struct str_I2C_WriteNickRoll I2C_WriteNickRoll; |
66 | struct str_I2C_Mag I2C_Mag; |
66 | struct str_I2C_Mag I2C_Mag; |
67 | struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM; |
67 | struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM; |
68 | struct str_I2C_Version I2C_Version; |
68 | struct str_I2C_Version I2C_Version; |
69 | struct str_I2C_WriteCal I2C_WriteCal; |
69 | struct str_I2C_WriteCal I2C_WriteCal; |
70 | u8 CompassUpdateActiv = 0; |
70 | u8 CompassUpdateActiv = 0; |
71 | u8 CompassCalState = 0; |
71 | u8 CompassCalState = 0; |
72 | volatile u8 I2C_ReadRequest = 0; |
72 | volatile u8 I2C_ReadRequest = 0; |
73 | 73 | ||
74 | //-------------------------------------------------------------- |
74 | //-------------------------------------------------------------- |
75 | void I2C1_Init(void) |
75 | void I2C1_Init(void) |
76 | { |
76 | { |
77 | I2C_InitTypeDef I2C_Struct; |
77 | I2C_InitTypeDef I2C_Struct; |
78 | GPIO_InitTypeDef GPIO_Struct; |
78 | GPIO_InitTypeDef GPIO_Struct; |
79 | 79 | ||
80 | SerialPutString("I2C init..."); |
80 | SerialPutString("I2C init..."); |
81 | SCU_APBPeriphClockConfig(__I2C1,ENABLE); |
81 | SCU_APBPeriphClockConfig(__I2C1,ENABLE); |
82 | I2C_DeInit(I2C1); |
82 | I2C_DeInit(I2C1); |
83 | 83 | ||
84 | GPIO_Struct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; |
84 | GPIO_Struct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; |
85 | GPIO_Struct.GPIO_Type = GPIO_Type_OpenCollector; |
85 | GPIO_Struct.GPIO_Type = GPIO_Type_OpenCollector; |
86 | GPIO_Struct.GPIO_IPConnected = GPIO_IPConnected_Enable; |
86 | GPIO_Struct.GPIO_IPConnected = GPIO_IPConnected_Enable; |
87 | GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2; |
87 | GPIO_Struct.GPIO_Alternate=GPIO_OutputAlt2; |
88 | GPIO_Init(GPIO2, &GPIO_Struct); |
88 | GPIO_Init(GPIO2, &GPIO_Struct); |
89 | 89 | ||
90 | I2C_Struct.I2C_GeneralCall = I2C_GeneralCall_Disable; |
90 | I2C_Struct.I2C_GeneralCall = I2C_GeneralCall_Disable; |
91 | I2C_Struct.I2C_Ack = I2C_Ack_Enable; |
91 | I2C_Struct.I2C_Ack = I2C_Ack_Enable; |
92 | I2C_Struct.I2C_CLKSpeed = 20000; |
92 | I2C_Struct.I2C_CLKSpeed = 20000; |
93 | I2C_Struct.I2C_OwnAddress = I2C_SLAVE_ADDRESS; |
93 | I2C_Struct.I2C_OwnAddress = I2C_SLAVE_ADDRESS; |
94 | I2C_Init(I2C1, &I2C_Struct); |
94 | I2C_Init(I2C1, &I2C_Struct); |
95 | 95 | ||
96 | I2C_Cmd(I2C1, ENABLE); |
96 | I2C_Cmd(I2C1, ENABLE); |
97 | I2C_ITConfig(I2C1, ENABLE); |
97 | I2C_ITConfig(I2C1, ENABLE); |
98 | 98 | ||
99 | VIC_Config(I2C1_ITLine,VIC_IRQ , 8); |
99 | VIC_Config(I2C1_ITLine,VIC_IRQ , 8); |
100 | VIC_ITCmd(I2C1_ITLine, ENABLE); |
100 | VIC_ITCmd(I2C1_ITLine, ENABLE); |
101 | 101 | ||
102 | I2C_Heading.Heading = 0; |
102 | I2C_Heading.Heading = 0; |
103 | SerialPutString("ok\n\r"); |
103 | SerialPutString("ok\n\r"); |
104 | 104 | ||
105 | 105 | ||
106 | } |
106 | } |
107 | 107 | ||
108 | //-------------------------------------------------------------- |
108 | //-------------------------------------------------------------- |
109 | void I2C1_IRQHandler(void) |
109 | void I2C1_IRQHandler(void) |
110 | { |
110 | { |
111 | 111 | ||
112 | switch (I2C_GetLastEvent(I2C1)) |
112 | switch (I2C_GetLastEvent(I2C1)) |
113 | { |
113 | { |
114 | case I2C_EVENT_MASTER_MODE_SELECT: // EV5 |
114 | case I2C_EVENT_MASTER_MODE_SELECT: // EV5 |
115 | Tx_Idx = 0; |
115 | Tx_Idx = 0; |
116 | Rx_Idx = 0; |
116 | Rx_Idx = 0; |
117 | I2C_Send7bitAddress(I2C1, I2C_SLAVE_ADDRESS, I2C_Direction); |
117 | I2C_Send7bitAddress(I2C1, I2C_SLAVE_ADDRESS, I2C_Direction); |
118 | // DebugOut.Analog[16]++; |
118 | // DebugOut.Analog[16]++; |
119 | break; |
119 | break; |
120 | 120 | ||
121 | case I2C_EVENT_MASTER_MODE_SELECTED: // EV6 |
121 | case I2C_EVENT_MASTER_MODE_SELECTED: // EV6 |
122 | // Clear EV6 by set again the PE bit |
122 | // Clear EV6 by set again the PE bit |
123 | I2C1->CR |= 0x20; |
123 | I2C1->CR |= 0x20; |
124 | if (I2C_Direction == I2C_MODE_TRANSMITTER) |
124 | if (I2C_Direction == I2C_MODE_TRANSMITTER) |
125 | { |
125 | { |
126 | I2C_SendData(I2C1, I2C_Command);//EV8 just after EV6 |
126 | I2C_SendData(I2C1, I2C_Command);//EV8 just after EV6 |
127 | } |
127 | } |
128 | break; |
128 | break; |
129 | 129 | ||
130 | case I2C_EVENT_MASTER_BYTE_TRANSMITTED: // EV8 |
130 | case I2C_EVENT_MASTER_BYTE_TRANSMITTED: // EV8 |
131 | // DebugOut.Analog[17]++; |
131 | // DebugOut.Analog[17]++; |
132 | if ( Tx_Idx >= I2C_TxBufferSize ) |
132 | if ( Tx_Idx >= I2C_TxBufferSize ) |
133 | { |
133 | { |
134 | I2C_GenerateSTOP (I2C1, ENABLE); |
134 | I2C_GenerateSTOP (I2C1, ENABLE); |
135 | Tx_Idx = 0; |
135 | Tx_Idx = 0; |
136 | if (I2C_RxBufferSize > 0) // wird Antwort erwartet ? |
136 | if (I2C_RxBufferSize > 0) // wird Antwort erwartet ? |
137 | { |
137 | { |
138 | I2C_ReadRequest = 1; |
138 | I2C_ReadRequest = 1; |
139 | TimerI2CReadDelay = SetDelay(10); |
139 | TimerI2CReadDelay = SetDelay(10); |
140 | } |
140 | } |
141 | } |
141 | } |
142 | else |
142 | else |
143 | { |
143 | { |
144 | I2C_SendData(I2C1, I2C_TxBuffer[Tx_Idx]); |
144 | I2C_SendData(I2C1, I2C_TxBuffer[Tx_Idx]); |
145 | Tx_Idx++; |
145 | Tx_Idx++; |
146 | } |
146 | } |
147 | break; |
147 | break; |
148 | 148 | ||
149 | case I2C_EVENT_MASTER_BYTE_RECEIVED: // EV7 |
149 | case I2C_EVENT_MASTER_BYTE_RECEIVED: // EV7 |
150 | DebugOut.Analog[16]++; |
150 | DebugOut.Analog[16]++; |
151 | //if (Rx_Idx == 1) DebugOut.Analog[19] = I2C_RxBuffer[0]; |
151 | //if (Rx_Idx == 1) DebugOut.Analog[19] = I2C_RxBuffer[0]; |
152 | if (Rx_Idx < I2C_RxBufferSize) |
152 | if (Rx_Idx < I2C_RxBufferSize) |
153 | { I2C_RxBuffer[Rx_Idx] = I2C_ReceiveData(I2C1); |
153 | { I2C_RxBuffer[Rx_Idx] = I2C_ReceiveData(I2C1); |
154 | 154 | ||
155 | } else I2C_ReceiveData(I2C1); |
155 | } else I2C_ReceiveData(I2C1); |
156 | 156 | ||
157 | Rx_Idx++; |
157 | Rx_Idx++; |
158 | if ( Rx_Idx == I2C_RxBufferSize-2 ) |
158 | if ( Rx_Idx == I2C_RxBufferSize-2 ) |
159 | { |
159 | { |
160 | I2C_AcknowledgeConfig (I2C1, DISABLE); |
160 | I2C_AcknowledgeConfig (I2C1, DISABLE); |
161 | } |
161 | } |
162 | if ( Rx_Idx == I2C_RxBufferSize -1 ) |
162 | if ( Rx_Idx == I2C_RxBufferSize -1 ) |
163 | { |
163 | { |
164 | I2C_GenerateSTOP(I2C1, ENABLE); |
164 | I2C_GenerateSTOP(I2C1, ENABLE); |
165 | if (I2C_Command == I2C_CMD_READ_HEADING) CompassUpdateActiv = 0; |
165 | if (I2C_Command == I2C_CMD_READ_HEADING) CompassUpdateActiv = 0; |
166 | } |
166 | } |
167 | break; |
167 | break; |
168 | 168 | ||
169 | default: |
169 | default: |
170 | break; |
170 | break; |
171 | } |
171 | } |
172 | } |
172 | } |
173 | //---------------------------------------------------------------- |
173 | //---------------------------------------------------------------- |
174 | void SendI2C_Command(u8 command) |
174 | void SendI2C_Command(u8 command) |
175 | { |
175 | { |
176 | I2C_Command = command; |
176 | I2C_Command = command; |
177 | //I2C_GenerateSTOP(I2C1, ENABLE); |
177 | //I2C_GenerateSTOP(I2C1, ENABLE); |
178 | 178 | ||
179 | switch (command) |
179 | switch (command) |
180 | { |
180 | { |
181 | case I2C_CMD_VERSION: |
181 | case I2C_CMD_VERSION: |
182 | I2C_RxBuffer = (u8 *)&I2C_Version; |
182 | I2C_RxBuffer = (u8 *)&I2C_Version; |
183 | I2C_RxBufferSize = sizeof(I2C_Version); |
183 | I2C_RxBufferSize = sizeof(I2C_Version); |
184 | I2C_TxBufferSize = 0; |
184 | I2C_TxBufferSize = 0; |
185 | break; |
185 | break; |
186 | case I2C_CMD_WRITE_EEPROM: |
186 | case I2C_CMD_WRITE_EEPROM: |
187 | I2C_RxBufferSize = 0; |
187 | I2C_RxBufferSize = 0; |
188 | I2C_TxBuffer = (u8 *)&I2C_WriteEEPROM; |
188 | I2C_TxBuffer = (u8 *)&I2C_WriteEEPROM; |
189 | I2C_TxBufferSize = sizeof(I2C_WriteEEPROM); |
189 | I2C_TxBufferSize = sizeof(I2C_WriteEEPROM); |
190 | break; |
190 | break; |
191 | case I2C_CMD_WRITE_CAL: |
191 | case I2C_CMD_WRITE_CAL: |
192 | I2C_RxBufferSize = 0; |
192 | I2C_RxBufferSize = 0; |
193 | I2C_WriteCal.CalByte = CompassCalState; |
193 | I2C_WriteCal.CalByte = CompassCalState; |
194 | I2C_TxBuffer = (u8 *)&I2C_WriteCal; |
194 | I2C_TxBuffer = (u8 *)&I2C_WriteCal; |
195 | I2C_TxBufferSize = sizeof(I2C_WriteCal); |
195 | I2C_TxBufferSize = sizeof(I2C_WriteCal); |
196 | break; |
196 | break; |
197 | case I2C_CMD_READ_EEPROM: |
197 | case I2C_CMD_READ_EEPROM: |
198 | I2C_RxBuffer = (u8 *)&I2C_ReadEEPROM.Inhalt; |
198 | I2C_RxBuffer = (u8 *)&I2C_ReadEEPROM.Inhalt; |
199 | I2C_RxBufferSize = 2; |
199 | I2C_RxBufferSize = 2; |
200 | I2C_TxBuffer = (u8 *)&I2C_ReadEEPROM; |
200 | I2C_TxBuffer = (u8 *)&I2C_ReadEEPROM; |
201 | I2C_TxBufferSize = 1; |
201 | I2C_TxBufferSize = 1; |
202 | break; |
202 | break; |
203 | case I2C_CMD_READ_MAG: |
203 | case I2C_CMD_READ_MAG: |
204 | I2C_RxBuffer = (u8 *)&I2C_Mag; |
204 | I2C_RxBuffer = (u8 *)&I2C_Mag; |
205 | I2C_RxBufferSize = sizeof(I2C_Mag); |
205 | I2C_RxBufferSize = sizeof(I2C_Mag); |
206 | I2C_TxBufferSize = 0; |
206 | I2C_TxBufferSize = 0; |
207 | break; |
207 | break; |
208 | case I2C_CMD_READ_HEADING: |
208 | case I2C_CMD_READ_HEADING: |
209 | CompassUpdateActiv = 1; |
209 | CompassUpdateActiv = 1; |
210 | I2C_RxBuffer = (u8 *)&I2C_Heading; |
210 | I2C_RxBuffer = (u8 *)&I2C_Heading; |
211 | I2C_RxBufferSize = sizeof(I2C_Heading); |
211 | I2C_RxBufferSize = sizeof(I2C_Heading); |
212 | I2C_TxBuffer = (u8 *)&I2C_WriteNickRoll; |
212 | I2C_TxBuffer = (u8 *)&I2C_WriteNickRoll; |
213 | I2C_TxBufferSize = sizeof(I2C_WriteNickRoll); |
213 | I2C_TxBufferSize = sizeof(I2C_WriteNickRoll); |
214 | break; |
214 | break; |
215 | 215 | ||
216 | } |
216 | } |
217 | if (I2C_RxBufferSize > 0) |
217 | if (I2C_RxBufferSize > 0) |
218 | { |
218 | { |
219 | I2C_RxBufferSize++; |
219 | I2C_RxBufferSize++; |
220 | if (I2C_RxBufferSize < 3) I2C_RxBufferSize = 3; |
220 | if (I2C_RxBufferSize < 3) I2C_RxBufferSize = 3; |
221 | } |
221 | } |
222 | 222 | ||
223 | I2C_AcknowledgeConfig (I2C1, ENABLE); |
223 | I2C_AcknowledgeConfig (I2C1, ENABLE); |
224 | I2C_Direction = I2C_MODE_TRANSMITTER; |
224 | I2C_Direction = I2C_MODE_TRANSMITTER; |
225 | 225 | ||
226 | I2C_GenerateStart(I2C1, ENABLE); |
226 | I2C_GenerateStart(I2C1, ENABLE); |
227 | 227 | ||
228 | } |
228 | } |
229 | 229 |