打印
[内核技术]

读取SD卡扇区程序读回来一堆乱码

[复制链接]
632|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
SD卡, se, AD, ST, ck
本帖最后由 又见龙楼 于 2018-12-7 13:52 编辑

求各位大神指教……
问题是这样的,我用disk_read程序读SD卡扇区,结果读到的跟我用winhex看到的根本不一样,可以说是一堆乱码,相信大家都知道最后两位是55AA才是正确的,可我是前面几位是55AA,后面的数据都不知道从哪里来的,换张卡也一样,最可怕的是,换个扇区号也一样,几天了,实在绝望了,求大家赐教……
对了,我用的是英飞凌芯片,底层是没什么问题的。

这是代码
DRESULT disk_read (
        BYTE drv,                /* Physical drive number (0) */
        BYTE *buff,                /* Pointer to the data buffer to store read data */
        DWORD sector,        /* Start sector number (LBA) */
        UINT count                /* Number of sectors to read (1..128) */
)
{
        int m,n;
        if (drv || !count) return RES_PARERR;                /* Check parameter */
        if (Stat & STA_NOINIT) return RES_NOTRDY;        /* Check if drive is ready */

        if (!(CardType & CT_BLOCK)) sector *= 512;        /* LBA ot BA conversion (byte addressing cards) */

        if (count == 1)
        {        /* Single sector read */
                m=send_cmd(CMD17, sector);
                n=rcvr_datablock(buff, 520);
                strange[3]=m;
                strange[4]=n;

                if((m==0)&&(n==1))   count = 0;
        }


        else
        {
                /* Multiple sector read */
                if (send_cmd(CMD18, sector) == 0) {        /* READ_MULTIPLE_BLOCK */
                        do {
                                if (!rcvr_datablock(buff, 512)) break;
                                buff += 512;
                        } while (--count);
                        send_cmd(CMD12, 0);                                /* STOP_TRANSMISSION */
                }
                deselect();

                strange[2]=count;
                return count ? RES_ERROR : RES_OK;        /* Return result */
        }

}

这是读取结果

微信图片_20181207134329.png (131.79 KB )

微信图片_20181207134329.png

微信图片_20181207134333.png (56.71 KB )

微信图片_20181207134333.png

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝