Rev 294 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 294 | Rev 297 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | #include "ssc.h" |
5 | #include "ssc.h" |
6 | #include "timer0.h" |
6 | #include "timer0.h" |
7 | #include "printf_P.h" |
7 | #include "printf_P.h" |
8 | #include "crc16.h" |
8 | #include "crc16.h" |
Line 9... | Line 9... | ||
9 | 9 | ||
Line 10... | Line 10... | ||
10 | #define _SD_DEBUG |
10 | //#define _SD_DEBUG |
11 | 11 | ||
12 | #define CMD_GO_IDLE_STATE 0x00 /* CMD00: response R1 */ |
12 | #define CMD_GO_IDLE_STATE 0x00 /* CMD00: response R1 */ |
13 | #define CMD_SEND_OP_COND 0x01 /* CMD01: response R1 */ |
13 | #define CMD_SEND_OP_COND 0x01 /* CMD01: response R1 */ |
Line 138... | Line 138... | ||
138 | printf("\r\nCmd=%02X, arg=%04X%04X", CmdNo, (uint16_t)(arg>>16), (uint16_t)(0xFFFF & arg)); |
138 | printf("\r\nCmd=%02X, arg=%04X%04X", CmdNo, (uint16_t)(arg>>16), (uint16_t)(0xFFFF & arg)); |
139 | #endif |
139 | #endif |
140 | SSC_Disable(); // disable chipselect. |
140 | SSC_Disable(); // disable chipselect. |
141 | SSC_PutChar(0xFF); // dummy to sync |
141 | SSC_PutChar(0xFF); // dummy to sync |
142 | SSC_Enable(); // enable chipselect. |
142 | SSC_Enable(); // enable chipselect. |
143 | _delay_loop_2(200); |
- | |
- | 143 | ||
144 | //SDC_WaitForBusy(500); // wait 500ms until card is busy |
144 | SDC_WaitForBusy(500); // wait 500ms until card is busy |
Line 145... | Line 145... | ||
145 | 145 | ||
146 | for (a = 0;a < 6; a++) // send the command sequence to the sdcard (6 bytes) |
146 | for (a = 0;a < 6; a++) // send the command sequence to the sdcard (6 bytes) |
147 | { |
147 | { |
148 | SSC_PutChar(cmd[a]); |
148 | SSC_PutChar(cmd[a]); |
149 | _delay_loop_2(10); |
149 | _delay_loop_2(10); |
150 | } |
150 | } |
151 | // get response byte |
151 | // get response byte |
152 | do |
152 | do |
153 | { |
153 | { |
154 | r1 = SSC_GetChar(); // get byte from sd-card |
154 | r1 = SSC_GetChar(); // get byte from sd-card |
155 | if (timeout++ > 1000) break; |
155 | if (timeout++ > 500) break; |
156 | }while(r1 == 0xFF); // wait for the response byte from sd-card. |
156 | }while(r1 == 0xFF); // wait for the response byte from sd-card. |
157 | #ifdef _SD_DEBUG |
157 | #ifdef _SD_DEBUG |
158 | printf("-->R1=%02X", r1); |
158 | printf("-->R1=%02X", r1); |
159 | #endif |
159 | #endif |
Line 241... | Line 241... | ||
241 | void SDC_PrintCID(uint8_t * pCID) |
241 | void SDC_PrintCID(uint8_t * pCID) |
242 | { |
242 | { |
243 | uint8_t pn[6]; |
243 | uint8_t pn[6]; |
244 | uint16_t temp1, temp2; |
244 | uint16_t temp1, temp2; |
Line 245... | Line 245... | ||
245 | 245 | ||
246 | printf("\r\n Manufacturer ID: %i\r\n", pCID[0]); |
246 | printf("\r\n Manufacturer ID: %i\r\n", pCID[0]); |
247 | memcpy(pn, &pCID[1], 2); |
247 | memcpy(pn, &pCID[1], 2); |
248 | pn[2] = '\0'; // terminate string |
248 | pn[2] = '\0'; // terminate string |
249 | printf(" Application ID: %s\r\n",pn); |
249 | printf(" Application ID: %s\r\n",pn); |
250 | memcpy(pn, &pCID[3], 5); |
250 | memcpy(pn, &pCID[3], 5); |
251 | pn[5] = '\0'; // terminate string |
251 | pn[5] = '\0'; // terminate string |
252 | printf(" Product Name: %s\r\n",pn); |
252 | printf(" Product Name: %s\r\n",pn); |
253 | printf(" Product Rev.: %i.%i\r\n",pCID[8]>>4, pCID[8]&0xF); |
253 | printf(" Product Rev.: %i.%i\r\n",pCID[8]>>4, pCID[8]&0xF); |
254 | printf(" Serial No.: "); |
254 | printf(" Serial No.: "); |
255 | for(temp1 = 0; temp1<4; temp1++) |
255 | for(temp1 = 0; temp1<4; temp1++) |
256 | { |
256 | { |
257 | printf("%02X", pCID[9+temp1]); |
257 | printf("%02X", pCID[9+temp1]); |
258 | } |
258 | } |
259 | printf("\r\n"); |
259 | printf("\r\n"); |
260 | temp1 = pCID[14] & 0x0F; // month |
260 | temp1 = pCID[14] & 0x0F; // month |
261 | temp2 = ((pCID[14]>>4)|(pCID[13]<<4)) + 2000; // year |
261 | temp2 = ((pCID[14]>>4)|(pCID[13]<<4)) + 2000; // year |
262 | printf(" Manufac. Date: %i/%i\r\n\r\n",temp1, temp2); |
262 | printf(" Manufac. Date: %i/%i\r\n\r\n",temp1, temp2); |
Line 263... | Line 263... | ||
263 | } |
263 | } |
264 | 264 | ||
265 | //________________________________________________________________________________________________________________________________________ |
265 | //________________________________________________________________________________________________________________________________________ |
Line 310... | Line 310... | ||
310 | { |
310 | { |
311 | printf("\r\n SSC init..."); |
311 | printf("\r\n SSC init..."); |
312 | SSC_Init(); |
312 | SSC_Init(); |
313 | printf("ok"); |
313 | printf("ok"); |
Line 314... | Line 314... | ||
314 | 314 | ||
Line 315... | Line 315... | ||
315 | _delay_loop_2(1050); |
315 | //_delay_loop_2(1050); |
316 | 316 | ||
317 | printf("\r\n SDC init..."); |
317 | printf("\r\n SDC init..."); |
318 | SDCardInfo.Valid = 0; |
318 | SDCardInfo.Valid = 0; |
Line 516... | Line 516... | ||
516 | } |
516 | } |
Line 517... | Line 517... | ||
517 | 517 | ||
518 | switch(SDCardInfo.Version) |
518 | switch(SDCardInfo.Version) |
519 | { |
519 | { |
520 | case VER_1X: |
520 | case VER_1X: |
521 | printf(" SD-CARD V1.x"); |
521 | printf("\r\n SD-CARD V1.x"); |
522 | break; |
522 | break; |
523 | case VER_20: |
523 | case VER_20: |
524 | printf(" SD-CARD V2.0 or later"); |
524 | printf("\r\n SD-CARD V2.0 or later"); |
525 | default: |
525 | default: |
526 | break; |
526 | break; |
527 | } |
527 | } |
528 | uint16_t mb_size = (uint16_t)(SDCardInfo.Capacity/(1024L*1024L)); |
528 | uint16_t mb_size = (uint16_t)(SDCardInfo.Capacity/(1024L*1024L)); |