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 | //________________________________________________________________________________________________________________________________________ |
59 | //________________________________________________________________________________________________________________________________________ |
60 | // Module name: fat16.c |
60 | // Module name: fat16.c |
61 | // Compiler used: avr-gcc 3.4.5 |
61 | // Compiler used: avr-gcc 3.4.5 |
62 | // Last Modifikation: 24.07.2007 |
62 | // Last Modifikation: 24.07.2007 |
63 | // Version: 1.02 |
63 | // Version: 1.02 |
64 | // Authors: Stephan Busker |
64 | // Authors: Stephan Busker |
65 | // Description: Source files for access to the synchrnous serial channel. |
65 | // Description: Source files for access to the synchrnous serial channel. |
66 | // Copyright (C) 2007 Stephan Busker |
66 | // Copyright (C) 2007 Stephan Busker |
67 | //........................................................................................................................................ |
67 | //........................................................................................................................................ |
68 | // Functions: extern void SSC_Init(void); |
68 | // Functions: extern void SSC_Init(void); |
69 | // extern u8 SSC_GetChar (void); |
69 | // extern u8 SSC_GetChar (void); |
70 | // extern void SSC_PutChar (u8 Byte); |
70 | // extern void SSC_PutChar (u8 Byte); |
71 | // extern void SSC_Disable(void); |
71 | // extern void SSC_Disable(void); |
72 | // extern void SSC_Enable(void); |
72 | // extern void SSC_Enable(void); |
73 | //........................................................................................................................................ |
73 | //........................................................................................................................................ |
74 | // ext. functions: extern u8 SDC_GetSector (unsigned long,u8 *); |
74 | // ext. functions: extern u8 SDC_GetSector (unsigned long,u8 *); |
75 | // extern u8 SDC_PutSector (unsigned long,u8 *); |
75 | // extern u8 SDC_PutSector (unsigned long,u8 *); |
76 | //........................................................................................................................................ |
76 | //........................................................................................................................................ |
77 | // |
77 | // |
78 | // URL: www.Mikro-Control.de |
78 | // URL: www.Mikro-Control.de |
79 | // mailto: stephan.busker@mikro-control.de |
79 | // mailto: stephan.busker@mikro-control.de |
80 | //________________________________________________________________________________________________________________________________________ |
80 | //________________________________________________________________________________________________________________________________________ |
81 | 81 | ||
82 | 82 | ||
83 | 83 | ||
84 | 84 | ||
85 | //________________________________________________________________________________________________________________________________________ |
85 | //________________________________________________________________________________________________________________________________________ |
86 | // Funtion: SSC_Init(void); |
86 | // Funtion: SSC_Init(void); |
87 | // |
87 | // |
88 | // Description: This function initialises the synchronus serial channel to the sdcard. |
88 | // Description: This function initialises the synchronus serial channel to the sdcard. |
89 | // |
89 | // |
90 | // |
90 | // |
91 | // Returnvalue: none |
91 | // Returnvalue: none |
92 | //________________________________________________________________________________________________________________________________________ |
92 | //________________________________________________________________________________________________________________________________________ |
93 | 93 | ||
94 | void SSC_Init(void) |
94 | void SSC_Init(void) |
95 | { |
95 | { |
96 | 96 | ||
97 | SerialPutString("SPI1 init..."); |
97 | SerialPutString("SPI1 init..."); |
98 | 98 | ||
99 | GPIO_InitTypeDef GPIO_InitStructure; |
99 | GPIO_InitTypeDef GPIO_InitStructure; |
100 | SSP_InitTypeDef SSP_InitStructure; |
100 | SSP_InitTypeDef SSP_InitStructure; |
101 | 101 | ||
102 | SCU_APBPeriphClockConfig(__SSP1 ,ENABLE); |
102 | SCU_APBPeriphClockConfig(__SSP1 ,ENABLE); |
103 | 103 | ||
104 | // GPIO_DeInit(GPIO2); |
104 | // GPIO_DeInit(GPIO2); |
105 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
105 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
106 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6; |
106 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6; |
107 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
107 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
108 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
108 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
109 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; |
109 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; |
110 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
110 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
111 | 111 | ||
112 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
112 | GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; |
113 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
113 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; |
114 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
114 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; |
115 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
115 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Disable; |
116 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; |
116 | GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; |
117 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
117 | GPIO_Init (GPIO5, &GPIO_InitStructure); |
118 | 118 | ||
119 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
119 | GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; |
120 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
120 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; |
121 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
121 | GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull; |
122 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
122 | GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; |
123 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
123 | GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; |
124 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
124 | GPIO_Init (GPIO3, &GPIO_InitStructure); |
125 | 125 | ||
126 | SSP_DeInit(SSP1); |
126 | SSP_DeInit(SSP1); |
127 | SSP_StructInit(&SSP_InitStructure); |
127 | SSP_StructInit(&SSP_InitStructure); |
128 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
128 | SSP_InitStructure.SSP_FrameFormat = SSP_FrameFormat_Motorola; |
129 | SSP_InitStructure.SSP_Mode = SSP_Mode_Master; |
129 | SSP_InitStructure.SSP_Mode = SSP_Mode_Master; |
130 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
130 | SSP_InitStructure.SSP_CPHA = SSP_CPHA_1Edge; |
131 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
131 | SSP_InitStructure.SSP_CPOL = SSP_CPOL_Low; |
132 | // Hier muss die Baudrate noch richtig eingestellt werden (mit Prescaler) |
132 | // Hier muss die Baudrate noch richtig eingestellt werden (mit Prescaler) |
133 | SSP_InitStructure.SSP_ClockRate = 5; |
133 | SSP_InitStructure.SSP_ClockRate = 5; |
134 | SSP_InitStructure.SSP_ClockPrescaler = 8; |
134 | SSP_InitStructure.SSP_ClockPrescaler = 8; |
135 | SSP_Init(SSP1, &SSP_InitStructure); |
135 | SSP_Init(SSP1, &SSP_InitStructure); |
136 | SSC_Disable(); |
136 | SSC_Disable(); |
137 | SSP_Cmd(SSP1, ENABLE); |
137 | SSP_Cmd(SSP1, ENABLE); |
138 | /* MMC_Direction_REG &=~(1<<SPI_DI); // Set the direction of the ssc-port |
138 | /* MMC_Direction_REG &=~(1<<SPI_DI); // Set the direction of the ssc-port |
139 | MMC_Direction_REG |= (1<<SPI_Clock); // _______ _______ |
139 | MMC_Direction_REG |= (1<<SPI_Clock); // _______ _______ |
140 | MMC_Direction_REG |= (1<<SPI_DO); // CS \________________________/ |
140 | MMC_Direction_REG |= (1<<SPI_DO); // CS \________________________/ |
141 | MMC_Direction_REG |= (1<<MMC_Chip_Select); // |
141 | MMC_Direction_REG |= (1<<MMC_Chip_Select); // |
142 | MMC_Direction_REG |= (1<<SPI_SS); // ___ ___ ___ |
142 | MMC_Direction_REG |= (1<<SPI_SS); // ___ ___ ___ |
143 | // clk __________/ \___/ \___/ \_________ |
143 | // clk __________/ \___/ \___/ \_________ |
144 | // |
144 | // |
145 | // ___ ___ |
145 | // ___ ___ |
146 | // data_________/ \___________/ \___________ |
146 | // data_________/ \___________/ \___________ |
147 | 147 | ||
148 | // initialise ssc, clock = Idel low |
148 | // initialise ssc, clock = Idel low |
149 | // devide clock by 32 |
149 | // devide clock by 32 |
150 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<CPOL); // Enable SSC in mastermode, invert clockpolarity (idle high) |
150 | SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<CPOL); // Enable SSC in mastermode, invert clockpolarity (idle high) |
151 | SPSR = SPSR|(1<<SPI2X);*/ |
151 | SPSR = SPSR|(1<<SPI2X);*/ |
152 | 152 | ||
153 | SerialPutString("ok\n\r"); |
153 | SerialPutString("ok\n\r"); |
154 | } |
154 | } |
155 | 155 | ||
156 | 156 | ||
157 | //________________________________________________________________________________________________________________________________________ |
157 | //________________________________________________________________________________________________________________________________________ |
158 | // Funtion: SSC_GetChar(void); |
158 | // Funtion: SSC_GetChar(void); |
159 | // |
159 | // |
160 | // Description: This function reads one byte from the SSC |
160 | // Description: This function reads one byte from the SSC |
161 | // |
161 | // |
162 | // |
162 | // |
163 | // Returnvalue: the byte received. |
163 | // Returnvalue: the byte received. |
164 | //________________________________________________________________________________________________________________________________________ |
164 | //________________________________________________________________________________________________________________________________________ |
165 | 165 | ||
166 | u8 SSC_GetChar (void) |
166 | u8 SSC_GetChar (void) |
167 | { |
167 | { |
168 | u8 Byte = 0; |
168 | u8 Byte = 0; |
169 | // SerialPutString("\n\rGetChar."); |
169 | // SerialPutString("\n\rGetChar."); |
170 | SSP_SendData(SSP1, 0xFF); |
170 | SSP_SendData(SSP1, 0xFF); |
171 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); |
171 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); |
172 | Byte = SSP_ReceiveData(SSP1); |
172 | Byte = SSP_ReceiveData(SSP1); |
173 | /* SPDR = 0x00; // read one byte of data from the SSC |
173 | /* SPDR = 0x00; // read one byte of data from the SSC |
174 | while(!(SPSR & (1<<SPIF))){}; // wait until the data has been read. |
174 | while(!(SPSR & (1<<SPIF))){}; // wait until the data has been read. |
175 | Byte = SPDR; |
175 | Byte = SPDR; |
176 | */ |
176 | */ |
177 | // sprintf(text," %02X ", Byte); SerialPutString(text);SerialPutString("done."); |
177 | // sprintf(text," %02X ", Byte); SerialPutString(text);SerialPutString("done."); |
178 | return (Byte); |
178 | return (Byte); |
179 | 179 | ||
180 | } |
180 | } |
181 | 181 | ||
182 | //________________________________________________________________________________________________________________________________________ |
182 | //________________________________________________________________________________________________________________________________________ |
183 | void SSC_ClearRxFifo (void) |
183 | void SSC_ClearRxFifo (void) |
184 | { |
184 | { |
185 | // SerialPutString("\n\rClr RxFifo "); |
185 | // SerialPutString("\n\rClr RxFifo "); |
186 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); |
186 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoEmpty) != SET); |
187 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1); |
187 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_RxFifoNotEmpty) == SET) SSP_ReceiveData(SSP1); |
188 | // SerialPutString("done."); |
188 | // SerialPutString("done."); |
189 | } |
189 | } |
190 | //________________________________________________________________________________________________________________________________________ |
190 | //________________________________________________________________________________________________________________________________________ |
191 | // Funtion: SSC_PutChar(u8 Byte); |
191 | // Funtion: SSC_PutChar(u8 Byte); |
192 | // |
192 | // |
193 | // Description: This function writes one byte to the SSC |
193 | // Description: This function writes one byte to the SSC |
194 | // |
194 | // |
195 | // |
195 | // |
196 | // Returnvalue: none |
196 | // Returnvalue: none |
197 | //________________________________________________________________________________________________________________________________________ |
197 | //________________________________________________________________________________________________________________________________________ |
198 | 198 | ||
199 | void SSC_PutChar (u8 Byte) |
199 | void SSC_PutChar (u8 Byte) |
200 | { |
200 | { |
201 | //SerialPutString("\n\rPutChar."); sprintf(text," %02X ", Byte); SerialPutString(text); |
201 | //SerialPutString("\n\rPutChar."); sprintf(text," %02X ", Byte); SerialPutString(text); |
202 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET); |
202 | while(SSP_GetFlagStatus(SSP1, SSP_FLAG_TxFifoNotFull) != SET); |
203 | SSP_SendData(SSP1, Byte); |
203 | SSP_SendData(SSP1, Byte); |
204 | //SerialPutString("done."); |
204 | //SerialPutString("done."); |
205 | 205 | ||
206 | } |
206 | } |
207 | 207 | ||
208 | 208 | ||
209 | //________________________________________________________________________________________________________________________________________ |
209 | //________________________________________________________________________________________________________________________________________ |
210 | // Funtion: SSC_Disable(void); |
210 | // Funtion: SSC_Disable(void); |
211 | // |
211 | // |
212 | // Description: This function enables chipselect of the sdcard (active low) |
212 | // Description: This function enables chipselect of the sdcard (active low) |
213 | // |
213 | // |
214 | // |
214 | // |
215 | // Returnvalue: none |
215 | // Returnvalue: none |
216 | //________________________________________________________________________________________________________________________________________ |
216 | //________________________________________________________________________________________________________________________________________ |
217 | 217 | ||
218 | void SSC_Disable(void) |
218 | void SSC_Disable(void) |
219 | { |
219 | { |
220 | //MMC_Write &= ~(1<<MMC_Chip_Select); // disable chipselect of the sdcard (active low). |
220 | //MMC_Write &= ~(1<<MMC_Chip_Select); // disable chipselect of the sdcard (active low). |
221 | GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET); |
221 | GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_SET); |
222 | } |
222 | } |
223 | 223 | ||
224 | 224 | ||
225 | 225 | ||
226 | 226 | ||
227 | //________________________________________________________________________________________________________________________________________ |
227 | //________________________________________________________________________________________________________________________________________ |
228 | // Funtion: SSC_Enable(void); |
228 | // Funtion: SSC_Enable(void); |
229 | // |
229 | // |
230 | // Description: This function disables chipselect of the sdcard (active low) |
230 | // Description: This function disables chipselect of the sdcard (active low) |
231 | // |
231 | // |
232 | // |
232 | // |
233 | // Returnvalue: none |
233 | // Returnvalue: none |
234 | //________________________________________________________________________________________________________________________________________ |
234 | //________________________________________________________________________________________________________________________________________ |
235 | 235 | ||
236 | void SSC_Enable(void) |
236 | void SSC_Enable(void) |
237 | { |
237 | { |
238 | //MMC_Write |= (1<<MMC_Chip_Select); // enable chipselect of the sdcard (active low). |
238 | //MMC_Write |= (1<<MMC_Chip_Select); // enable chipselect of the sdcard (active low). |
239 | GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET); |
239 | GPIO_WriteBit(GPIO5, GPIO_Pin_4 , Bit_RESET); |
240 | } |
240 | } |
241 | 241 |