[求助]U盘初始化失败,帮帮忙啊!

我用8051控制ch375,液晶显示进行检测,发现U盘的初始化始终没法完成,初始化程序如下

ch375writecmd(0x51); del_5ms(); if(waitstatu()==0x14) { putstr(0," usb int success"); } else { putstr(0," usb int error! "); }

底层的3个读写函数是

unsigned char waitstatu(void) //等待并读取状态 { ch375_int=1; while(ch375_int); ch375writecmd(0x22); EA=1; return ch375readdata(); }

void ch375writecmd(unsigned char cmd) { P1=cmd; ch375_a0=1; ch375_rd=1; ch375_wr=0; ch375_cs=0; ; ch375_wr=1; ch375_cs=1; }

void ch375writedata(unsigned char value) { P1=value; ch375_a0=0; ch375_rd=1; ch375_wr=0; ch375_cs=0; ; ch375_wr=1; ch375_cs=1; }

unsigned char ch375readdata(void) { unsigned char value; P1=0xff; ch375_rd=0; ch375_wr=1; ch375_a0=0; ch375_cs=0; ; value=P1; ; ch375_rd=1; ch375_cs=1; return value; }

望指教,谢谢!!

unsigned char waitstatu(void) //等待并读取状态 { ch375_int=1; while(ch375_int); ch375writecmd(0x22); EA=1; return ch375readdata(); }

void ch375writecmd(unsigned char cmd) { P1=cmd; ch375_a0=1; ch375_rd=1; ch375_cs=0; ch375_wr=0; ; ch375_wr=1; ch375_cs=1; ch375_a0=0; }

void ch375writedata(unsigned char value) { P1=value; ch375_a0=0; ch375_rd=1; ch375_cs=0; ch375_wr=0; ; ch375_wr=1; ch375_cs=1; }

unsigned char ch375readdata(void) { unsigned char value; P1=0xff; ch375_wr=1; ch375_a0=0; ch375_cs=0; ch375_rd=0; ; value=P1; ; ch375_rd=1; ch375_cs=1; return value; } 还有就是你单片机用的是多少M的晶振?还有就是USB线要尽量的短点


你的三个读写子程序时序有点问题: 你按下面改下试试: void ch375writecmd(unsigned char cmd) { P1 = cmd; ch375_a0 = 1; ch375_rd=1; ch375_cs=0; ch375_wr=0; ch375_cs=0; ch375_wr=1; ch375_cs=1; ch375_a0=0;; P1 = 0xff; }

void ch375writedata(unsigned char value) { P1= value; ch375_cs=0; ch375_wr=0; ch375_cs=0;

ch375_wr=1; ch375_cs=1; P1= 0xff; }

unsigned char ch375readdata(void) { unsigned char value; P1=0xff; ch375_cs= 0; ch375_rd = 0; ch375_cs=0; value=P1; ch375_rd=1; ch375_cs=1; P1= 0xff; return( value); }


单片机晶振是11.0592,


   用上面的读写函数替换了,还是不行,返回值还是2CH


我直接将ch375芯片与单片机连接,这样能否使用文件级子程序中的CH375LibInit( )和CH375DiskReady( ) 如果能的话,U盘的初始化是在哪个函数中的,使用文件级子程序库时,芯片与单片机的接口连接是怎样的?


使用文件级子程序库,单片机系统需要具备不少于4KB到7KB的程序空间,不少于600字节的RAM.将库添加到工程中,就可以使用CH375LibInit( )和CH375DiskReady( )两个函数,CH375DiskReady( )这个函数是查询磁盘准备好,成功后就可以对U盘操作.芯片与单片机的接口连接支持并口和串口连接,FILELIB5中有串口操作的例子,FILELIB4中是并口连接的例子.具体的库说明可以看CH375EVT/CH375HF.PDF


你可以不可以将你的晶振提高点,例如换成22。1184,因为速度太慢也会出现问题


只有登录才能回复,可以选择微信账号登录