那你先插上U盘在库初始化之后,375的INT脚有变低吗??
在CH375Reset( );后没有中断,中断信号一直是高! 在ucErr = CH375LibInit( );中有一次中断,读取以后一直都是高电平信号! 请问这个有问题吗?
CH375LibInit()函数应该没有中断才对啊,那你读取之后有没有去看下中断状态是多少??
开始忘记读了,现在读了一下.读到的是DISK_CONNECT,表示设备已经连接!这样是不对的吗?
跟踪测试了以下,初始化顺序如下: (1)发送命令0x06(检测CH375工作是否正常),写入数据0x65,读到数据为0x9A; (2)发送命令0x06(检测CH375工作是否正常),写入数据0x9A,读到数据为0x65; (3)发送命令0x01(读取芯片及固件版本),读到数据为0xA4; (4)发送命令0x15(设置U盘工作模式),写入数据0x06; (5)连续10次延时xDelay100uS (6)读到数据为0x15(检测到USB设备连接事件). (7)产生USB中断 我跟踪的过程就是这个样子的! 其中第(3)个,我在数据手册上看到说明,采用CH375A,返回的应该是0XA2; 为什么返回的是0xA4?? 是不是这个有问题呢? 但是为什么我只是在读写U盘操作会出问题,其他操作比如bListAll()和CH375DiskQuery()都正常?
我只有明天上午上班了就放假了,所以期待贵公司技术人员能帮我看看初始化是不是有问题! 非常感谢!
那你看到你程序停在什么地方吗??,还有就是检测U盘连接应该是这样做: i = CH375LibInit( ); /* 初始化CH375程序库和CH375芯片,操作成功返回0 */ /* 其它电路初始化 */ while ( 1 ) { while ( CH375DiskStatus != DISK_CONNECT ) xQueryInterrupt( ); mDelaymS( 200 ); /* 延时,可选操作,有的USB存储器需要几十毫秒的延时 */ 如果你按照你说的先插下U盘不可以的话,那你一定要检测你程序停在什么地方
每次都是死在: void xQueryInterrupt( void ) /* 查询中断状态,等待硬件中断 */ { while ( CH375IntStatus == 0 ); /* 子程序库调用该子程序之前CH375IntStatus=0,硬件中断后,由中断服务程序置为非0的实际中断状态后返回 */ } 里面,检测不到中断了! 但是也奇怪哈! 为什么bListAll()和CH375DiskQuery()都正常? 这也一样有中断啊,而写数据和读数据就死掉了! 我自己的U盘是Diamond的,却可以正常的操作,而且我也跟踪进去了,流程和我说的是一样的,为什么有一些就不行呢? 而且按照技术资料的说明,理论上应该只可能是先插上是正常,而后插上可能会出问题,现在怎么反了,先插上还不行,非得要后插上才能正常读写文件! 感觉怪怪的!
你把下面的程序: while ( 1 ) { while ( CH375DiskStatus != DISK_CONNECT ) xQueryInterrupt( ); mDelaym(200 ); 换为: while ( 1 ) { while ( CH375DiskStatus != DISK_CONNECT ) CH375DiskConnect( );mDelaymS( 200 );
函数xQueryInterrupt( ); 我没有调用过,是在贵公司的子函数库里面调用的函数! 现在怎么改呢?
子函数库里面是在哪里调用这个函数呢?是不是可以改一下你们的子程序库呢? 我的调用的子程序库是"CH375HF9.LIB"
上面的这个函数是在库里面做好的,你可以直接调用
函数xQueryInterrupt( );原来原函数是在CH375HF9.H里面,但是因为我们工程里面按照你们提供的头文件,会提示出错,也是为了和我们公司的编写程序规范,我把该头文件里面原函数全部提到了我自己建立的CH375HF.C里面!而具体再哪里调用了xQueryInterrupt( ),都是由你们的子函数库决定的!我自己没有调过该函数! 现在问题是先插上U盘,则除了读写文件不能正常操作,而读磁盘信息和列举文件都正常.是不是哪里有问题?
那你读写U盘的函数在什么地方??
读写U盘的函数都是在CH375HF.C里面! 系统上电的时候,只是初始化CH375,初始化过程如下: CH375Reset( ); mDelaymS(100); ucErr = CH375LibInit( ); mDelaymS(100); for(j = 0; j < 5; j++) { if (CH375DiskStatus == DISK_CONNECT) break; mDelaymS(100); } if(j == 5) { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"没有检测到U盘!"); #else GUI_MsgBox((INT8U *)"Not find UDisk!"); #endif BuzzerCon(1, 600000); delay(0x00500000); g_pCurMenu = g_pRootM->child; g_pCurWin = g_pCurMenu->pWin; GUI_UpdataWindow(); } else { mDelaymS(300 ); /* 延时,可选操作,有的USB存储器需要几十毫秒的延时 */ if(j != 5) { for ( i = 0; i < 3; i ++ ) { /* 有的U盘总是返回未准备好,不过可以被忽略 */ mDelaymS( 100 ); if ( CH375DiskReady( ) == ERR_SUCCESS ) break; } } }
当需要从SDRAM拷贝文件到U盘中时,再开始执行写文件操作,操作如下: INT8U bRdSDRAMToUDisk(void) { extern WINDOWS gWinHandle; P_FAT_DIR_INFO mFileDir; BMCmdFileStart fileHead; BSchedule TmpSchedule; INT8U ucPathName[MAX_PATH_LEN]; INT32U uiFileIndex, uiSizeRead = 0, ulTmpData = 0; INT8U ucErr, ucSectorCount, ucFlag = 1;//, ucCharNum; INT32S iErr, i;
uiFileIndex = bfGetCurrentFileIndex(); bfOpenFile(uiFileIndex, 0, &g_pFile); bfReadFile(g_pFile, (INT8U *)&fileHead, BMCMD_FILE_START_SIZE, &uiSizeRead); bfCloseFile(g_pFile); bfOpenFile(uiFileIndex, 0, &g_pFile);
ucPathName[0] = '/'; for(i = 0; i < 8; i++) { if ( fileHead.ucFileName[i] >= 'a' && fileHead.ucFileName[i] <= 'z' ) //转换成大写字母 fileHead.ucFileName[i] = fileHead.ucFileName[i] - ( 'a' - 'A' ); ucPathName[i + 1] = fileHead.ucFileName[i]; if((fileHead.ucFileName[i] == '\0') || (fileHead.ucFileName[i] == '.')) { break; } } //ucCharNum = strlen((char *)fileHead.ucFileName); if(fileHead.ucFileName[i - 1] == '.') { ucPathName[i ] = 'U'; ucPathName[i + 1] = 'L'; ucPathName[i + 2] = 'E'; ucPathName[i + 3] = '\0'; } else { ucPathName[i + 1] = '.'; ucPathName[i + 2] = 'U'; ucPathName[i + 3] = 'L'; ucPathName[i + 4] = 'E'; ucPathName[i + 5] = '\0'; } ucErr = bCheckFileExist((INT8U*)&ucPathName[0]); if(ucErr != ERR_SUCCESS) ucFlag = 0; else { #ifdef __LANGUAGE_CHINESE__ gWinHandle.title = "文件存储中......"; #else #ifdef __LANGUAGE_SPANISH__ gWinHandle.title = "Guardar archivo"; #else gWinHandle.title = "Saving file..."; #endif #endif GUI_WindowsDraw((WINDOWS *)&gWinHandle); for(i = 0; i < MAX_PATH_LEN; i++) { mCmdParam.Create.mPathName[i] = ucPathName[i]; if(ucPathName[i] == '\0') break; } ucErr = CH375FileCreate(); if(ucErr == ERR_SUCCESS) { TmpSchedule.ulLast = 0; TmpSchedule.ulAll = fileHead.uiFileSize; TmpSchedule.ulStep = fileHead.uiFileSize / 100; if(fileHead.uiFileSize > FILE_DATA_BUF_LEN) { ucSectorCount = (FILE_DATA_BUF_LEN >> 9); while(1) { iErr = bfReadFile(g_pFile, (INT8U *)&FILE_DATA_BUF[0], FILE_DATA_BUF_LEN, &uiSizeRead); if(iErr == BFERR_FILE_NOT_OPENED_FOR_READ) { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"文件未打开!"); #else #ifdef __LANGUAGE_SPANISH__ GUI_MsgBox((INT8U *)"No est?listo para lectura"); #else GUI_MsgBox((INT8U *)"The file is not open!"); #endif #endif delay(0x00500000); ucFlag = 0; break; } else { mCmdParam.Write.mSectorCount = ((uiSizeRead + 511) >> 9); if(mCmdParam.Write.mSectorCount) { ucErr = CH375FileWrite( ); if(ucErr == ERR_SUCCESS) { ulTmpData += uiSizeRead; TmpSchedule.ulCurrent = ulTmpData; GUI_DrawScheduleBar(32, 38, (BSchedule *)&TmpSchedule); } else { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"存储文件失败!"); #else #ifdef __LANGUAGE_SPANISH__ GUI_MsgBox((INT8U *)"?rror al guardar archivo!"); #else GUI_MsgBox((INT8U *)"Failed to store the file!"); #endif #endif delay(0x00500000); ucFlag = 0; break; } } if(mCmdParam.Write.mSectorCount < ucSectorCount) { break; } } } } else { iErr = bfReadFile(g_pFile, (INT8U *)&FILE_DATA_BUF[0], FILE_DATA_BUF_LEN, &uiSizeRead); if(iErr == BFERR_FILE_NOT_OPENED_FOR_READ) { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"文件未打开!"); #else #ifdef __LANGUAGE_SPANISH__ GUI_MsgBox((INT8U *)"No est?listo para lectura"); #else GUI_MsgBox((INT8U *)"The file is not open!"); #endif #endif delay(0x00500000); ucFlag = 0; } else { mCmdParam.Write.mSectorCount =((uiSizeRead + 511 ) >> 9); ucErr = CH375FileWrite( ); if(ucErr == ERR_SUCCESS) { ulTmpData += uiSizeRead; TmpSchedule.ulCurrent = ulTmpData; GUI_DrawScheduleBar(32, 38, (BSchedule *)&TmpSchedule); } else { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"存储文件失败!"); #else #ifdef __LANGUAGE_SPANISH__ GUI_MsgBox((INT8U *)"?rror al guardar archivo!"); #else GUI_MsgBox((INT8U *)"Failed to store the file!"); #endif #endif delay(0x00500000); ucFlag = 0; } } } ucErr = CH375FileQuery( ); if(ucErr == ERR_SUCCESS) { mFileDir = (P_FAT_DIR_INFO)( (INT8U *)(&DISK_BASE_BUF[0]) + CH375vFdtOffset ); mFileDir->DIR_CrtDate = MAKE_FILE_DATE(fileHead.Time.usYear, fileHead.Time.ucMonth, fileHead.Time.ucDay); mFileDir->DIR_CrtTime = MAKE_FILE_TIME(fileHead.Time.ucHour, fileHead.Time.ucMin, fileHead.Time.ucSec); mFileDir->DIR_LstAccDate = MAKE_FILE_DATE(fileHead.Time.usYear, fileHead.Time.ucMonth, fileHead.Time.ucDay); } mCmdParam.Modify.mFileAttr = 0x20; // 存档文件 mCmdParam.Modify.mFileTime = MAKE_FILE_TIME(fileHead.Time.ucHour, fileHead.Time.ucMin, fileHead.Time.ucSec); mCmdParam.Modify.mFileDate = MAKE_FILE_DATE(fileHead.Time.usYear, fileHead.Time.ucMonth, fileHead.Time.ucDay); mCmdParam.Modify.mFileSize = fileHead.uiFileSize; ucErr = CH375FileModify( ); /* 修改当前文件的信息,修改日期和长度 */ if(ucErr != ERR_SUCCESS) { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"文件属性修改失败!"); #else GUI_MsgBox((INT8U *)"Failed to modify attribute!"); #endif delay(0x00500000); ucFlag = 0; } } else { #ifdef __LANGUAGE_CHINESE__ GUI_MsgBox((INT8U *)"创建文件失败!"); #else GUI_MsgBox((INT8U *)"Create file failure!"); #endif delay(0x00500000); ucFlag = 0; } mCmdParam.Close.mUpdateLen = 0; ucErr = CH375FileClose( ); } bfCloseFile(g_pFile); gSystem.ulSysStatus[gSystem.ulSysStatusCur] = STATUS_WAITING; g_pCurMenu = g_pRootM->child; //将系统界面切换到主界面 chenaihua 2006-03-11 g_pCurWin = g_pCurMenu->pWin; GUI_UpdataWindow(); CH375DirtyBuffer(); return ucFlag; }
当需要从U盘拷贝文件到SDRAM中时,执行读文件操作,操作如下: INT8U bRdUDiskToSDRAM(INT32U ulIndex) { extern WINDOWS gWinHandle; BSchedule TmpSchedule; BF_FileAttribute *pFileProp; INT8U i, j, ucErr, ucErrFlag = 1; INT16U usSecCount, ulCurCount = 0; INT32U ulTmpData = 0, ulFileCurSize; INT8U ucPathName[MAX_PATH_LEN]; INT32S iErr;
for (i = 0; i < MAX_PATH_LEN; i++) { ucPathName[i] = g_ucFilePath[i]; if(g_ucFilePath[i] == '\0') break; } for(j = 0 ; j < 16; j++) { ucPathName[i + j] = g_ucUFileName[ulIndex][j]; } ucErr = bChec