Forum: Mikrocontroller und Digitale Elektronik Chipselect einer SD Karte


von Christian F. (christianf)


Lesenswert?

Moin !

Ich bin mittlerweile komplett "durcheinander" und zwar was hat es nun 
mit dem Chipselect der SD Karte auf sich? Ferner wie ist er zu setzen.

Folgendes habe ich rausgelesen:

() nachdem die Karte angeschaltet wurde mit CS -> HIGH 74~ Dummyclocks 
gesendet werden.

() Danach CS -> LOW ziehen.

und jetzt teilen sich irgendwie die Meinungen.

1. Laut http://elm-chan.org/docs/mmc/mmc_e.html :

The CS signal must set low prior to send a command frame and held low 
during the transaction (command, response and data transfer if exist)

-> Also vor jedem Command CS -> LOW und danach CS -> High.

2. Nun hat "Flo" eine anderen Ansatz

Beitrag "SD Karte via ATmega644 und SPI ansprechen"

CS -> LOW
-> komplette initialisierung mit CMD0 CMD8 etc...
CS -> HIGH

3. Ein anderer Weg ist nach jedem Byte das CS zu togglen.


Nun meine Frage:

Wie ist das CS Signal zu handhaben?

von Christian F. (christianf)


Lesenswert?

Anders ausgedrückt, ich wollte nun so verfahren :
1
Xuint8  sd_send_cmd(Xuint8 Command, Xuint16 ParameterX, Xuint16 ParameterY)
2
  {
3
    Xuint8 response;
4
    XIo_Out32((SPI_BASE_ADDRESS)+ SPI_Slave_Select_Register, CS_LOW);           // CS -> LOW
5
    delay(50);                                       // wait some CLKs for stable CLK Signal
6
7
        spi_send_byte(0x40 | Command);                            //send the command
8
9
        spi_send_byte((Xuint8) (ParameterX >> 8));                             //send the MSB of ParamX
10
11
        spi_send_byte((Xuint8) (ParameterX));                                    //send the LSB of ParamX
12
13
        spi_send_byte((Xuint8) (ParameterY >> 8));                              //send the MSB of ParamY
14
15
        spi_send_byte((Xuint8) (ParameterY));                                    //send the LSB of ParamY
16
17
        switch(Command)
18
        {
19
          case CMD8:
20
            //when sending the IF cond (CMD8) we must always send
21
            //the correct CRC
22
            spi_send_byte(0x87);
23
            break;
24
25
          case CMD0:
26
            //CMD0 = 0x95 CRC
27
          spi_send_byte(0x95);
28
            break;
29
30
          default:
31
            //for all other commands, CRC is ignored in SPI mode.
32
          spi_send_byte(0xFF);
33
            break;
34
        }
35
36
    response = spi_read_byte();                              // read the SD response
37
38
39
    XIo_Out32((SPI_BASE_ADDRESS)+ SPI_Slave_Select_Register, CS_HIGH);           // CS -> HIGH
40
41
    return response;
42
  }

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.