[求助]CH375芯片不能通過測試工作狀態(tài)

大家好,

我用的Ch375芯片不知道為什么通電的時候然后發(fā)送復(fù)位命令(RESET_ALL),然后發(fā)送(CHECK_EXIST),不管發(fā)送什么數(shù)據(jù),它返回的數(shù)據(jù)都為0xff。這是怎么回事?難道是我的CH375芯片壞了,還是我的代碼寫得有問題?

我用的是CH375S芯片,供電電壓為5V(這個芯片工作電壓是不是5V,還是3.3V?),微控制器為Microchip PIC18F4550 工作頻率為48MHz。電路我是按照CH375中文手冊上面的并口方式連接的。

以下是我用來讀寫CH375S芯片的代碼以及初始化的代碼:

//write command to CH375A void CH375A_CMD_Write(unsigned char cmd) { CH375_TRIS = 0x0; //make all pins as outputs CS = 0; //enable the chip RD = 1; A0 = 1; //command Delayus(2); //delay for 2us CH375_PORT_OUT = cmd; WR = 0; //write operation Delayus(2); //delay for 2us }

//Write data to CH375A void CH375A_DATA_Write(unsigned char data) { CH375_TRIS = 0x0; //make all pins as outputs CS = 0; //enable the chip RD = 1; //disables read operation A0 = 0; //data CH375_PORT_OUT = data; WR = 0; //enables write operation Delayus(2); //delay for 2us }

//Read data from CH375A unsigned char CH375A_DATA_Read(void) { unsigned char dat; CH375_TRIS = 0xff; //make all PortD pins as inputs CS = 0; //enable the chip RD = 0; //enables read operation WR = 1; //disables write operation A0 = 0; //data Delayus(2); //delay for 1us dat = CH375_PORT_IN; return dat; }

//Initialize CH375A unsigned char InitCH375A(void) { unsigned char i,status; CH375A_CMD_Write(CMD_RESET_ALL); //reset CH375A Delayms(100); //delay for bigger than 40ms CH375A_CMD_Write(CMD_CHECK_EXIST); CH375A_DATA_Write(0x55); status = CH375A_DATA_Read();

CH375A_CMD_Write(CMD_SET_USB_MODE); //set usb mode CH375A_DATA_Write(6); //set usb host, autogenerate SOF packet for (i=0xff; i > 0; i--) if(CH375A_DATA_Read() == CMD_RET_SUCCESS) break; if( i >0) return 0; //good else return 0xff; //error }

首先,測試數(shù)據(jù)返回0XFF就要檢查晶振起振沒有,還有就是復(fù)位完全不完全?接下來就是你的3個讀寫函數(shù)的時序上面有點問題,你用下面的讀寫程序試下看: void CH375A_CMD_Write(unsigned char cmd) { CH375_TRIS = 0x0; //make all pins as outputs Delayus(2); //delay for 2us CH375_PORT_OUT = cmd; A0 = 1; //command WR = 0; //write operation CS = 0; //enable the chip RD = 1; Delayus(2); //delay for 2us }

//Write data to CH375A void CH375A_DATA_Write(unsigned char data) { CH375_TRIS = 0x0; //make all pins as outputs、 Delayus(1); CH375_PORT_OUT = data; CS = 0; //enable the chip RD = 1; //disables read operation A0 = 0; //data WR = 0; //enables write operation Delayus(2); //delay for 2us }

//Read data from CH375A unsigned char CH375A_DATA_Read(void) { unsigned char dat; CH375_TRIS = 0xff; //make all PortD pins as inputs CS = 0; //enable the chip RD = 0; //enables read operation WR = 1; //disables write operation A0 = 0; //data Delayus(2); //delay for 1us dat = CH375_PORT_IN; CS = 1; //enable the chip RD = 1; //enables read operation return dat; }


多謝,我試試


我知道問題所在了,我把#CS針接錯了,所以每次都輸出ff,但是還是不能通過測試狀態(tài)。我不管用什么數(shù)據(jù)測試(發(fā)送CHECK_EXIST命令)返回的數(shù)據(jù)都是0x5F, 讀寫的函數(shù)我已按照您說的改了。這是為什么?


為什么每次我用不同的數(shù)據(jù)來測試CH375(CHECK_EXIST)返回的總是0x5F呢?


我也檢查了硬件連接,好像是沒有什么問題,數(shù)據(jù)總線連接也沒有問題,請問hcn老大,什么原因能引起這個呢?


可能是你的數(shù)據(jù)口被鉗住了,你仔細(xì)檢查下你的硬件連線上面以及地址之類的有沒有沖突,以及在讀數(shù)據(jù)的時候有沒有其他的數(shù)據(jù)干擾


請問“數(shù)據(jù)口被鉗住了”是什么意思,我仔細(xì)檢查了硬件連線,沒有錯誤。地址我直接用代碼來表示,RESET_ALL=05和CHECK_EXIST=06。我自己又重新寫了一個小程序,就用來測試CH375芯片,但是還是通過不了CHECK_EXIST(06)。 這是我寫的程序 MCU為PIC18F452,晶振為16Mhz: #include #include

#pragma code

//define macros for CH375A #define A0 LATCbits.LATC3 #define RD LATCbits.LATC2 #define WR LATCbits.LATC1 #define CS LATCbits.LATC0 #define INT PORTBbits.RB0 #define CH375_PORT_IN PORTD #define CH375_PORT_OUT PORTD #define CH375_TRIS TRISD

void Delayus(unsigned char delay) { unsigned char i; for(i = 0; i < delay; i++) Nop(); Nop(); }

//delay for x ms void Delayms(unsigned char delay) { unsigned char i, j; while(delay-- != 0) { for(i=9; i!= 0; i--) { for(j=47;j !=0; j--) { Nop(); } } } }

void CH375A_CMD_Write(unsigned char cmd) { CH375_TRIS = 0x0; //make all pins as outputs Delayus(2); //delay for 2us CH375_PORT_OUT = cmd; A0 = 1; //command WR = 0; //write operation CS = 0; //enable the chip RD = 1; Delayus(2); //delay for 2us }

//Write data to CH375A void CH375A_DATA_Write(unsigned char data) { CH375_TRIS = 0x0; //make all pins as outputs、 Delayus(1); CH375_PORT_OUT = data; CS = 0; //enable the chip RD = 1; //disables read operation A0 = 0; //data WR = 0; //enables write operation Delayus(2); //delay for 2us }

//Read data from CH375A unsigned char CH375A_DATA_Read(void) { unsigned char dat; CH375_TRIS = 0xff; //make all PortD pins as inputs CS = 0; //enable the chip RD = 0; //enables read operation WR = 1; //disables write operation A0 = 0; //data Delayus(2); //delay for 1us dat = CH375_PORT_IN; CS = 1; //enable the chip RD = 1; //enables read operation return dat; }

//initialize the ports void InitPort(void) { LATA = 0; LATD = 0; LATC = 0; LATB = 0; TRISA=0xff; TRISB=0xff; TRISC=0x0; TRISD=0xff; TRISE=0xff; ADCON1 = 0x07; //make all ports digital I/O }

//Initialize CH375A unsigned char InitCH375A(void) { unsigned char i,status; CH375A_CMD_Write(0x05); //reset CH375A Delayms(50); //delay for bigger than 40ms CH375A_CMD_Write(0x06); CH375A_DATA_Write(0xff); status = CH375A_DATA_Read();

}

void main(void) { unsigned char status; InitPort(); Delayms(100); InitCH375A(); while(1); }

還有就是有沒有可能是晶振離CH375太遠(yuǎn)的原故?由于我這沒有SOP轉(zhuǎn)DIP的轉(zhuǎn)換器,而我只能把各個引腳用一些短鐵絲給焊上,然后插到實驗板上測試,有沒有可能在焊的時候因為引腳之間的距離太近了,所以產(chǎn)生干擾了,但是如果有干擾,為什么每一次的CHECK_EXIST返回值都是0x5F呢?如果我把它放到PCB上會不會解決問題?


這個不是主要的問題,我所說的總線被鉗住指的是你在操作的時候,將總線一直處于0X5F的狀態(tài),而和你的硬件上面沒什么多大的問題


但是我也檢查過數(shù)據(jù)總線,當(dāng)我讓數(shù)據(jù)口為輸入狀態(tài)的時候,而CH375沒有被片選的時候,數(shù)據(jù)口輸入為0xFF,而當(dāng)片選打開的時候,我請求CHECK_EXIST命令,它返回的是0x5F,然后我馬上請求GET_STATUS,它返回的為0x20,這能不能說明數(shù)據(jù)總線沒被鉗???

以下是我測試的主程序:

//Initialize CH375A unsigned char InitCH375A(void) { unsigned char i,status; CH375A_CMD_Write(0x05); //reset CH375A Delayms(50); //delay for bigger than 40ms CH375A_CMD_Write(0x06); CH375A_DATA_Write(0x55); status = CH375A_DATA_Read(); //status 返回 0x5F CH375A_CMD_Write(0x22); status = CH375A_DATA_Read(); //status 返回 0x20

}


hcn老大,

請問我還用不用連接RST和RST#這2個引腳,我現(xiàn)在的電路沒有連那2 個引腳。這是不是原因呢。還有今天我試了一下連接那2個引腳,把RST通過一個10K電阻接地,然后把RST#通過一個4.7K的電阻接5V,但是所有的返回都為0xff了,然后我把那2個引腳懸空,返回也還都是0xff了,這是怎么回事,是不是我把芯片燒了?

救命啊


這2個引腳是復(fù)位輸出腳,不需要連接的,正常復(fù)位的話,RST為低電平,RST#為高電平


只有登錄才能回復(fù),可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频