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 | }
|