又见龙楼 发表于 2018-12-7 13:44

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

本帖最后由 又见龙楼 于 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=m;
                strange=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=count;
                return count ? RES_ERROR : RES_OK;      /* Return result */
      }

}

这是读取结果

页: [1]
查看完整版本: 读取SD卡扇区程序读回来一堆乱码