44B0正常操作U盤,后面的帖有CH375源程序。

呵呵,自從上次識(shí)別U盤容量正確后,休息了好多天,今天晚上心血來潮,編寫了CH375讀寫扇區(qū)的程序,將原來編寫的CF卡讀寫文件的程序稍作修改,就可以正常讀寫刪U盤文件了。 FAT16格式的。一切CH375代碼都有源程序,按照沁恒提供的數(shù)據(jù)手冊作的,有疑問的在這里詢問后得以解決,不是引用的庫文件。

空有訪問量,沒有回帖量,郁悶,今天把主帖改為回帖可見,其實(shí)真正內(nèi)容在"第2樓".

今天再添加一條廣告: 想購買44B0+U盤+CF+CPLD套件的請(qǐng)聯(lián)系個(gè)人信息保護(hù),已隱藏,價(jià)格450圓(可以讀寫U盤或CF卡扇區(qū)).如果包含F(xiàn)AT16源代碼價(jià)格880圓(只可以讀寫刪FAT16根目錄文件,子目錄下的文件訪問不支持).

能貼出來讓我們分享嗎?


//********************CH375.C**************** /*; CH375/CH372 EVT ; U1(S3C44B0) Program ; ; Website: http:// ; Email: PEIYUAN@2911.NET ; Author: WUHAN 2004.12 ; ;**************************************************************************** */ #include #include "..\inc\44b.h" #include "..\inc\44blib.h" #include "..\inc\CH375.h"

#include #include #include #include #include

//**************************************************************************** #define SUCCESS 0 #define ERROR_READFILE_NOFILE -1 #define ERROR_READFILE_LONGFILENAME -2 #define ERROR_READFILE_BADFILENAME -3 #define ERROR_WRITEFILE_NOSPACE -11 #define ERROR_WRITEFILE_FULLRDT -12 #define ERROR_WRITEFILE_BADCLUSTER -13 #define ERROR_WRITEFILE_FILEEXIST -14

//**************************************************************************** extern unsigned char Usb_Buf_Len; extern unsigned char Usb_Buf[64]; extern U8* Usb_Buf_Startp; extern U8* Usb_Buf_Endp; extern U8 Usb_INT_HAVE; extern U8 Usb_INT_STATUS;

//**************************************************************************** //**************************************************************************** //****************************************************************************

//**************************************************************************** void CH375WriteCommand(U8 commandvalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Command_Address, commandvalue); for (loop=0;loop<20;loop++) { ; } }

//**************************************************************************** void CH375WriteData(U8 datavalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Data_Address, datavalue); for (loop=0;loop<5;loop++) { ; } }

//**************************************************************************** U8 CH375ReadData(void) { char i; U32 loop; for (loop=0;loop<5;loop++) { ; } i=inportb(Ch375_Base_Address + Ch375_Data_Address); return i; }

//**************************************************** void CH375_check(void) { CH375WriteCommand(CHECK_EXIST); CH375WriteData(0x55); if (CH375ReadData()==0xaa) { } else { Uart_Printf("\nChip CH375 test error!"); //while(1); } Uart_Printf("\nChip USB test OK!\n"); } //**************************************************** void CH375_setmode(U8 mode) { U8 i,f; f=1; while(f==1) { CH375WriteCommand(SET_USB_MODE); Delay(15); CH375WriteData(mode); Delay(15); i=CH375ReadData(); if (i==CMD_RET_SUCCESS) { f=0; } Delay(1000); } Uart_Printf("Chip USB SET MODE %x\n",mode); } //**************************************************** U8 CH375_get_status(void) { CH375WriteCommand(GET_STATUS); return CH375ReadData(); } //**************************************************** void CH375_Init(void) { CH375_check(); CH375_setmode(0x02); }

//**************************************************** void CH375_Read(void) { int i; CH375WriteCommand(RD_USB_DATA); Usb_Buf_Len=CH375ReadData(); for (i=0;i { Usb_Buf[i]=CH375ReadData(); } }

//**************************************************** void CH375_Write(void)//U8* Usb_Buf_Startp;U8* Usb_Buf_Endp; { U8 k; int i; //int time; //Timer_Start(3);//128us resolution

if ((Usb_Buf_Endp-Usb_Buf_Startp)>64) { Usb_Buf_Len=64; } else { Usb_Buf_Len=Usb_Buf_Endp-Usb_Buf_Startp; } CH375WriteCommand(WR_USB_DATA7); CH375WriteData(Usb_Buf_Len); for (i=0;i { k=*Usb_Buf_Startp; CH375WriteData(k); //Uart_Printf("%x",k); Usb_Buf_Startp++; } //time=Timer_Stop(); //Uart_Printf("%f\n",time*128E-6); }

//**************************************************** void CH375_Unlock_Usb(void) { CH375WriteCommand(UNLOCK_USB); }

//**************************************************** void CH375_Reset_All(void) { CH375WriteCommand(RESET_ALL); }

//****************************************************//**************************************************** //****************************************************//**************************************************** //****************************************************//**************************************************** //****************************************************//****************************************************

//****************************************************

void CH375_INIT_Wait(void) { while(Usb_INT_HAVE==0) { } Usb_INT_HAVE=0; }

//****************************************************

void CH375_Disk_Reset(void) { U8 i; CH375WriteCommand(DISK_RESET); }

//****************************************************

U32 CH375_Disk_Size(void) {

}

//****************************************************

void CH375_Disk_Read(void) {

}

//****************************************************

void CH375_Disk_ReadGo(void) {

}

//****************************************************

void CH375_Disk_Write(void) {

}

//****************************************************

void CH375_Disk_WriteGo(void) {

}

//****************************************************

U32 CH375_Disk_Init(void) { U16 i,j; U32 Size_Udisk; CH375_check(); CH375_setmode(0x06);//usb host

Delay(200); CH375_INIT_Wait(); while(Usb_INT_STATUS!=USB_INT_CONNECT) { }

Delay(2000); CH375WriteCommand(DISK_INIT); CH375_INIT_Wait(); while(Usb_INT_STATUS!=USB_INT_SUCCESS) { }

Delay(2000); Usb_Buf[6]=0xff; while( (Usb_Buf[4]!=0x00)|(Usb_Buf[5]!=0x00)|(Usb_Buf[6]!=0x02)|(Usb_Buf[7]!=0x00) ) { for (j=0;j<20000;j++) { Delay(200); CH375WriteCommand(DISK_SIZE); CH375_INIT_Wait(); if (Usb_INT_STATUS=USB_INT_SUCCESS) break; } CH375_Read(); } Size_Udisk=(Usb_Buf[0]*256*256*256)+(Usb_Buf[1]*256*256)+(Usb_Buf[2]*256)+(Usb_Buf[3]); Size_Udisk=Size_Udisk*0x0200; return Size_Udisk; }

//************************************************************************

S8 CH375_LbaRead(U8 *buffaddr,U32 LbaNo,U8 SecNum) { U8 i; CH375WriteCommand(DISK_READ); CH375WriteData(((LbaNo>>0)&0xff)); CH375WriteData(((LbaNo>>8)&0xff)); CH375WriteData(((LbaNo>>16)&0xff)); CH375WriteData(((LbaNo>>24)&0xff)); CH375WriteData(SecNum); while (1) { CH375_INIT_Wait(); switch (Usb_INT_STATUS) { case USB_INT_DISK_READ: CH375_Read(); for (i=0;i { *buffaddr=Usb_Buf[i]; buffaddr++; } CH375WriteCommand(DISK_RD_GO); break; case USB_INT_SUCCESS: return SUCCESS; break; default : return ERROR_WRITEFILE_BADCLUSTER; break; } } }

//********************************************************************** S8 CH375_LbaWrite(U8 *buffaddr,U32 LbaNo,U8 SecNum) { U8 i; CH375WriteCommand(DISK_WRITE); CH375WriteData(((LbaNo>>0)&0xff)); CH375WriteData(((LbaNo>>8)&0xff)); CH375WriteData(((LbaNo>>16)&0xff)); CH375WriteData(((LbaNo>>24)&0xff)); CH375WriteData(SecNum); while (1) { CH375_INIT_Wait(); switch (Usb_INT_STATUS) { case USB_INT_DISK_WRITE: Usb_Buf_Startp=buffaddr; buffaddr=buffaddr+64; Usb_Buf_Endp=buffaddr; CH375_Write();//void CH375_Write(void)//U8* Usb_Buf_Startp;U8* Usb_Buf_Endp; CH375WriteCommand(DISK_WR_GO); break; case USB_INT_SUCCESS: return SUCCESS; break; default : return ERROR_WRITEFILE_BADCLUSTER; break; } } }


有參考意義,謝謝!


12


請(qǐng)問你44b0降主頻了嗎?把main函數(shù)也貼出來看看吧,我做測試命令 CH375_WR_CMD_PORT( CMD_CHECK_EXIST ); /* 測試CH375是否正常工作 */ CH375_WR_DAT_PORT( 0x55 ); /* 寫入測試數(shù)據(jù) */ 返回是 0啊,是不是我的讀寫時(shí)序有問題?


不需要降頻(66M),只需要這樣延時(shí)即可. //**************************************************************************** void CH375WriteCommand(U8 commandvalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Command_Address, commandvalue); for (loop=0;loop<20;loop++) { } }

//**************************************************************************** void CH375WriteData(U8 datavalue) { U32 loop; outportb(Ch375_Base_Address + Ch375_Data_Address, datavalue); for (loop=0;loop<5;loop++) { } }

//**************************************************************************** U8 CH375ReadData(void) { char i; U32 loop; for (loop=0;loop<5;loop++) { } i=inportb(Ch375_Base_Address + Ch375_Data_Address); return i; }

你測試不過關(guān)請(qǐng)參看2樓中的程序,這是部分摘錄: U32 CH375_Disk_Init(void) { U16 i,j; U32 Size_Udisk; CH375_check();


good


程序太干凈了,呵呵


haha


;)


學(xué)習(xí)中


eee



謝謝,參考一下


調(diào)通一個(gè)在main中死等讀寫U盤,不干別的事的程序,再快也是沒什么意義的.把你的程序加上FIQ中斷嵌套幾個(gè)IRQ中斷并在后臺(tái)把U盤做存儲(chǔ)器隨時(shí)讀寫數(shù)據(jù)試試! 我正用STR710做如此工作,好象比較艱難.


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

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