大家好,
我用的Ch375芯片不知道为什么通电的时候然后发送复位命令(RESET_ALL),然后发送(CHECK_EXIST),不管发送什么数据,它返回的数据都为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 }