我參照你們的例程寫了下面的程序,我直接向U盤DATA區(qū)寫多扇區(qū)數(shù)據(jù)時(shí),發(fā)現(xiàn)375只能寫8個(gè)包,就是一個(gè)扇區(qū)512字節(jié)的數(shù)據(jù),寫完后剩余的包就寫不動(dòng)了,程序總是卡在等待375的#INT引腳上。不明白為什么。
#if _DebugVer_ /* 中斷測(cè)試 */ Uint16 Interrupt_test(void) { //CH375檢測(cè)到NAK會(huì)進(jìn)行重試,防止在此處死機(jī).對(duì)其做超時(shí)處理,一旦超過(guò)規(guī)定的時(shí)間則強(qiáng)行終止NAK重試 Uint16 i; for ( i = 0; CH375_INT_WIRE != 0; i ++ ) // 如果CH375的中斷引腳INT#輸出高電平則等待,通過(guò)計(jì)數(shù)防止超時(shí) { delay1us(); if( i == 0x00ff) { CH375_WR_CMD( CMD_ABORT_NAK ); // 如果超時(shí)達(dá)61mS以上則強(qiáng)行終止NAK重試,中斷返回USB_INT_RET_NAK return(0x00ff); } } CH375_WR_CMD(CMD_GET_STATUS); //產(chǎn)生操作完成中斷, 獲取中斷狀態(tài) return(CH375_RD_DAT()); } #endif
/* 等待CH375中斷并獲取狀態(tài) */ Uint16 CH375_Wait_Interrupt(void) { while(CH375_INT_WIRE); //查詢等待CH375操作完成中斷(INT#低電平) CH375_WR_CMD(CMD_GET_STATUS); //產(chǎn)生操作完成中斷, 獲取中斷狀態(tài) return(CH375_RD_DAT()); }
/* 將緩沖區(qū)中的多個(gè)扇區(qū)的數(shù)據(jù)塊寫入U(xiǎn)盤 iLbaStart 是寫入的線起始性扇區(qū)號(hào), iSectorCount 是寫入的扇區(qū)數(shù), *mBufferPoint指向?qū)懭霐?shù)據(jù)的首地址*/ Uint16 CH375_WriteSector(Uint32 iLbaStart,Uint16 iSectorCount,Uint16 *mBufferPoint) { unsigned int mIntStatus; unsigned int mBlockCount; unsigned int mLength; CH375_WR_CMD(CMD_DISK_WRITE); //向USB存儲(chǔ)器寫數(shù)據(jù)塊 CH375_WR_DAT((Uint16)iLbaStart& 0x00ff); //LBA的最低8位 CH375_WR_DAT((Uint16)(iLbaStart >> 8)& 0x00ff); CH375_WR_DAT((Uint16)(iLbaStart >> 16)& 0x00ff); CH375_WR_DAT((Uint16)(iLbaStart >> 24)& 0x00ff); //LBA的最高8位 CH375_WR_DAT(iSectorCount); //扇區(qū)數(shù) for(mBlockCount=iSectorCount*BlockPerSector;mBlockCount !=0;mBlockCount --) //數(shù)據(jù)塊計(jì)數(shù) { #if _DebugVer_ mIntStatus= Interrupt_test(); // while(mIntStatus== 0x00ff); 驗(yàn)證是否#int引腳響應(yīng)超時(shí) #else mIntStatus= CH375_Wait_Interrupt(); //等待USB請(qǐng)求數(shù)據(jù)的中斷并獲取狀態(tài) #endif if(mIntStatus!= USB_INT_DISK_WRITE) //中斷狀態(tài)錯(cuò)誤,清除錯(cuò)誤,寫數(shù)據(jù)提前結(jié)束 { CH375_ClearError(); //清除U盤錯(cuò)誤以便重試 return( mIntStatus ); //操作失敗 } CH375_WR_CMD( CMD_WR_USB_DATA7 ); //向CH375緩沖區(qū)寫入數(shù)據(jù)塊 mLength = CH375_BLOCK_SIZE; CH375_WR_DAT( mLength ); //后續(xù)數(shù)據(jù)的長(zhǎng)度 while(mLength) //根據(jù)長(zhǎng)度寫入數(shù)據(jù) { //#if _DebugVer_ // CH375_WR_DAT(0x66); //調(diào)試過(guò)程,連續(xù)向U盤寫入0x66 //#else CH375_WR_DAT(*mBufferPoint); //將緩沖區(qū)數(shù)據(jù)寫入U(xiǎn)盤 //#endif delayNuS(10); mBufferPoint++; mLength--; } CH375_WR_CMD(CMD_DISK_WR_GO); //繼續(xù)執(zhí)行USB存儲(chǔ)器的寫操作 } #if _DebugVer_ mIntStatus= Interrupt_test(); #else mIntStatus= CH375_Wait_Interrupt(); //等待中斷并獲取狀態(tài) #endif //完成所有數(shù)據(jù)塊且得到CH375的成功應(yīng)答,返回成功 if(mBlockCount == 0) { if (mIntStatus == USB_INT_SUCCESS) return(0); //操作成功 } //if(mIntStatus == USB_INT_DISCONNECT) return(mIntStatus); //U盤斷開 CH375_ClearError(); //清除U盤錯(cuò)誤以便重試 return( mIntStatus ); //操作失敗 }