Subversion Repositories Projects

Rev

Rev 294 | Show entire file | Regard 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 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));