(1)晶振起振,12MHz (2)25脚为低电平,26脚为高电平 全部正常!
就这样结束了?
那你这样吧,把程序贴出来我们看看!
http://wch.cn/bbs/View.asp?S=101&I=24703 按这个主题的程序好了!问题现在就出现在这儿!按回贴的程序也试过了!行不通!
void CPU_Delay_US(word USTime)//精确的1us延时处理 { word i; for(i=0;i} void CH375_WR_CMD(byte Command) { CH375_WR=0; CH375_RD=1; CH375_CS=0; CH375_A0=1; Data_IO =0xff; CPU_Delay_US(3); CH375_Data=Command; CPU_Delay_US(3); CH375_WR=1; CH375_RD=1; CH375_CS=1; CH375_Data=0; }
void CH375_WR_DAT(byte Data) { CH375_WR=0; CH375_RD=1; CH375_CS=0; CH375_A0=0; Data_IO =0xff; CPU_Delay_US(2); CH375_Data=Data; CPU_Delay_US(2); CH375_WR=1; CH375_RD=1; CH375_CS=1; CH375_A0=1; CH375_Data=0; }
byte CH375_RD_DAT(void) { byte ReadByte; CH375_WR=1; CH375_RD=0; CH375_CS=0; CH375_A0=0; Data_IO =0x00; CPU_Delay_US(3); ReadByte=CH375_Data; Data_IO =0xff; CH375_WR=1; CH375_RD=1; CH375_CS=1; CH375_A0=1; CH375_Data=0; return ReadByte; }
byte Set_USB_Mode(void) { byte ReadByte; CH375_WR_CMD(CMD_SET_USB_MODE); CPU_Delay_US(20); CH375_WR_DAT(6); CPU_Delay_US(20); ReadByte=CH375_RD_DAT(); if(ReadByte==CMD_RET_SUCCESS) return TRUE; //操作成功 return FALSE; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
byte CHBUF[CHBUF_LENGTH]; SYS_INFO_BLOCK DeviceInfo; CH_CMD_BLOCK CHCmdBlock; CH_RSP_BLOCK CHRspBlock; FILE_INFO ThisFile;
byte EnumMassDev(void) { byte ReadByte; PMBR_BLOCK pMBR; PBPB_BLOCK pBPB; CH375_WR_CMD(CMD_DISK_INIT); // 初始化USB存储器 CPU_Delay_US(20); if(mWaitInterrupt()!=USB_INT_SUCCESS) return FALSE; // U盘已经成功初始化
pMBR=(PMBR_BLOCK)DBUF; DeviceInfo.BPB_BytesPerSec=512; //暂假设为512
//检查USB存储器错误 CH375_WR_CMD(CMD_DISK_R_SENSE); CPU_Delay_US(20); if(mWaitInterrupt()!=USB_INT_SUCCESS ) return FALSE; //读容量 if(!ReadCapacity()) return FALSE;
//读指定扇区的数据到给这缓冲区中 //未调通 if(!RBC_Read(0x00,1,DBUF)) return FALSE; /* if(DBUF[0]==0xeb||DBUF[0]==0xe9) { DeviceInfo.StartSector=0; } else { DeviceInfo.StartSector=Swapdword(pMBR->StartSector); }
pBPB=(PBPB_BLOCK)DBUF; if(!RBC_Read(DeviceInfo.StartSector,1,DBUF)) return FALSE;
DeviceInfo.BPB_BytesPerSec=Swapword(pBPB->BPB_BytesPerSec); DeviceInfo.BPB_SecPerClus=pBPB->BPB_SecPerClus; DeviceInfo.BPB_NumFATs=pBPB->BPB_NumFATs; DeviceInfo.BPB_RootEntCnt=Swapword(pBPB->BPB_RootEntCnt); DeviceInfo.BPB_TotSec16=Swapword(pBPB->BPB_TotSec16); DeviceInfo.BPB_FATSz16=Swapword(pBPB->BPB_FATSz16); DeviceInfo.BPB_TotSec32=Swapdword(pBPB->BPB_TotSec32); DeviceInfo.FatStartSector=DeviceInfo.StartSector+pBPB->BPB_RsvdSecCn[0]; DeviceInfo.RootStartSector=DeviceInfo.StartSector+2*DeviceInfo.BPB_FATSz16+pBPB->BPB_RsvdSecCn[0]; DeviceInfo.FirstDataSector=DeviceInfo.FatStartSector+2*DeviceInfo.BPB_FATSz16+32; ThisFile.bFileOpen=0; bXXGFlags.bits.SLAVE_IS_ATTACHED=1; */ return TRUE; }
byte mWaitInterrupt(void) { byte ReadByte=0; while (CH375_INT_WIRE) ; // 如果CH375的中断引脚输出高电平则等待 while(!CH375_INT_WIRE) // 保证能取消中断状态 { CH375_WR_CMD(CMD_GET_STATUS); // 获取当前中断状态 CPU_Delay_US(20); ReadByte=CH375_RD_DAT(); // 返回中断状态 CPU_Delay_US(20); } return(ReadByte); }
//#define TranR_D; byte ReadCapacity(void) { byte *buf; byte ReadByte=0; #ifdef TranR_D byte SaveLong=0; #endif buf=DBUF; CH375_WR_CMD(CMD_DISK_SIZE);// 读取容量 CPU_Delay_US(20); while(mWaitInterrupt()!=USB_INT_SUCCESS) { CPU_Delay_US(20); CH375_WR_CMD(CMD_DISK_SIZE);// 读取容量 CPU_Delay_US(20); } CH375_WR_CMD(CMD_RD_USB_DATA); // 从CH375缓冲区读取数据块 CPU_Delay_US(300); ReadByte=CH375_RD_DAT(); // 后续数据的长度 CPU_Delay_US(20); #ifdef TranR_D SaveLong=ReadByte; #endif while(ReadByte) // 根据长度读取数据并保存 { *buf=CH375_RD_DAT(); buf++; ReadByte--; CPU_Delay_US(20); } #ifdef TranR_D for(ReadByte=0;ReadByte { SCI0DRL=DBUF[ReadByte]; while((SCI0SR1&0x80)==0) ; } #endif return TRUE; }
//iLbaStart 是读取的线起始性扇区号, iSectorCount 是读取的扇区数 byte RBC_Read(dword iLbaStart, byte iSectorCount,byte *mBufferPoint) { word mBlockCount; byte ReadByte=0; byte SaveLong=0;
SCI0DRL=0x11;//用于示波器查找本部分程序运行起始位置 while((SCI0SR1&0x80)==0) ; CPU_Delay_US(500); CH375_WR_CMD(CMD_DISK_READ); // 从USB存储器读数据块 CPU_Delay_US(20); CH375_WR_DAT((byte)iLbaStart); // LBA的最低8位 CPU_Delay_US(20); CH375_WR_DAT((byte)(iLbaStart>>8)); CPU_Delay_US(20); CH375_WR_DAT((byte)(iLbaStart>>16)); CPU_Delay_US(20); CH375_WR_DAT((byte)(iLbaStart>>24)); // LBA的最高8位 CPU_Delay_US(20); CH375_WR_DAT(iSectorCount); // 扇区数 for(mBlockCount=iSectorCount*CH375_BLK_PER_SEC; mBlockCount!=0; mBlockCount--) { if(mWaitInterrupt()==USB_INT_DISK_READ) { CH375_WR_CMD(CMD_RD_USB_DATA); // 从CH375缓冲区读取数据块 CPU_Delay_US(30); ReadByte=CH375_RD_DAT(); ReadByte=64; while (ReadByte) { CPU_Delay_US(10); *mBufferPoint=CH375_RD_DAT(); mBufferPoint++; ReadByte--; } CH375_WR_CMD(CMD_DISK_RD_GO); } else break; } if(mBlockCount==0) { // 等待中断并获取状态 SCI0DRL=0x55; while((SCI0SR1&0x80)==0) ; if(mWaitInterrupt()==USB_INT_SUCCESS) return TRUE; // 操作成功 } SCI0DRL=0xAA; while((SCI0SR1&0x80)==0) ; SCI0DRL=mBlockCount; while((SCI0SR1&0x80)==0) ; return FALSE; // 操作失败 }
程序员怀疑硬件电路上有问题!
你的时序由些问题 void CH375_WR_CMD(byte Command) { CH375_Data=Command; Data_IO =0xff; /* 置输出方向 */ CH375_RD=1; CH375_A0=1; CH375_CS=0; CH375_WR=0; /*添加100ns的延时*/ CH375_WR=1; CH375_CS=1; CH375_A0=0; Data_IO =0x00; /* 置输入方向 */ }
void CH375_WR_DAT(byte Data) { CH375_Data=Data; Data_IO =0xff; /* 置输出方向 */ CH375_RD=1; CH375_A0=0; CH375_CS=0; CH375_WR=0; /*添加100ns的延时*/ CH375_WR=1; CH375_CS=1; Data_IO =0x00; /* 置输入方向 */ }
byte CH375_RD_DAT(void) { byte ReadByte;
Data_IO =0x00; /* 置输入方向 */ CH375_WR=1; CH375_A0=0; CH375_CS=0; CH375_RD=0; /*添加100ns的延时*/ ReadByte = CH375_Data; CH375_RD=1; CH375_CS=1; return ReadByte; }