论坛大神
  
- 积分
- 2233
- 金钱
- 2233
- 注册时间
- 2012-4-30
- 在线时间
- 7 小时
|

楼主 |
发表于 2012-5-24 15:17:30
|
显示全部楼层
呵呵 这不是怕大家没时间帮我吗~
这是我的初始化,spi_speed(1);代表高速模式 spi_speed(0);代表低速模式
send就是SPI发送的,send_com是发送给SD卡命令 参数 CRC的
u8 init_SD(void)
{
u8 i, r1;
spi_init();//spi及相应脚初始化
spi_speed(0);//低速模式
for (i = 0; i < 20; i++) //延时74个时钟以上
send(0xff);
i = 20;
do
{
r1 = send_com(0, 0, 0x95); //复位SD卡,send_com函数里已将CS = 0;
i--;
}while(r1 != 0x01 && i);
if (i != 0)
{
i = 0xff;
do
{
send_com(55, 0, 0x0);
r1 = send_com(41, 0x40000000, 0x01); //检验是否为SD卡,是则继续,不是则拒绝访问
}while(r1 && i--);
if (i != 0)
{
if (r1 == 0)
{
cs = 1;
send(0xff); //禁止SD卡,发送8个时钟
spi_speed(1);
return 1;
}
else
return 0;
}
else
{
cs = 1;
send(0xff);
spi_speed(1);
return 0;
}
}
else
{
cs = 1;
send(0xff);
spi_speed(1);
return 0;
}
}
|
|