大家好,
我用的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 }