[求助]ch375读u盘,第0扇区怎么总是读到u盘说明信息?

第一句总是:KingstonDataTravelerMiniPMAP,而不是boot。这可能是什么原因引起的?下面是我读第1扇区得到的信息:

55 53 42 20 43 68 65 63 6B 65 72 20 49 6E 20 44 65 76 6C 6F 70 69 6E 67 21 0D 0A 00 00 00 01 1F 00 00 00 4B 69 6E 67 73 74 6F 6E 44 61 74 61 54 72 61 76 65 6C 65 72 4D 69 6E 69 50 4D 41 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF 04 FF FF 04 FF FF 04 00 00 00 8C 00 00 00 01 00 00 50 00 01 FF FF FF FF FF

读一扇区代码如下: void ReadDiskOneSector(UINT32 LBA,UINT8 *buffer) { UINT8 cnt = 8; BOOL retry = TRUE; while(retry) { Ch375WriteCommand(CMD_DISK_READ); Ch375WriteData((UINT8)LBA); Ch375WriteData((UINT8)(LBA>>8)); Ch375WriteData((UINT8)(LBA>>16)); Ch375WriteData((UINT8)(LBA>>24)); Ch375WriteCommand(1); while(cnt--) { if(WaitInterrupt() != USB_INT_DISK_READ) break; ReadUsbData(buffer); Ch375WriteCommand(CMD_DISK_RD_GO); } if(cnt != 0xff) { InitialUsbDisk(); } else { retry = FALSE; } } }

// 从CH37X读出数据块 void ReadUsbData( UINT8 *buf ) { UINT8 i, len; Ch375WriteCommand(CMD_RD_USB_DATA); /* 从CH375的端点缓冲区读取接收到的数据 */ len=Ch375ReadData(); /* 后续数据长度 */ for ( i=0; i { *buf++=Ch375ReadData(); } }


Ch375WriteCommand(1); ??? 扇区数怎么能通过命令口写呢!应为:Ch375WriteData(1)


写成如下,一样的结果!疯了! //CH375读一个扇区 void ReadDiskOneSector(UINT32 LBA,UINT8 *buffer) { UINT8 cnt; BOOL retry = TRUE; UINT8 rstatus; while(retry) { cnt = 9; Ch375WriteCommand(CMD_DISK_READ); Ch375WriteData((UINT8)LBA); Ch375WriteData((UINT8)(LBA>>8)); Ch375WriteData((UINT8)(LBA>>16)); Ch375WriteData((UINT8)(LBA>>24)); Ch375WriteData(1); while(--cnt) { rstatus = WaitInterrupt(); if(rstatus != USB_INT_DISK_READ) { PrintRS232char(rstatus); break; } ReadUsbData(buffer); Ch375WriteCommand(CMD_DISK_RD_GO);

} if(cnt == 0) retry = FALSE; else InitialUsbDisk(); } }


换了一个u盘,读到如下结果: 68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73 6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20 61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61 72 74 0D 0A 00 00 00 00 00 AC CB D8 00 00 55 AA 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF 04 FF FF 04 00 FF 04 FF FF 04 00 2E 20 00 03 04 00 00 00 00 00 02 00 01


正确应该是: EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 02 26 00 02 00 00 00 00 F8 00 00 3F 00 FF 00 00 00 00 00 00 E8 03 00 E1 03 00 00 00 00 00 00 02 00 00 00 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 29 4A F0 50 0C 4E 4F 20 4E 41 4D 45 20 20 20 20 46 41 54 33 32 20 20 20 33 C9 8E D1 BC F4 7B 8E C1 8E D9 BD 00 7C 88 4E 02 8A 56 40 B4 08 CD 13 73 05 B9 FF FF 8A F1 66 0F B6 C6 40 66 0F B6 D1 80 E2 3F F7 E2 86 CD C0 ED 06 41 66 0F B7 C9 66 F7 E1 66 89 46 F8 83 7E 16 00 75 38 83 7E 2A 00 77 32 66 8B 46 1C 66 83 C0 0C BB 00 80 B9 01 00 E8 2B 00 E9 48 03 A0 FA 7D B4 7D 8B F0 AC 84 C0 74 17 3C FF 74 09 B4 0E BB 07 00 CD 10 EB EE A0 FB 7D EB E5 A0 F9 7D EB E0 98 CD 16 CD 19 66 60 66 3B 46 F8 0F 82 4A 00 66 6A 00 66 50 06 53 66 68 10 00 01 00 80 7E 02 00 0F 85 20 00 B4 41 BB AA 55 8A 56 40 CD 13 0F 82 1C 00 81 FB 55 AA 0F 85 14 00 F6 C1 01 0F 84 0D 00 FE 46 02 B4 42 8A 56 40 8B F4 CD 13 B0 F9 66 58 66 58 66 58 66 58 EB 2A 66 33 D2 66 0F B7 4E 18 66 F7 F1 FE C2 8A CA 66 8B D0 66 C1 EA 10 F7 76 1A 86 D6 8A 56 40 8A E8 C0 E4 06 0A CC B8 01 02 CD 13 66 61 0F 82 54 FF 81 C3 00 02 66 40 49 0F 85 71 FF C3 4E 54 4C 44 52 20 20 20 20 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0D 0A 52 65 6D 6F 76 65 20 64 69 73 6B 73 20 6F 72 20 6F 74 68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73 6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20 61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61 72 74 0D 0A 00 00 00 00 00 AC CB D8 00 00 55 AA

把前面的数据丢了! 请提示一下,可能是什么原因。


数了一下,丢了七块*端点大小(64Byte),只读了最后一块。


应该是程序上的原因,建议您下载CH375EVT.ZIP,用..\PUB\MCS51C\MISCELL目录下的示例程序试试


128M优盘没有问题了,可新买的2GB的爱国者 MiniUsb不行,1G的kingston也不行。用的是ch375B. 读u盘大小时,就死了 //初始化U盘 void InitialUsbDisk(void) { UINT8 rstatus; UINT32 size; UINT8 temp; PrintRS232FlashStr("Wait Usb disk Insert..."); while(TestConnect() == USB_INT_DISCONNECT); PrintRS232FlashStr("Find Usb Disk! "); PrintRS232FlashStr("Reset Usb Disk... "); ResetUsbBus(); PrintRS232FlashStr("Reset Ok! "); PrintRS232FlashStr("Initial Usb Disk..."); while(TRUE) { Ch375WriteCommand(CMD_DISK_INIT); rstatus = WaitInterrupt(); if(rstatus == USB_INT_SUCCESS) break; } PrintRS232FlashStr("Initial Ok! "); PrintRS232FlashStr("Read Usb Disk Size... "); PrintRS232FlashStr("Usb disk Size: "); size = ReadDiskSize(); size = size >> 20; temp = (UINT8)(size / 1000); PrintRS232char(temp + 0x30); size -= 1000*(UINT32)temp; temp = (UINT8)(size / 100); PrintRS232char(temp + 0x30); size -= 100*(UINT32)temp; temp = (UINT8)(size / 10); PrintRS232char(temp+0x30); size -= 10*(UINT32)temp; PrintRS232char((UINT8)size + 0x30); PrintRS232FlashStr("MB"); }


请各位帮忙分析一下。


大优盘初始化读u盘大小时就出错: UINT32 ReadDiskSize(void) { UINT8 buffer[8]; UINT32 temp1,temp2; UINT8 rstatus; while(TRUE) { Ch375WriteCommand(CMD_DISK_SIZE); rstatus = WaitInterrupt(); if(rstatus != USB_INT_SUCCESS) { PrintRS232char(rstatus);//大优盘这里返回的是0x1F,而不是期待的0x1D. DelayNms(100); } else break; } ReadUsbData(buffer); temp1 = (UINT32)buffer[0]<<24; temp1 += (UINT32)buffer[1]<<16; temp1 += (UINT32)buffer[2]<<8; temp1 += (UINT32)buffer[3]<<0; temp2 = (UINT32)buffer[4]<<24; temp2 += (UINT32)buffer[5]<<16; temp2 += (UINT32)buffer[6]<<8; temp2 += (UINT32)buffer[7]<<0; temp1 = temp1*temp2; return temp1; }


调试窗口如下: Now check Ch375 Chip: Find Ch375 Chip Now Initial UsbDisk Wait Usb disk Insert... Find Usb Disk! Reset Usb Disk... Reset Ok! Initial Usb Disk... Initial Ok! Read Usb Disk Size... Usb disk Size: 死在这里,收到的全部都是: 0x1F 0x1F

但使用爱国者1G优盘没有问题。


Now Initial UsbDisk Wait Usb disk Insert... Find Usb Disk! Reset Usb Disk... Reset Ok! Initial Usb Disk... Initial Ok! Read Usb Disk Size... Usb disk Size: 0967MB


出现上面的问题一般都是前面没有做好: mDelaymS( 200 ); set_usb_mode( 6 ); /* 设置USB主机模式 */ while ( wait_interrupt()!=USB_INT_CONNECT ); set_usb_mode( 7 ); /* 复位USB设备,CH375向USB信号线的D+和D-输出低电平 */ mDelaymS( 10 ); /* 复位时间不少于1mS,建议为10mS */ set_usb_mode( 6 ); /* 结束复位 */ mDelaymS( 100 ); while ( wait_interrupt()!=USB_INT_CONNECT ); /* 等待复位之后的设备端再次连接上来 */ mDelaymS( 200 ); /* 有些USB设备要等待数百毫秒才能正常工作 */

.......进行枚举操作 上述延时是比较正确的,根据自己硬件时钟进行修改,但是延时不必太长,在极少数情况下可能会设备挂起.


void InitialUsbDisk(void) { UINT8 rstatus; UINT32 size; UINT8 temp; PrintRS232FlashStr("Wait Usb disk Insert..."); while(TestConnect() == USB_INT_DISCONNECT); PrintRS232FlashStr("Find Usb Disk! "); PrintRS232FlashStr("Reset Usb Disk... "); ResetUsbBus(); //复位保持时间不少于1MS建议10MS mDelaymS( 100 ); PrintRS232FlashStr("Reset Ok! "); //再次检测设备连接 while ( wait_interrupt()!=USB_INT_CONNECT ); /* 等待复位之后的设备端再次连接上来 */ PrintRS232FlashStr("Initial Usb Disk..."); //延时200MS mDelaymS( 200 ); while(TRUE) { Ch375WriteCommand(CMD_DISK_INIT); rstatus = WaitInterrupt(); if(rstatus == USB_INT_SUCCESS) break; } PrintRS232FlashStr("Initial Ok! "); PrintRS232FlashStr("Read Usb Disk Size... "); PrintRS232FlashStr("Usb disk Size: "); size = ReadDiskSize(); size = size >> 20; temp = (UINT8)(size / 1000); PrintRS232char(temp + 0x30); size -= 1000*(UINT32)temp; temp = (UINT8)(size / 100); PrintRS232char(temp + 0x30); size -= 100*(UINT32)temp; temp = (UINT8)(size / 10); PrintRS232char(temp+0x30); size -= 10*(UINT32)temp; PrintRS232char((UINT8)size + 0x30); PrintRS232FlashStr("MB"); } U盘的时序相差很大,兼容性想做好确实很不容易,要进行大批量的测试,不知道您用的是什么单片机?为何不选用我们的文件系统进行操作呢?


谢谢您。我等等试验。我用的是avr,因为我还要处理sd卡,已经有了fat系统。不想再加一套fat.


只有登录才能回复,可以选择微信账号登录