u8 CH376ByteRead( u8* buf, u16 ReqCount, u16* RealCount )

版主,請問u8CH376ByteRead( u8* buf, u16 ReqCount, u16* RealCount ) 函數(shù)中ReqCount最大值可取多少,我現(xiàn)在想將SD卡中的數(shù)據(jù)轉(zhuǎn)存到U盤中,發(fā)現(xiàn)數(shù)據(jù)個(gè)數(shù)為45個(gè)就不行了,怎么處理,謝謝

ReqCount最大值是65535,ReqCount=45肯定是可以讀取的,你監(jiān)控一下有無錯(cuò)誤返回值?讀出的buf緩沖區(qū)定義有無問題?


我定義的是這樣一組數(shù)據(jù)u8 RSM1[90]={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,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};就是數(shù)字123456789,當(dāng)我設(shè)置ReqCount為48時(shí),讀到的值是48個(gè)3,這是怎么回事啊


當(dāng)我設(shè)置ReqCount為49時(shí),讀到的值是49個(gè)4, 設(shè)置90,讀到90個(gè)9,我用的是FSMC總線方式,這是怎么回事啊


很明顯你的錯(cuò)誤是有規(guī)律的,估計(jì)軟件編程哪邊有問題?首先你得確認(rèn)你想讀出來的數(shù)據(jù)是什么? 可以把程序貼出來看一下。


#define CH376_DAT_PORT (*( volatile u8 *)0x6C000000) // A0 = 0, CS = 0 #define CH376_CMD_PORT (*( volatile u8 *)0x6C000001) // A0 = 1, CS = 0

u8 RSM1[45]={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}; u8 RSM[45]={0}; u8 WCHH[45]; u8 u8Result; u8 u8Length; u8 *pu8Temp = RSM1; u8 *pu8Temp1 = WCHH;

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

#define HRES GPIO_SetBits(GPIOB, GPIO_Pin_12); //CH376復(fù)位信號高電平有效 #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--; } }

//描述: 查詢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 mInitCH376Host(void) //數(shù)據(jù)寫完需要關(guān)閉文件,否則文本中數(shù)據(jù)無法更新 { u8 u8Result; FSMC_SRAM_Init(); /* 接口硬件初始化 */ GPIO_SetBits(GPIOE, GPIO_Pin_3); 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ù)位,晶振不工作 */ } //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_USB_Function(void) { u8Result = mInitCH376Host();

if (u8Result == USB_INT_SUCCESS) { /*while (CH376DiskConnect() != USB_INT_SUCCESS) //檢查設(shè)備是否連接 { delay_ms(500); }*/

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

else { u8Result=CH376FileCreate("/WCHH.TXT"); // u8Result = CH376FileOpenPath("\\WCH.TXT"); u8Result=CH376FileOpen("/WCHH.TXT"); u8Length = CH376ReadBlock(pu8Temp); }

//if (u8Length != 0) if (u8Result == 0x14) { CH376DiskQuery((u32 *)pu8Temp1); // u8Result=CH376FileCreate("/WCHH.TXT"); u8Result=CH376FileOpen("/WCHH.TXT");

if (u8Result == USB_INT_SUCCESS) { // 獲取文件大小 u32FileLen = CH376GetFileSize();

while (u32DataCnt < u32FileLen) { CH376ByteWrite(RSM1, 45, 0); // // pu8Temp++; //CH376ByteRead(pu8Temp1, 2, 0); u32DataCnt += 1; } CH376FileClose(1); u8Result=CH376FileOpen("/WCHH.TXT"); if (u8Result == USB_INT_SUCCESS) { u32DataCnt=0; RealFileLen = CH376GetFileSize(); if (u32DataCnt < RealFileLen) { CH376ByteRead(pu8Temp1, RealFileLen, 0); // CH376ByteWrite((uint8_t *)buf, strlen(buf), NULL ); //CH376ByteRead(pu8Temp1, RealFileLen, 0); //CH376ByteRead(pu8Temp1, RealFileLen, 0); //u32DataCnt++; strcpy(RSM, WCHH ); /* 目標(biāo)文件名 strcpy( (char *)buf,(const char *)"\\YY.TXT" );*/ } } CH376FileClose(1); } } xWriteCH376Cmd(CMD11_SET_USB_MODE); /* 15 SD工作模式 */ 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((u32 *)pu8Temp1); u8Result=CH376FileCreate("/HUA.TXT"); u8Result=CH376FileOpen("/HUA.TXT"); if (u8Result == USB_INT_SUCCESS) { // 獲取文件大小 u32DataCnt=0; u32FileLen = CH376GetFileSize(); //u32FileLen作為實(shí)際長度 while (u32DataCnt < u32FileLen) { CH376ByteWrite(RSM, RealFileLen, 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; },我用的是STM32FSMC總線方式操作的(8位并口),每次寫SD卡沒有問題,但讀出來就不正確,容易掉數(shù)據(jù),現(xiàn)在設(shè)置的是45個(gè)數(shù)據(jù),讀出來就只要39個(gè),我是想把SD卡中的數(shù)據(jù)轉(zhuǎn)存到U盤中


不好意思,這個(gè)數(shù)組里只要36個(gè),但昨天測試的時(shí)候讀數(shù)據(jù)經(jīng)常會出現(xiàn)我昨天描述的問題,90個(gè)就是讀出90個(gè)9,48個(gè)數(shù)據(jù)就是讀出48個(gè)3


按照你的流程把數(shù)據(jù)改成寫45個(gè)數(shù)據(jù),讀45數(shù)據(jù)可以正常操作,首先你確保你寫正確,或者直接在電腦上創(chuàng)建文件,然后調(diào)用讀函數(shù)。 出現(xiàn)讀出90個(gè)9還是跟軟件編程有關(guān)系,有出錯(cuò)的程序才能分析問題。


哦,我在分析下,還有就是比如我采集的電壓數(shù)據(jù)0xfff,也就是滿偏電壓3.3V,這樣寫到SD卡中的數(shù)據(jù)該怎么處理一下,直接寫入就是查看就是ASC碼


內(nèi)部讀寫函數(shù)每次寫入1字節(jié)數(shù)據(jù),TXT文檔是以ASCII碼來查看的。所以你采集到的電壓數(shù)據(jù)得做處理,如分成兩個(gè)字節(jié)。


版主,我直接在電腦上創(chuàng)建文件再讀結(jié)果是一樣的,比如120個(gè),0-17位讀出來是好的,后面全是9,你覺得是總線速度的問題嗎,寫沒有任何問題的,下面是設(shè)置90時(shí)調(diào)試的結(jié)果20143710111981.jpg


讀跟寫的操作是類似的,你最好進(jìn)入CH376ByteRead監(jiān)控一下,是不是讀出buf有問題?


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

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