Subversion Repositories FlightCtrl

Rev

Rev 1961 | Rev 1964 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1961 Rev 1963
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur für den privaten und nicht-kommerziellen Gebrauch zulässig ist.
7
// + dass eine Nutzung (auch auszugsweise) nur f�r den privaten und nicht-kommerziellen Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
 
52
 
53
#include <avr/boot.h>
53
#include <avr/boot.h>
54
#include <avr/io.h>
54
#include <avr/io.h>
55
#include <avr/interrupt.h>
55
#include <avr/interrupt.h>
56
#include <util/delay.h>
56
#include <util/delay.h>
57
 
57
 
58
#include "timer0.h"
58
#include "timer0.h"
59
#include "timer2.h"
59
#include "timer2.h"
60
#include "uart0.h"
60
#include "uart0.h"
61
#include "uart1.h"
61
#include "uart1.h"
62
#include "output.h"
62
#include "output.h"
63
#include "menu.h"
63
#include "menu.h"
64
#include "attitude.h"
64
#include "attitude.h"
65
#include "flight.h"
65
#include "flight.h"
66
#include "controlMixer.h"
-
 
67
#include "rc.h"
66
#include "rc.h"
68
#include "analog.h"
67
#include "analog.h"
69
#include "configuration.h"
68
#include "configuration.h"
70
#include "printf_P.h"
69
#include "printf_P.h"
71
#include "twimaster.h"
70
#include "twimaster.h"
72
#ifdef USE_NAVICTRL
71
#ifdef USE_NAVICTRL
73
#include "spi.h"
72
#include "spi.h"
74
#endif
73
#endif
75
#ifdef USE_MK3MAG
74
#ifdef USE_MK3MAG
76
#include "mk3mag.h"
75
#include "mk3mag.h"
77
#endif
76
#endif
78
#include "eeprom.h"
77
#include "eeprom.h"
79
 
78
 
80
int16_t main(void) {
79
int16_t main(void) {
81
  uint16_t timer;
80
  uint16_t timer;
82
 
81
 
83
  // disable interrupts global
82
  // disable interrupts global
84
  cli();
83
  cli();
85
 
84
 
86
  // analyze hardware environment
85
  // analyze hardware environment
87
  CPUType = getCPUType();
86
  CPUType = getCPUType();
88
  boardRelease = getBoardRelease();
87
  boardRelease = getBoardRelease();
89
 
88
 
90
  // disable watchdog
89
  // disable watchdog
91
  MCUSR &= ~(1 << WDRF);
90
  MCUSR &= ~(1 << WDRF);
92
  WDTCSR |= (1 << WDCE) | (1 << WDE);
91
  WDTCSR |= (1 << WDCE) | (1 << WDE);
93
  WDTCSR = 0;
92
  WDTCSR = 0;
94
 
93
 
95
  // PPM_in[CH_THROTTLE] = 0;
94
  // PPM_in[CH_THROTTLE] = 0;
96
  // Why??? They are already initialized to 0.
95
  // Why??? They are already initialized to 0.
97
  // stickPitch = stickRoll = stickYaw = 0;
96
  // stickPitch = stickRoll = stickYaw = 0;
98
 
97
 
99
  RED_OFF;
98
  RED_OFF;
100
 
99
 
101
  // initalize modules
100
  // initalize modules
102
  output_init();
101
  output_init();
103
  timer0_init();
102
  timer0_init();
104
  timer2_init();
103
  timer2_init();
105
  usart0_Init();
104
  usart0_Init();
106
  if (CPUType == ATMEGA644P);// usart1_Init();
105
  if (CPUType == ATMEGA644P);// usart1_Init();
107
  RC_Init();
106
  RC_Init();
108
  analog_init();
107
  analog_init();
109
  I2C_init();
108
  I2C_init();
110
#ifdef USE_NAVICTRL
109
#ifdef USE_NAVICTRL
111
  SPI_MasterInit();
110
  SPI_MasterInit();
112
#endif
111
#endif
113
#ifdef USE_MK3MAG
112
#ifdef USE_MK3MAG
114
  MK3MAG_Init();
113
  MK3MAG_Init();
115
#endif
114
#endif
116
 
115
 
117
  // enable interrupts global
116
  // enable interrupts global
118
  sei();
117
  sei();
119
 
118
 
120
  printf("\n\r===================================");
119
  printf("\n\r===================================");
121
  printf("\n\rFlightControl");
120
  printf("\n\rFlightControl");
122
  printf("\n\rHardware: Custom");
121
  printf("\n\rHardware: Custom");
123
  printf("\r\n     CPU: Atmega644");
122
  printf("\r\n     CPU: Atmega644");
124
  if (CPUType == ATMEGA644P)
123
  if (CPUType == ATMEGA644P)
125
    printf("p");
124
    printf("p");
126
  printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
125
  printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
127
  printf("\n\r===================================");
126
  printf("\n\r===================================");
128
 
127
 
129
  // Parameter Set handling
128
  // Parameter Set handling
130
  channelMap_readOrDefault();
129
  channelMap_readOrDefault();
131
  paramSet_readOrDefault();
130
  paramSet_readOrDefault();
132
 
131
 
133
  // Wait for a short time (otherwise the RC channel check won't work below)
132
  // Wait for a short time (otherwise the RC channel check won't work below)
134
  // timer = SetDelay(500);
133
  // timer = SetDelay(500);
135
  // while(!CheckDelay(timer));
134
  // while(!CheckDelay(timer));
136
 
135
 
137
  // Instead, while away the time by flashing the 2 outputs:
136
  // Instead, while away the time by flashing the 2 outputs:
138
  // First J16, then J17. Makes it easier to see which is which.
137
  // First J16, then J17. Makes it easier to see which is which.
139
  timer = setDelay(200);
138
  timer = setDelay(200);
140
  OUTPUT_SET(0,1);
139
  OUTPUT_SET(0,1);
141
  GRN_OFF;
140
  GRN_OFF;
142
  RED_ON;
141
  RED_ON;
143
  while (!checkDelay(timer))
142
  while (!checkDelay(timer))
144
    ;
143
    ;
145
 
144
 
146
  timer = setDelay(200);
145
  timer = setDelay(200);
147
  OUTPUT_SET(0,0);
146
  OUTPUT_SET(0,0);
148
  OUTPUT_SET(1,1);
147
  OUTPUT_SET(1,1);
149
  RED_OFF;
148
  RED_OFF;
150
  GRN_ON;
149
  GRN_ON;
151
  while (!checkDelay(timer))
150
  while (!checkDelay(timer))
152
    ;
151
    ;
153
 
152
 
154
  timer = setDelay(200);
153
  timer = setDelay(200);
155
  while (!checkDelay(timer))
154
  while (!checkDelay(timer))
156
    ;
155
    ;
157
  OUTPUT_SET(1,0);
156
  OUTPUT_SET(1,0);
158
 
157
 
159
  twi_diagnostics();
158
  twi_diagnostics();
160
 
159
 
161
  printf("\n\r===================================");
160
  printf("\n\r===================================");
162
 
161
 
163
#ifdef USE_NAVICTRL
162
#ifdef USE_NAVICTRL
164
  printf("\n\rSupport for NaviCtrl");
163
  printf("\n\rSupport for NaviCtrl");
165
#ifdef USE_RC_DSL
164
#ifdef USE_RC_DSL
166
  printf("\r\nSupport for DSL RC at 2nd UART");
165
  printf("\r\nSupport for DSL RC at 2nd UART");
167
#endif
166
#endif
168
#ifdef USE_RC_SPECTRUM
167
#ifdef USE_RC_SPECTRUM
169
  printf("\r\nSupport for SPECTRUM RC at 2nd UART");
168
  printf("\r\nSupport for SPECTRUM RC at 2nd UART");
170
#endif
169
#endif
171
#endif
170
#endif
172
 
171
 
173
#ifdef USE_MK3MAG
172
#ifdef USE_MK3MAG
174
  printf("\n\rSupport for MK3MAG Compass");
173
  printf("\n\rSupport for MK3MAG Compass");
175
#endif
174
#endif
176
 
175
 
177
#if (defined (USE_MK3MAG))
176
#if (defined (USE_MK3MAG))
178
  if(CPUType == ATMEGA644P) printf("\n\r2 UART");
177
  if(CPUType == ATMEGA644P) printf("\n\r2 UART");
179
  else printf("\n\r1 UART");
178
  else printf("\n\r1 UART");
180
#endif
179
#endif
181
 
180
 
182
  controlMixer_setNeutral();
181
  controlMixer_setNeutral();
183
 
182
 
184
  // Cal. attitude sensors and reset integrals.
183
  // Cal. attitude sensors and reset integrals.
185
  attitude_setNeutral();
184
  attitude_setNeutral();
186
 
185
 
187
  Servo_On();
186
  Servo_On();
188
 
187
 
189
  // Init flight parameters
188
  // Init flight parameters
190
  flight_setNeutral();
189
  flight_setNeutral();
191
 
190
 
192
  // RED_OFF;
191
  // RED_OFF;
193
 
192
 
194
  beep(2000);
193
  beep(2000);
195
 
194
 
196
  printf("\n\rControl: ");
195
  printf("\n\rControl: ");
197
  if (staticParams.bitConfig & CFG_HEADING_HOLD)
196
  if (staticParams.bitConfig & CFG_HEADING_HOLD)
198
    printf("HeadingHold");
197
    printf("HeadingHold");
199
    else printf("Neutral (ACC-Mode)");
198
    else printf("Neutral (ACC-Mode)");
200
 
199
 
201
  printf("\n\n\r");
200
  printf("\n\n\r");
202
 
201
 
203
  LCD_Clear();
202
  LCD_Clear();
204
 
203
 
205
  I2CTimeout = 5000;
204
  I2CTimeout = 5000;
206
 
205
 
207
  while (1) {
206
  while (1) {
208
    if (runFlightControl) { // control interval
207
    if (runFlightControl) { // control interval
209
      runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0
208
      runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0
210
      if (!analogDataReady) {
209
      if (!analogDataReady) {
211
        debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER;
210
        debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER;
212
      } else {
211
      } else {
213
        debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER;
212
        debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER;
214
 
213
 
215
        J4HIGH;
214
        J4HIGH;
216
        flight_control();
215
        flight_control();
217
        J4LOW;
216
        J4LOW;
218
 
217
 
219
        if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout
218
        if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout
220
          RED_ON;
219
          RED_ON;
221
          if (!I2CTimeout) {
220
          if (!I2CTimeout) {
222
            I2C_Reset();
221
            I2C_Reset();
223
            I2CTimeout = 5;
222
            I2CTimeout = 5;
224
          }
223
          }
225
        } else {
224
        } else {
226
          RED_OFF;
225
          RED_OFF;
227
        }
226
        }
228
 
227
 
229
        // Allow Serial Data Transmit if motors must not updated or motors are not running
228
        // Allow Serial Data Transmit if motors must not updated or motors are not running
230
        if (!runFlightControl || !(MKFlags & MKFLAG_MOTOR_RUN)) {
229
        if (!runFlightControl || !(MKFlags & MKFLAG_MOTOR_RUN)) {
231
          usart0_TransmitTxData();
230
          usart0_TransmitTxData();
232
        }
231
        }
233
 
232
 
234
        usart0_ProcessRxData();
233
        usart0_ProcessRxData();
235
 
234
 
236
        if (checkDelay(timer)) {
235
        if (checkDelay(timer)) {
237
          if (UBat <= UBAT_AT_5V) {
236
          if (UBat <= UBAT_AT_5V) {
238
            // Do nothing. The voltage on the input side of the regulator is <5V;
237
            // Do nothing. The voltage on the input side of the regulator is <5V;
239
            // we must be running off USB power. Keep it quiet.
238
            // we must be running off USB power. Keep it quiet.
240
          } else if (UBat < staticParams.batteryVoltageWarning) {
239
          } else if (UBat < staticParams.batteryVoltageWarning) {
241
            beepBatteryAlarm();
240
            beepBatteryAlarm();
242
          }
241
          }
243
 
242
 
244
#ifdef USE_NAVICTRL
243
#ifdef USE_NAVICTRL
245
          SPI_StartTransmitPacket();
244
          SPI_StartTransmitPacket();
246
          SendSPI = 4;
245
          SendSPI = 4;
247
#endif
246
#endif
248
          timer = setDelay(20); // every 20 ms
247
          timer = setDelay(20); // every 20 ms
249
        }
248
        }
250
        output_update();
249
        output_update();
251
      }
250
      }
252
 
251
 
253
#ifdef USE_NAVICTRL
252
#ifdef USE_NAVICTRL
254
      if(!SendSPI) {
253
      if(!SendSPI) {
255
        // SendSPI is decremented in timer0.c with a rate of 9.765 kHz.
254
        // SendSPI is decremented in timer0.c with a rate of 9.765 kHz.
256
        // within the SPI_TransmitByte() routine the value is set to 4.
255
        // within the SPI_TransmitByte() routine the value is set to 4.
257
        // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz,
256
        // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz,
258
        // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms.
257
        // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms.
259
        SPI_TransmitByte();
258
        SPI_TransmitByte();
260
      }
259
      }
261
#endif
260
#endif
262
    }
261
    }
263
  }
262
  }
264
  return (1);
263
  return (1);
265
}
264
}
266
 
265