Rev 1 | Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 37 | ||
---|---|---|---|
Line 5... | Line 5... | ||
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 |
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 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 this software (or part of it) to systems (other than 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 |
Line 50... | Line 50... | ||
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" |
Line 58... | Line 58... | ||
58 | 58 | ||
59 | u8 I2C_RxBufferSize, I2C_TxBufferSize; |
59 | u8 I2C_RxBufferSize, I2C_TxBufferSize; |
Line 62... | Line 62... | ||
62 | u8 I2C_Command; |
62 | u8 I2C_Command; |
Line 63... | Line 63... | ||
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; |
Line 74... | Line 74... | ||
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); |
Line 83... | Line 83... | ||
83 | 83 | ||
Line 90... | Line 90... | ||
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); |
Line 101... | Line 101... | ||
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 | ||
Line 106... | Line 106... | ||
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 |
Line 120... | Line 120... | ||
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 | } |
Line 128... | Line 128... | ||
128 | break; |
128 | break; |
Line 143... | Line 143... | ||
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+1 ) |
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+2 ) |
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; |
Line 168... | Line 168... | ||
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; |
Line 177... | Line 177... | ||
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: |
Line 207... | Line 207... | ||
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; |
Line 215... | Line 215... | ||
215 | 215 | ||
- | 216 | } |
|
216 | } |
217 | /* |
217 | if (I2C_RxBufferSize > 0) |
218 | if (I2C_RxBufferSize > 0) |
218 | { |
219 | { |
219 | I2C_RxBufferSize++; |
220 | I2C_RxBufferSize++; |
220 | if (I2C_RxBufferSize < 3) I2C_RxBufferSize = 3; |
221 | if (I2C_RxBufferSize < 3) I2C_RxBufferSize = 3; |
Line 221... | Line 222... | ||
221 | } |
222 | }*/ |
222 | 223 | ||
223 | I2C_AcknowledgeConfig (I2C1, ENABLE); |
224 | I2C_AcknowledgeConfig (I2C1, ENABLE); |
224 | I2C_Direction = I2C_MODE_TRANSMITTER; |
225 | I2C_Direction = I2C_MODE_TRANSMITTER; |
Line 225... | Line 226... | ||
225 | 226 |