CH376讀取單個的扇區(qū)成功,但讀取多個的扇區(qū)會出錯

CH376讀取單個的扇區(qū)成功,但讀取多個的扇區(qū)會出錯,這是怎么為什么呢...

出錯的現(xiàn)象是怎樣的?把你的程序貼出來看看


UINT8 idata buf[64]; UINT8 xdata FileDataBuf[5120]; /* 文件緩沖區(qū),太小則速度慢 */

main( ) {

UINT8 i, count; /* i為需要讀取的扇區(qū)數(shù) */ UINT16 s, total, Size, RealCount; /* s臨時變量, total需要讀的扇區(qū)數(shù), Size需要讀的字節(jié)數(shù) */ UINT32 NewSize; /* NewSize文件大小 */

mDelaymS( 100 ); /* 延時100毫秒 */ mInitSTDIO( ); /* 為了讓計算機通過串口監(jiān)控演示過程 */ printf( "Start\n" );

s = mInitCH376Host( ); /* 初始化CH376 */ mStopIfError( s ); /* 其它電路初始化 */

while ( 1 ) { printf( "Wait Udisk/SD\n" ); while ( CH376DiskConnect( ) != USB_INT_SUCCESS ) { /* 檢查U盤是否連接,等待U盤插入,對于SD卡,可以由單片機直接查詢SD卡座的插拔狀態(tài)引腳 */ mDelaymS( 100 ); } mDelaymS( 200 ); /* 延時,可選操作,有的USB存儲器需要幾十毫秒的延時 */

/* 對于檢測到USB設(shè)備的,最多等待10*50mS */ for ( s = 0; s < 10; s ++ ) { /* 最長等待時間,10*50mS */ mDelaymS( 50 ); printf( "Ready ?\n" ); if ( CH376DiskMount( ) == USB_INT_SUCCESS ) break; /* 初始化磁盤并測試磁盤是否就緒 */ }

/* 檢查U盤或者SD卡的剩余空間 */ printf( "DiskQuery: " ); s = CH376DiskQuery( (PUINT32)buf ); /* 查詢磁盤剩余空間信息,扇區(qū)數(shù) */ mStopIfError( s ); printf( "free cap = %ld MB\n", *(PUINT32)buf / ( 1000000 / DEF_SECTOR_SIZE ) ); /* 計算剩余空間信息 */

/* 如果CH376HFT.C文件已經(jīng)存在則添加數(shù)據(jù)到尾部,如果不存在則新建文件 */ printf( "Open\n" ); s = CH376FileOpen( "\\CH376HFT.C" ); /* 打開文件,該文件在根目錄下 */ if ( s == USB_INT_SUCCESS ) { /* 文件存在并且已經(jīng)被打開,移動文件指針到尾部以便添加數(shù)據(jù) */ NewSize = CH376GetFileSize( ); /* 讀取當(dāng)前文件長度,如果沒有零頭數(shù)據(jù),那么文件長度是DEF_SECTOR_SIZE的倍數(shù) */ printf( "File size = %ld\n", NewSize ); printf( "Locate tail\n" ); } else mStopIfError( s ); /* 打開文件時出錯 */ /* 扇區(qū)讀取源文件 */ while( NewSize ){ /* 扇區(qū)有字節(jié)讀出 */ printf( "NewSize = %ld \n", NewSize ); s = CH376SecLocate( 0 ); /* 移動到第一個字節(jié) */ mStopIfError( s ); /* 檢錯 */ total = ( NewSize + DEF_SECTOR_SIZE - 1 ) / DEF_SECTOR_SIZE; /* 將文件的字節(jié)數(shù)轉(zhuǎn)換為扇區(qū)數(shù)(除以DEF_SECTOR_SIZE),長度加上DEF_SECTOR_SIZE-1用于確保寫入最后的零頭數(shù)據(jù) */ printf( "Read sector = %d \n", total ); /* 準備要讀的扇區(qū)數(shù) */ while( total ) /* 如果扇區(qū)未讀完,則繼續(xù)讀扇區(qū) */ { if( total > 10 ) i = 10; /* 如果扇區(qū)數(shù)大于10,則該次要讀的扇區(qū)為10個 */ else i = total; /* 如果扇區(qū)數(shù)小于10,則該次要讀的扇區(qū)數(shù)為total */ s = CH376SecRead( FileDataBuf, i, &RealCount ); /* 從文件讀取數(shù)據(jù) */ mStopIfError( s ); /* 檢錯 */ total -= RealCount; /* 計數(shù),減去當(dāng)前實際已經(jīng)讀出的扇區(qū)數(shù) */ printf( "\n" ); printf( "total = %d \n", total ); if( FileSize > i * DEF_SECTOR_SIZE ) Size = i * DEF_SECTOR_SIZE; /* 如果剩余要讀的字節(jié)數(shù)大于4096,則輸出的字節(jié)數(shù)為4096 */ else Size = NewSize; /* 如果剩余要讀的字節(jié)數(shù)小于4096,則輸出的字節(jié)數(shù)為NewSize */ NewSize -= Size; printf( "\n" ); printf( "NewSize = %ld \n", NewSize ); for ( s=0; s!=Size; s++ ) printf( "%C", FileDataBuf[s] ); /* 顯示讀出的字符 */ } if( total <= 1 ) /* 如果要讀的扇區(qū)等于0,則文件讀到尾部 */ { printf( "\n" ); printf( "文件已經(jīng)結(jié)束\n" ); goto Close; /* 關(guān)閉文件 */ } } Close: printf( "Close\n" ); s = CH376FileClose( FALSE ); /* 關(guān)閉文件,扇區(qū)模式通常不自動更新文件長度,因為強制刷新緩沖區(qū)時已經(jīng)更新了文件長度,所以這里不需要自動更新文件長度 */ mStopIfError( s );

printf( "Take out\n" ); while ( CH376DiskConnect( ) == USB_INT_SUCCESS ) { /* 檢查U盤是否連接,等待U盤拔出 */ mDelaymS( 100 ); } mDelaymS( 200 ); } }


只讀取了前面一個扇區(qū)...后面的扇區(qū)都是FF..或者14


你的FileSize是怎么定義的,應(yīng)該是NewSize吧?按照你的流程是我可以讀到30K的文件


53 74 61 72 74 0D 0A 57 61 69 74 20 55 64 69 73 6B 2F 53 44 0D 0A 52 65 61 64 79 20 3F 0D 0A 44 69 73 6B 51 75 65 72 79 3A 20 66 72 65 65 20 63 61 70 20 3D 20 31 32 32 31 31 20 4D 42 0D 0A 4F 70 65 6E 0D 0A 46 69 6C 65 20 73 69 7A 65 20 3D 20 36 33 32 35 31 31 39 0D 0A 4C 6F 63 61 74 65 20 74 61 69 6C 0D 0A 4E 65 77 53 69 7A 65 20 3D 20 36 33 32 35 31 31 39 20 0D 0A 52 65 61 64 20 73 65 63 74 6F 72 20 3D 20 31 32 33 35 34 20 0D 0A 0D 0A 74 6F 74 61 6C 20 3D 20 39 37 39 34 20 0D 0A 0D 0A 4E 65 77 53 69 7A 65 20 3D 20 36 33 31 39 39 39 39 20 0D 0A 75 6E 73 69 67 6E 65 64 20 63 68 61 72 20 64 61 74 61 5B 31 30 32 32 32 33 36 5D 20 3D 20 7B 0D 0D 0A 09 30 78 34 39 2C 20 30 78 34 34 2C 20 30 78 33 33 2C 20 30 78 30 34 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 36 42 2C 20 30 78 35 34 2C 20 30 78 34 39 2C 20 30 78 35 34 2C 20 30 78 33 32 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 0D 0D 0A 09 30 78 30 30 2C 20 30 78 30 41 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 43 46 2C 20 30 78 45 30 2C 20 30 78 42 43 2C 20 30 78 46 42 2C 20 30 78 42 41 2C 20 30 78 44 45 2C 20 30 78 43 44 2C 20 30 78 45 44 2C 20 30 78 30 30 2C 20 30 78 35 34 2C 20 30 78 34 33 2C 20 0D 0D 0A 09 30 78 34 46 2C 20 30 78 34 45 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 37 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 34 46 2C 20 30 78 37 34 2C 20 30 78 36 38 2C 20 30 78 36 35 2C 20 30 78 37 32 2C 20 30 78 30 30 2C 20 30 78 35 34 2C 20 0D 0D 0A 09 30 78 34 31 2C 20 30 78 34 43 2C 20 30 78 34 32 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 31 33 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 43 35 2C 20 30 78 45 44 2C 20 30 78 44 33 2C 20 30 78 43 45 2C 20 30 78 43 31 2C 20 30 78 42 35 2C 20 0D 0D 0A 09 30 78 42 38 2C 20 30 78 45 38 2C 20 30 78 32 30 2C 20 30 78 44 37 2C 20 30 78 45 45 2C 20 30 78 42 30 2C 20 30 78 41 45 2C 20 30 78 42 45 2C 20 30 78 41 42 2C 20 30 78 44 31 2C 20 30 78 41 31 2C 20 30 78 30 30 2C 20 30 78 35 34 2C 20 30 78 35 30 2C 20 30 78 34 35 2C 20 30 78 33 31 2C 20 0D 0D 0A 09 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 38 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 43 35 2C 20 30 78 45 44 2C 20 30 78 42 43 2C 20 30 78 44 31 2C 20 30 78 42 42 2C 20 30 78 44 42 2C 20 30 78 30 30 2C 20 30 78 35 34 2C 20 30 78 35 33 2C 20 0D 0D 0A 09 30 78 35 33 2C 20 30 78 34 35 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 44 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 34 43 2C 20 30 78 36 31 2C 20 30 78 37 36 2C 20 30 78 36 36 2C 20 30 78 33 35 2C 20 30 78 33 32 2C 20 30 78 32 45 2C 20 0D 0D 0A 09 30 78 33 35 2C 20 30 78 33 34 2C 20 30 78 32 45 2C 20 30 78 33 30 2C 20 30 78 30 30 2C 20 30 78 46 46 2C 20 30 78 45 33 2C 20 30 78 34 30 2C 20 30 78 36 34 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 31 2C 20 30 78 41 34 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 0D 0D 0A 09 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 33 2C 20 30 78 34 38 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 30 30 2C 20 30 78 34 43 2C 20 30 78 34 31 2C 20 30 78 34 44 2C 20 30 78 34 35 2C 20 30 78 33 33 2C 20 30 78 32 45 2C 20 0D 0D 0A 09 30 78 33 39 2C 20 30 78 33 38 2C 20 30 78 32 45 2C 20 30 78 33 32 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 30 78 35 35 2C 20 0D 0D 0A 09 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 F4


我的還是這樣顯示...FF是空格...14是另一個符號...


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频