Uint8 USB_LbaRead(Uint8 *buffaddr,Uint32 lbaaddress,Uint8 sectornum) { Uint8 temp; Uint16 bufferlen=0;
USB_WRITE_CMD = USB_DISK_READ; DELAY_MS(20); USB_DATA_OPT = (lbaaddress>>0)&0xff; DELAY_MS(20); USB_DATA_OPT = (lbaaddress>>8)&0xff; DELAY_MS(20); USB_DATA_OPT = (lbaaddress>>16)&0xff; DELAY_MS(20); USB_DATA_OPT = (lbaaddress>>24)&0xff; DELAY_MS(20); USB_DATA_OPT = sectornum; DELAY_MS(20); while (1) { while(IOPIN0&USB_INIT_PORT); DELAY_MS(1000); USB_WRITE_CMD = USB_GET_STATUS; DELAY_MS(20); temp = USB_DATA_OPT; switch (temp) { case USB_INT_DISK_READ: USB_DataRead(&buffaddr[bufferlen]); bufferlen+=usbrvelen; USB_WRITE_CMD = USB_DISK_RD_GO; break; case USB_INT_SUCCESS: return 1; default : return 0; } } }
主要是延遲,一般都要加個(gè)20MS的延時(shí),特別是中斷的時(shí)候要加個(gè)1000MS的延時(shí),這樣才能讀64個(gè)字節(jié)。再做個(gè)8次循環(huán),呵呵 那個(gè)時(shí)間我調(diào)整過,只要少于立馬讀出來的全是00,加延遲數(shù)據(jù)就對。
不要告訴我用你們的那個(gè)文件庫,因?yàn)槟銈冞@個(gè)庫KEIL報(bào)錯(cuò),格式不識(shí)別。
讀寫脈寬設(shè)置圖: