[求助]CH376寫入資料請教

各位前輩們好,小弟在使用CH376的時候遇到了一個問題就是使用單芯片發(fā)指令建立一個TEST.TXT的文本文件,然后針對這個文本文件進行寫入的動作寫入動作都不成功,可是如果是在計算機上建立一個TEST.TXT檔案在使用單芯片執(zhí)行OPEN File然后針對這個TEST.TXT的文本文件做寫入的話寫入數(shù)據(jù)就會成功,目前看到的差異是使用單芯片建立TEST.TXT的時候文本文件里面會多出一個"1"的字符,請問建立檔案的時候怎樣才不會產(chǎn)生字符或者是說怎么使用覆蓋的方式來處理這個問題呢?還是說還有其他解決方法呢?請前輩們指教,感謝!

以下昰我的程式碼 while(1) { PORTB = 0X00; Delay5ms(20);

//Test communication interface and work status while(CHECK_EXIST() != 0x00) Delay5ms(1); PORTBbits.RB0 = 1; UART1_RX_Value_Buffer = 0; //Setting the USB mode while(SET_USB_MODE()!= 0x51) Delay5ms(1); PORTBbits.RB1 = 1; UART1_RX_Value_Buffer = 0; //Initialize the disk and test disk ready while(DISK_MOUNT()!=0x14) Delay5ms(1); PORTBbits.RB2 = 1; UART1_RX_Value_Buffer = 0; //Set to operate on the file name Delay5ms(1); SET_FILE_NAME(); PORTBbits.RB3 = 1; UART1_RX_Value_Buffer = 0; //Open the file or directory, enumerate files and directories while(FILE_OPEN()!=0x14) Delay5ms(1); PORTBbits.RB4 = 1; UART1_RX_Value_Buffer = 0; //while(BYTE_LOCATE()!=0x14)

BYTE_LOCATE(); Delay5ms(100); UART1_RX_Value_Buffer = 0; //Create documents // while(FILE_CREATE()!=0x14) // Delay5ms(1); // PORTBbits.RB4 = 1; // UART1_RX_Value_Buffer = 0; //===============================================================

//In bytes of the write data block to the current location //while(BYTE_WRITE()!=0x1E) BYTE_WRITE(); Delay5ms(1); PORTBbits.RB5 = 1; UART1_RX_Value_Buffer = 0; //Specified buffer to the internal write request data blocks Delay5ms(1); WR_REQ_DATA(); PORTBbits.RB6 = 1; UART1_RX_Value_Buffer = 0; //Continue byte write while(BYTE_WR_GO()!=0x14) //BYTE_WR_GO(); Delay5ms(1); BYTE_WR_GO(); PORTBbits.RB7 = 1; UART1_RX_Value_Buffer = 0; //Closes the currently open file or directory while(FILE_CLOSE()!=0x14) Delay5ms(1); PORTBbits.RB8 = 1; UART1_RX_Value_Buffer = 0;

Delay5ms(200);

//================================================================== //Test communication interface and work status unsigned char CHECK_EXIST() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x06); UART1_Send_Value(0xFF); return UART1_RX_Value_Buffer; } ////Setting the USB mode unsigned char SET_USB_MODE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x15); UART1_Send_Value(0x03); return UART1_RX_Value_Buffer; } //Initialize the disk and test disk ready unsigned char DISK_MOUNT() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x31); return UART1_RX_Value_Buffer; } //Set to operate on the file name unsigned char SET_FILE_NAME() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2F); char data[] = "TEST.TXT"; UART1_Send_String(data);

//TEST.TXT //UART1_Send_Value(0x54); //UART1_Send_Value(0x45); //UART1_Send_Value(0x53); //UART1_Send_Value(0x54); //UART1_Send_Value(0x2E); //UART1_Send_Value(0x54); //UART1_Send_Value(0x58); //UART1_Send_Value(0x54); return UART1_RX_Value_Buffer; } //Create documents unsigned char FILE_CREATE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x34); return UART1_RX_Value_Buffer; }

unsigned char BYTE_WRITE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x3C); UART1_Send_Value(0x0A); UART1_Send_Value(0x0A>>8); return UART1_RX_Value_Buffer; }

unsigned char BYTE_READ() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x3A); return UART1_RX_Value_Buffer; } unsigned char WR_REQ_DATA() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2D);

UART1_Send_Value(0x31); UART1_Send_Value(0x32); UART1_Send_Value(0x31); UART1_Send_Value(0x32); UART1_Send_Value(0x41); UART1_Send_Value(0x0D); // \r UART1_Send_Value(0x0A); // \n UART1_Send_Value(0x45); UART1_Send_Value(0x47); UART1_Send_Value(0x48); return UART1_RX_Value_Buffer; }

unsigned char BYTE_WR_GO() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x3D); return UART1_RX_Value_Buffer; }

unsigned char FILE_CLOSE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x36); UART1_Send_Value(0x01); return UART1_RX_Value_Buffer; }

unsigned char FILE_OPEN() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x32); return UART1_RX_Value_Buffer; }

unsigned char WR_OFS_DATA() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2E); UART1_Send_Value(0x00); UART1_Send_Value(0x05);

UART1_Send_Value(0x42); UART1_Send_Value(0x42); UART1_Send_Value(0x42); UART1_Send_Value(0x46); UART1_Send_Value(0x46); return UART1_RX_Value_Buffer; }

unsigned char BYTE_LOCATE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x39);

UART1_Send_Value(0xFF); UART1_Send_Value(0xFF); UART1_Send_Value(0xFF); UART1_Send_Value(0xFF); }


熱門產(chǎn)品 : USB3.0 HUB控制器:CH634

我們CH376創(chuàng)建文件成功的話會產(chǎn)生長度為1個字符的文件,這是正?,F(xiàn)象。你遇到的問題是文件寫不進去,文件寫完之后需要更新文件長度的??戳四愕某绦?,在發(fā)送CMD01_WR_REQ_DATA(2DH)命令后,需要讀取可以往CH376數(shù)據(jù)長度,之后才是寫數(shù)據(jù)。


前輩好,我目前測試的結(jié)果是假如我將TEST.TXT的文字內(nèi)容刪除那可以CH376S可以正常打開文件,可是假設文件內(nèi)有資料的話就沒辦法正常打開文件,回復錯誤代碼是42,可否請前輩指點,感謝!


你之前內(nèi)容寫不進文件的問題還有可能是寫延遲問題,你可以這樣試一下先關閉文件,再創(chuàng)建文件,再刪除看看能否解決? 另外,返回0x42代表沒有找到文件,你可以在電腦上創(chuàng)建一個文件寫入內(nèi)容,再用CH376看看能否正常打開。


現(xiàn)在的狀況是我只要文件內(nèi)有資料的話要開啟檔案就會反回0x42,假設文件內(nèi)沒有資料的話就可以找的到檔案,這個問題還蠻奇怪的,我的程式內(nèi)容如下,可否請前輩抽空指點,感謝!

while(1) { PORTB = 0X00; Delay5ms(20);

//Test communication interface and work status while(CHECK_EXIST() != 0x00) Delay5ms(1); PORTBbits.RB0 = 1; UART1_RX_Value_Buffer = 0; //Setting the USB mode while(SET_USB_MODE()!= 0x51) Delay5ms(1); PORTBbits.RB1 = 1; UART1_RX_Value_Buffer = 0; //Initialize the disk and test disk ready while(DISK_MOUNT()!=0x14) Delay5ms(1); PORTBbits.RB2 = 1; UART1_RX_Value_Buffer = 0; //Set to operate on the file name Delay5ms(1); SET_FILE_NAME(); PORTBbits.RB3 = 1; UART1_RX_Value_Buffer = 0; //Open the file or directory, enumerate files and directories while(FILE_OPEN()!=0x14) Delay5ms(1); FILE_OPEN(); PORTBbits.RB4 = 1; UART1_RX_Value_Buffer = 0; //============================================================ unsigned char CHECK_EXIST() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x06); UART1_Send_Value(0xFF); return UART1_RX_Value_Buffer; } ////Setting the USB mode unsigned char SET_USB_MODE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x15); UART1_Send_Value(0x03); return UART1_RX_Value_Buffer; } //Initialize the disk and test disk ready unsigned char DISK_MOUNT() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x31); return UART1_RX_Value_Buffer; } //Set to operate on the file name unsigned char SET_FILE_NAME() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2F); char data[] = "TEST.TXT"; UART1_Send_String(data); }

unsigned char FILE_OPEN() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x32); return UART1_RX_Value_Buffer; }


目前的狀況是只要TEST.TXT檔案內(nèi)有數(shù)據(jù)我用OPEN File就會回傳0x42(找不到數(shù)據(jù))假設TEST.TXT檔案內(nèi)容凈空,那用OPEN File就可以找到數(shù)據(jù),我的代碼如下,可否請錢被抽空指點,感謝!

while(1) { PORTB = 0X00; Delay5ms(20);

//Test communication interface and work status while(CHECK_EXIST() != 0x00) Delay5ms(1); PORTBbits.RB0 = 1; UART1_RX_Value_Buffer = 0; //Setting the USB mode while(SET_USB_MODE()!= 0x51) Delay5ms(1); PORTBbits.RB1 = 1; UART1_RX_Value_Buffer = 0; //Initialize the disk and test disk ready while(DISK_MOUNT()!=0x14) Delay5ms(1); PORTBbits.RB2 = 1; UART1_RX_Value_Buffer = 0; //Set to operate on the file name Delay5ms(1); SET_FILE_NAME(); PORTBbits.RB3 = 1; UART1_RX_Value_Buffer = 0;

//Open the file or directory, enumerate files and directories while(FILE_OPEN()!=0x14) Delay5ms(1); FILE_OPEN(); PORTBbits.RB4 = 1; UART1_RX_Value_Buffer = 0; } //=========================================================== //Test communication interface and work status unsigned char CHECK_EXIST() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x06); UART1_Send_Value(0xFF); return UART1_RX_Value_Buffer; } ////Setting the USB mode unsigned char SET_USB_MODE() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x15); UART1_Send_Value(0x03); return UART1_RX_Value_Buffer; } //Initialize the disk and test disk ready unsigned char DISK_MOUNT() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x31); return UART1_RX_Value_Buffer; } //Set to operate on the file name unsigned char SET_FILE_NAME() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x2F); char data[] = "TEST.TXT"; UART1_Send_String(data); } unsigned char FILE_OPEN() { UART1_Send_Value(0x57); UART1_Send_Value(0xAB); UART1_Send_Value(0x32); return UART1_RX_Value_Buffer; }


你文件名換成"\\TEST.TXT"或者"/TEST.TXT"試一下?


前輩好,我現(xiàn)在遇到的問題是只要文件內(nèi)有數(shù)據(jù)用open file就找不到檔案,假設文件內(nèi)容是凈空的,用open file就找的到檔案,不會回傳0x42,請前輩指點,感謝!


文件的打開與文件里面有無內(nèi)容沒有關系的,你先用6樓的方法試一下?


請教前輩,對CH376下指令有規(guī)定每個指令之間要多少時間的延遲嗎?


命令與命令、數(shù)據(jù)之間間隔1.5us,數(shù)據(jù)與數(shù)據(jù)之間延時0.6us


前輩好,我在計算機上創(chuàng)建一個文件,只要這個文件內(nèi)容是凈空的,CH376就可以讀取到這個文件,假設這個文件內(nèi)容不是凈空的,CH376就找不到文件,不知道前輩知道這是什么原因嗎?請前輩指點,感謝!


前輩好,目前文件內(nèi)容非淨空狀態(tài)以經(jīng)可以找到文件,目前的狀況是只要文件內(nèi)容非淨空,就沒辦法順利寫資料進去,可以請教前輩文件有內(nèi)容就無法寫資料進去可能是哪些問題引起的呢?請前輩抽空指點,感謝!


文件的空和非空和你寫入數(shù)據(jù)應該沒什么關系,主要看你寫入的時候是需要在文件后面追加數(shù)據(jù)還是打開文件直接寫數(shù)據(jù)。如果是追加數(shù)據(jù),則需要使用LOCATE函數(shù)跳至你需要追加的位置。然后寫數(shù)據(jù)。如果是直接寫數(shù)據(jù),則打開文件之后直接寫數(shù)據(jù)。每次寫完之后需要更新文件長度。關閉文件。每次調(diào)用函數(shù)請監(jiān)控文件的返回狀態(tài)。


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

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