STC89C58控制CH375A芯片读写U盘问题

我正在用STC89C58单片机控制CH375A芯片读写U盘,电路图基本按照CH375DS1.pdf文档中并行方式,我只是省去了U3、U4、U5,而直接把CH375的A0、RD#、WR#、CS#、INT#和D0-D7引脚直接连接到单片机的IO引脚上,具体接法看我下面程序的引脚定义更清楚。单片机的串口我用来输出数据到电脑上显示CH375返回的数据以便于分析。我下载程序到单片机上运行,出现的现象: 1、不管输入任何命令,CH375好像并没有数据返回,理由是我读CH375的数据口时返回的值都是单片机最后一次发给CH375的值; 2、插入U盘,串在ACT#引脚上的LED灯长亮,拔出U盘后则灭。

按我的分析,现象2说明了CH375已经成功设置了USB工作模式,说明CH375已经成功接收我命令(设置工作模式为06),也说明的写命令和写数据的函数是正确的。但是现象1我一直查不出原因,下面是我的程序,各位帮我分析分析,谢谢。

//这就是我的测试程序了 #include "reg52.h" #include #include "CH375_CMD.h" //CH375命令和常数的定义

#define CH375_IO P2 //数据口

sbit CH375_CS = P1^7; //CH375片选 sbit CH375_A0 = P1^6; //CH375数据命令选择 sbit CH375_WR = P1^5; //CH375写选通 sbit CH375_RD = P1^4; //CH375读选通 sbit CH375_INT = P3^2; //CH375中断

#define Select_Ch375( ) CH375_CS=0; #define Release_Ch375( ) CH375_CS=1;

#define Switch_Data( ) CH375_A0=0; #define Switch_cmd( ) CH375_A0=1;

#define Write_On( ) CH375_WR=0; #define Write_Off( ) CH375_WR=1;

#define Read_On( ) CH375_RD=0; #define Read_Off( ) CH375_RD=1;

void Init_Ser(void) //功能:初始化串口通讯 { //中断允许 EA = 1; ES = 1; //允许串口中断 EX0 = 1; //允许外部中断0 //定时器T1设置,波特率9600,11.0592M TMOD = 0x20; TH1 = 0xfd; TL1 = 0xfd; //通讯模式设置 SM0 = 0; SM1 = 1; REN = 1; //允许接收 TR1 = 1; //启动定时器 }

void SendStrToPC(uint8 *p) //功能:向PC串口发送字符串 { while(*p!='\0') { SBUF = (*p); while(!TI); TI = 0; p++; } }

void SendCHToPC(uint8 ch) //功能:向PC串口发送一个字符 { SBUF =ch; while(!TI); TI = 0; }

void mDelay100mS( ) { unsigned char i, j, c; for ( i = 200; i != 0; i -- ) for ( j = 200; j != 0; j -- ) c+=3; }

void CH375_Write_cmd(uint8 cmdCode) //写命令 { Switch_cmd(); Read_Off( ); Write_Off(); CH375_IO = cmdCode; Write_On(); _nop_(); Write_Off(); Switch_Data(); CH375_IO=0xFF; }

void CH375_Write_Data(uint8 myData) //写数据 { Switch_Data(); Read_Off( ); Write_Off(); CH375_IO = myData; Write_On(); _nop_(); Write_Off(); CH375_IO=0xFF; //Switch_cmd(); }

uint8 CH375_Read_Data(void) //读数据 { uint8 temp; Switch_Data( ); Write_Off(); Read_Off( ); CH375_IO = 0xff; Read_On( ); _nop_(); temp = CH375_IO; Read_Off( ); //Switch_cmd( ); return (temp); }

uint8 CH375_Read_Sta(void) //读中断状态 { uint8 temp; Switch_cmd( ); Write_Off(); Read_Off( ); CH375_IO = 0xff; Read_On( ); _nop_(); temp = CH375_IO; Read_Off( ); Switch_Data( ); //Switch_cmd( ); return (temp); }

void Interrupt_int0(void) interrupt 0 //功能:处理外部中断 { uchar i; CH375_Write_cmd(CMD_GET_STATUS); for(i=40;i>0;i--)i--; SendCHToPC(CH375_Read_Sta()); }

void Inter_Ser(void) interrupt 4 //功能:处理串口中断 { //保留 }

void main(void) { uchar i,ch; Select_Ch375( ); Select_Ch375( ); Init_Ser(); //初始化串口 mDelay100mS(); SendStrToPC("ReSetCH375......\n"); CH375_Write_cmd(CMD_RESET_ALL); //执行硬件复位 mDelay100mS(); SendStrToPC("Test CH375......\n"); CH375_Write_cmd(CMD_CHECK_EXIST); //测试CH375芯片是否在工作 CH375_Write_Data(0x5A); //写数据 for(i=40;i>0;i--)i--; ch=CH375_Read_Data(); SendCHToPC(ch); SendStrToPC("Set CH375 mode 07......\n"); CH375_Write_cmd(CMD_SET_USB_MODE); //先设置CH375的工作模式为07,再设置为06 CH375_Write_Data(0x07); for(i=30;i!=0;i--); //延时30us ch=CH375_Read_Data(); SendCHToPC(ch); SendStrToPC("Set CH375 mode 06......\n"); CH375_Write_cmd(CMD_SET_USB_MODE); CH375_Write_Data(0x06); //设置CH375的工作模式为06。至此,CH375的初始化算是完成了。 for(i=50;i!=0;i--)i--; //延时30us ch=CH375_Read_Data(); SendCHToPC(ch); SendStrToPC("CH375 initialize is OK..!\n"); //Release_Ch375(); while(1); }


单片机晶振是多少?


单片机和CH375的晶振都是12MHZ


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