初始化返回代碼是0x81,晶振兩個(gè)引腳的電壓在2.2v左右,usb接口d+約3.7v,d-約0v,檢查電路連接沒(méi)有發(fā)現(xiàn)問(wèn)題,請(qǐng)教下一步如何測(cè)試?
用測(cè)試命令測(cè)試,發(fā)出去的0x55,讀回來(lái)的是0x85,請(qǐng)問(wèn)可能是什么原因?25腳和26腳的電平是正確的
/* PC1--CH375_A0 PC2--CH375_RD PC3--CH375_WR PC4--CH375_CS PD3--CH375_INT PC5--其他芯片用 */ //向CH375 的命令端口寫(xiě)入命令 void xWriteCH375Cmd(unsigned char cmd) { PORTC|=0X02; //CH375_A0=1 PORTA=cmd; PORTC&=0XEF; //CH375_CS=0 PORTC&=0XF7; //CH375_WR=0 delay_us(2); PORTC|=0X08; //CH375_WR=1 PORTC|=0X10; //CH375_CS=1 delay_us(2); }
//向CH375 的數(shù)據(jù)端口寫(xiě)入數(shù)據(jù) void xWriteCH375Data(unsigned char dat) { PORTC&=0XFD; //CH375_A0=0 PORTA=dat; PORTC&=0XEF; //CH375_CS=0 PORTC&=0XF7; //CH375_WR=0 delay_us(2); PORTC|=0X08; //CH375_WR=1 PORTC|=0X10; //CH375_CS=1 }
//從CH375 的數(shù)據(jù)端口讀出數(shù)據(jù) unsigned char xReadCH375Data(void) { unsigned char dat=0; PORTC&=0XFD; //CH375_A0=0 PORTC&=0XEF; //CH375_CS=0 PORTC&=0XFB; //CH375_RD=0 delay_us(2); dat=PORTA; PORTC|=0X04; //CH375_RD=1 PORTC|=0X10; //CH375_CS=1 return(dat); }
//初始化ch375,成功返回0 unsigned char init_ch375(void) { unsigned char i; DDRC|=0X3E; //PC1--PC5輸出 PORTC|=0X1E; //PC1--PC4=1 PORTC&=0X20; //PC5=0 DDRD&=0XF7; //PD3輸入 PORTD|=0X08; //PD3上拉 CH375Reset(); i=CH375LibInit(); // 初始化CH375程序庫(kù)和CH375芯片,操作成功返回0 return(i); } 以上是我的初始化程序,請(qǐng)幫忙看看問(wèn)題,謝謝!
USB口的電壓在不接任何東西的時(shí)候應(yīng)該為低電平,還有就是你做測(cè)試命令不成功的話,那就需要查看你的硬件了,你可以使用示波器來(lái)看你的時(shí)序包括你的硬件上面是否連接正確等等,都可以用示波器來(lái)看下
好了,找到問(wèn)題了,端口A沒(méi)有設(shè)置輸入輸出,修改后的程序入下,初始化可以通過(guò)了
/* PC1--CH375_A0 PC2--CH375_RD PC3--CH375_WR PC4--CH375_CS PD3--CH375_INT PC5--其他芯片用 */ //向CH375 的命令端口寫(xiě)入命令 void xWriteCH375Cmd(unsigned char cmd) { DDRA|=0XFF; //PORTA輸出 PORTC|=0X02; //CH375_A0=1 PORTA=cmd; PORTC&=0XEF; //CH375_CS=0 PORTC&=0XF7; //CH375_WR=0 delay_us(2); PORTC|=0X08; //CH375_WR=1 PORTC|=0X10; //CH375_CS=1 delay_us(2); }
//向CH375 的數(shù)據(jù)端口寫(xiě)入數(shù)據(jù) void xWriteCH375Data(unsigned char dat) {
DDRA|=0XFF; //PORTA輸出 PORTC&=0XFD; //CH375_A0=0 PORTA=dat; PORTC&=0XEF; //CH375_CS=0 PORTC&=0XF7; //CH375_WR=0 delay_us(2); PORTC|=0X08; //CH375_WR=1 PORTC|=0X10; //CH375_CS=1 }
//從CH375 的數(shù)據(jù)端口讀出數(shù)據(jù) unsigned char xReadCH375Data(void) { unsigned char dat=0; DDRA&=0X00; //PORTA輸入 PORTA|=0XFF; //上拉 PORTC&=0XFD; //CH375_A0=0 PORTC&=0XEF; //CH375_CS=0 PORTC&=0XFB; //CH375_RD=0 delay_us(2); dat=PINA; PORTC|=0X04; //CH375_RD=1 PORTC|=0X10; //CH375_CS=1 return(dat); }
//初始化ch375,成功返回0 unsigned char init_ch375(void) { unsigned char i; DDRC|=0X3E; //PC1--PC5輸出 PORTC|=0X1E; //PC1--PC4=1 PORTC&=0X20; //PC5=0 DDRD&=0XF7; //PD3輸入 PORTD|=0X08; //PD3上拉 CH375Reset(); i=CH375LibInit(); // 初始化CH375程序庫(kù)和CH375芯片,操作成功返回0 return(i);