CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount )中 RealCount是干嘛用的

版主,CH376ByteRead( PUINT8 buf, UINT16 ReqCount, PUINT16 RealCount )中 RealCount是干嘛用的,我一般就是直接將RealCount設(shè)為NULL,我現(xiàn)在大批量讀數(shù)據(jù)出現(xiàn)問題,這個(gè)值有影響沒,謝謝

RealCount表示真正讀取的數(shù)據(jù)長度,例如一個(gè)文件只有10個(gè)字節(jié),而 ReqCount設(shè)置為30個(gè)字節(jié),則調(diào)用字節(jié)讀取函數(shù)則RealCount為10個(gè)字節(jié),而非30個(gè)字節(jié),大批量讀取數(shù)據(jù)出現(xiàn)問題可能和這個(gè)有關(guān)系,建議加上這個(gè)判斷在測試下。


哦哦,我看見這個(gè)變量是個(gè)指針,那實(shí)際調(diào)用時(shí)怎么賦值呢


送一個(gè)變量進(jìn)去,如果讀取函數(shù)成功,則看下RealCount返回?cái)?shù)據(jù)和你要讀取的數(shù)據(jù)數(shù)量是否一致即可,真正讀取到的數(shù)據(jù)位RealCount 的數(shù)據(jù)長度。而不是ReqCount數(shù)據(jù)。


謝謝啊,我今天測試了下,每次讀70個(gè)字節(jié),我定義了一個(gè)560字節(jié)的buffer,發(fā)現(xiàn)讀到490個(gè)的時(shí)候,RealCount的值變?yōu)榱?40,其他時(shí)候?yàn)?0,怎么回事啊,這是調(diào)用的語句CH376ByteRead(pu8Temp1, 70, &ThisLen);


那說明你有一次數(shù)據(jù)沒有讀取就進(jìn)行下一次讀取了,所以你按照實(shí)際的數(shù)據(jù)取數(shù)據(jù)看數(shù)據(jù)有沒有丟失?


版主,那該怎么改呢,直接ThisLen置為NULL嗎


根據(jù)你的ThisLen值取數(shù)據(jù)?。?!


版主,我之前反饋說我大批量將SD卡中的數(shù)據(jù)轉(zhuǎn)存到U盤中出錯(cuò)的問題,現(xiàn)在還存在,我現(xiàn)在每次轉(zhuǎn)存70個(gè)字節(jié),轉(zhuǎn)存前面490個(gè)字節(jié)的時(shí)候都是對(duì)的,但大于490的下一次轉(zhuǎn)存時(shí)我發(fā)現(xiàn)ThisLen自己變成了140,讀出的數(shù)據(jù)就會(huì)出錯(cuò)我現(xiàn)在把代碼發(fā)給你看看,跳了好久了,麻煩看看,謝謝~ #include "Ch376INC.h" #include "FileSys.h" #include "FSMC.h" #include "Data.h" #include "systick.h" #include "stm32f10x_gpio.h" #include #include

u8 RSM1[980]={0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x31,0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37}; u8 RSM[560]={0}; u8 WCHH[560]={0};

//u8 WCHH[90]; u8 u8Result; u8 u8Length; u32 SD_capacity[5]; u32 *pu8Temp=SD_capacity; u8 *pu8Temp1 = WCHH; u32 total_memory; u32 memory; u32 u32FileLen = 0; u32 u32DataCnt = 0; u16* ThisLen; char SrcName[64]; char TarName[64];

//UINT8 idata buf[64]; char ch376_buf[64];

//描述: 延時(shí)函數(shù) //名稱: delay //輸入?yún)?shù): 無 //輸出參數(shù): 無 //返回值: 無 //說明: 無

#define HRES GPIO_SetBits(GPIOB, GPIO_Pin_12); //CH376復(fù)位信號(hào)高電平有效 #define LRES GPIO_ResetBits(GPIOB, GPIO_Pin_12); #define CH375_INT_WIRE GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)

void delay(u32 i) { while (i > 0) { i--; } }

/******************************************************************************* * 函數(shù)名:mStopIfError * 輸 入: iError, 錯(cuò)誤代碼 * 輸 出: * 功能說明:檢查操作狀態(tài),如果錯(cuò)誤則顯示錯(cuò)誤代碼并停機(jī), * 應(yīng)該替換為實(shí)際的處理措施,例如顯示錯(cuò)誤信息,等待用戶確認(rèn)后重試等 */ void mStopIfError(uint8_t iError) { if (iError == USB_INT_SUCCESS) { return; /* 操作成功 */ } //printf("Error: %02X\n", iError ); /* 顯示錯(cuò)誤 */ while(1) { /* LED閃爍 */ // GPIO_ResetBits(GPIOF, GPIO_Pin_6); // mDelaymS( 200 ); // GPIO_SetBits(GPIOF, GPIO_Pin_6); // mDelaymS( 200 ); } } //描述: 查詢INT引腳電平 //名稱: Query376Interrupt //輸入?yún)?shù): 無 //輸出參數(shù): 無 //返回值: u8 -- FALSE 沒有中斷 // TRUE 有中斷 //說明: 無 u8 Query376Interrupt(void) { //u8 temp=0; //temp=GPIO_ReadInputDataBit(GPIOG, GPIO_Pin_15); //delay_ms(10); //return TRUE; return (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13) ? FALSE : TRUE); //0表示沒有中斷 非0表示有中斷 }

//描述: 初始化Ch376芯片 //名稱: mInitCH376Host //輸入?yún)?shù): 無 //輸出參數(shù): 無 //返回值: u8 -- 初始化結(jié)果 // USB_INT_SUCCESS(0x14) 初始化成功 // ERR_USB_UNKNOWN(0xFA) 初始化失敗 //說明: 無

u8 mInitCH376initial(void) { u8 u8Result; FSMC_SRAM_Init(); /* 接口硬件初始化 */ GPIO_SetBits(GPIOE, GPIO_Pin_5); GPIO_ResetBits(GPIOE, GPIO_Pin_6); delay_ms(500); HRES; delay_ms(500); LRES; delay_ms(200); xWriteCH376Cmd(CMD11_CHECK_EXIST); /* 06 測試單片機(jī)與CH376之間的通訊接口 */ Write376Data(0x55); //手冊上為發(fā)送55,返回0AA為正確 delay_ms(2); u8Result = Read376Data(); if (u8Result != 0xAA ) //AA { return ERR_USB_UNKNOWN; /* 通訊接口不正常,可能原因有:接口連接異常,其它設(shè)備影響(片選不唯一),串口波特率,一直在復(fù)位,晶振不工作 */ } }

u8 mInitCH376Host(void) //數(shù)據(jù)寫完需要關(guān)閉文件,否則文本中數(shù)據(jù)無法更新 { u8 u8Result; FSMC_SRAM_Init(); /* 接口硬件初始化 */ GPIO_SetBits(GPIOE, GPIO_Pin_5); GPIO_ResetBits(GPIOE, GPIO_Pin_6); delay_ms(300); HRES; delay_ms(500); LRES; delay_ms(200); xWriteCH376Cmd(CMD11_CHECK_EXIST); /* 06 測試單片機(jī)與CH376之間的通訊接口 */ Write376Data(0x55); //手冊上為發(fā)送55,返回0AA為正確 delay_ms(2); u8Result = Read376Data(); if (u8Result != 0xAA ) //AA { return ERR_USB_UNKNOWN; /* 通訊接口不正常,可能原因有:接口連接異常,其它設(shè)備影響(片選不唯一),串口波特率,一直在復(fù)位,晶振不工作 */ } //xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 設(shè)備USB工作模式 */ //Write376Data(0x06); //切換到USB主機(jī)模式 xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 SD工作模式 */ Write376Data(0x03); //S //CH376_WRITE_REGISTER(CMD11_SET_USB_MODE,0x06); delay_ms(2); u8Result = Read376Data();

if (u8Result == CMD_RET_SUCCESS) { return USB_INT_SUCCESS; } else { return(ERR_USB_UNKNOWN); /* 設(shè)置模式錯(cuò)誤 */ }

}

void SD_CH376_read_capacity(void) { u8Result = mInitCH376Host();

if (u8Result == USB_INT_SUCCESS) { u8Result = CH376DiskMount(); // 初始化磁盤并測試磁盤是否就緒 if (u8Result != USB_INT_SUCCESS) { while (1); }

else { u8Length=CH376DiskCapacity(&total_memory); CH376DiskQuery(&memory); } } }

uint8_t s; void SD_CH376_USB_Function(void) { u8Result = mInitCH376Host();

if (u8Result == USB_INT_SUCCESS) { u8Result = CH376DiskMount(); // 初始化磁盤并測試磁盤是否就緒 if (u8Result != USB_INT_SUCCESS) { while (1); }

else { u8Result=CH376FileCreate("/WCHH.TXT"); if (u8Result == 0x14) { u8Length=CH376DiskCapacity(&total_memory); CH376DiskQuery(&memory); //u8Result=CH376FileOpen("/WCHH.TXT"); u8Result=CH376FileOpen("/WCHH.TXT"); if (u8Result == USB_INT_SUCCESS) { // 獲取文件大小 u32FileLen = CH376GetFileSize();

while (u32DataCnt < u32FileLen) { CH376ByteWrite(RSM1, strlen(RSM1), 0); // u32DataCnt += 1; } //CH376FileClose(1); CH376FileClose(1); u8Result=CH376FileOpen("/WCHH.TXT"); if (u8Result == USB_INT_SUCCESS) { u32DataCnt=0; u32FileLen = CH376GetFileSize(); for(u32DataCnt=0;u32DataCnt<490;u32DataCnt+=70) { CH376ByteRead(pu8Temp1, 70, ThisLen); // CH376ByteWrite((uint8_t *)buf, strlen(buf), NULL ); pu8Temp1+=70; } //if(u32DataCnt>=(u32FileLen-2)) strcpy(RSM, WCHH ); /* 目標(biāo)文件名 將WCHH中的數(shù)據(jù)復(fù)制到RSM中*/ CH376FileClose(1); // ReqCount設(shè)置為45、70時(shí)讀寫正確 //CH376ByteRead(RSM1, 90, 0); } } } xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 USB工作模式 */ Write376Data(0x06); //S delay_ms(2); u8Result = Read376Data(); if (u8Result == CMD_RET_SUCCESS) { while (CH376DiskConnect() != USB_INT_SUCCESS) //檢查設(shè)備是否連接 { delay_ms(500); }

u8Result = CH376DiskMount(); // 初始化磁盤并測試磁盤是否就緒 if (u8Result == USB_INT_SUCCESS) { CH376DiskQuery(&memory); u8Result=CH376FileCreate("/HUA.TXT"); u8Result=CH376FileOpen("/HUA.TXT"); if (u8Result == USB_INT_SUCCESS) { // 獲取文件大小 u32DataCnt=0; u32FileLen = CH376GetFileSize(); while (u32DataCnt < u32FileLen) { CH376ByteWrite(RSM, sizeof(RSM), 0); // u32DataCnt += 1; } CH376FileClose(1); } } } //} } } else { while (1); } }

/* 向索引端口寫入索引地址 */ //#define Write374Index( a ) { CH374_IDX_PORT = a; } void Write376Index(u8 mIndex ) /* 向CH374寫索引地址 */ { //CH376->CH376_REG = mIndex ; CH376_CMD_PORT= mIndex ; delay_ms(2); }

/* 向數(shù)據(jù)端口寫入數(shù)據(jù),索引地址自動(dòng)加1 */ //#define Write374Data( d ) { CH374_DAT_PORT = d & 0xFF; } void Write376Data( u8 mData ) { //CH376->CH376_RAM = mData ; CH376_DAT_PORT = mData ; delay_ms(2); }

/* 從數(shù)據(jù)端口讀出數(shù)據(jù),索引地址自動(dòng)加1 */ //#define Read374Data( ) ( (UINT8)CH374_DAT_PORT ) u8 Read376Data( void ) { //return (CH376->CH376_RAM); delay_ms(2); return (CH376_DAT_PORT); }

/* 從索引端口讀出數(shù)據(jù),索引地址不變,適用于[讀出->修改->寫回]操作 */ //#define Read374Data0( ) ( (UINT8)CH374_IDX_PORT ) u8 Read376Data0( void ) { //return( CH376->CH376_RAM ); return (CH376_DAT_PORT); }

/* 從指定寄存器讀取數(shù)據(jù) */ u8 CH376_READ_REGISTER(u8 mAddr) { //CH376->CH376_REG = mAddr; CH376_CMD_PORT= mAddr ; delay_ms(2); return Read376Data(); }

/* 向指定寄存器寫入數(shù)據(jù) */ void CH376_WRITE_REGISTER(u8 mAddr, u8 mData) { CH376_CMD_PORT= mAddr ; delay_ms(2); CH376_DAT_PORT=mData; delay_ms(2);

}

void xWriteCH376Cmd(u8 u8Cmd) { u8 i; CH376_CMD_PORT= u8Cmd ; delay_ms(2); for (i=100; i!=0; --i) { delay_ms(1); if ((xReadCH376Status() & PARA_STATE_BUSY ) == 0 ) //CH376_CMD_PORT & PARA_STATE_BUSY(10) { break; } } }

//描述: 向CH376寫數(shù)據(jù) //名稱: xWriteCH376Data //輸入?yún)?shù): u8Data -- 數(shù)據(jù) //輸出參數(shù): 無 //返回值: 無 //說明: 無 void xWriteCH376Data(u8 u8Data) { //CH376->CH376_RAM =u8Data; CH376_DAT_PORT=u8Data; //DelayMs(2); delay_ms(2); }

//描述: 從CH376讀數(shù)據(jù) //名稱: xReadCH376Data //輸入?yún)?shù): 無 //輸出參數(shù): 無 //返回值: u8 -- 總線數(shù)據(jù) //說明: 無 u8 xReadCH376Data(void) { u8 u16Temp =CH376_DAT_PORT; delay_ms(2); return u16Temp; }


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

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