[求助]CH375芯片不能通过测试工作状态

大家好,

我用的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 }

首先,测试数据返回0XFF就要检查晶振起振没有,还有就是复位完全不完全?接下来就是你的3个读写函数的时序上面有点问题,你用下面的读写程序试下看: 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,但是还是不能通过测试状态。我不管用什么数据测试(发送CHECK_EXIST命令)返回的数据都是0x5F, 读写的函数我已按照您说的改了。这是为什么?


为什么每次我用不同的数据来测试CH375(CHECK_EXIST)返回的总是0x5F呢?


我也检查了硬件连接,好像是没有什么问题,数据总线连接也没有问题,请问hcn老大,什么原因能引起这个呢?


可能是你的数据口被钳住了,你仔细检查下你的硬件连线上面以及地址之类的有没有冲突,以及在读数据的时候有没有其他的数据干扰


请问“数据口被钳住了”是什么意思,我仔细检查了硬件连线,没有错误。地址我直接用代码来表示,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太远的原故?由于我这没有SOP转DIP的转换器,而我只能把各个引脚用一些短铁丝给焊上,然后插到实验板上测试,有没有可能在焊的时候因为引脚之间的距离太近了,所以产生干扰了,但是如果有干扰,为什么每一次的CHECK_EXIST返回值都是0x5F呢?如果我把它放到PCB上会不会解决问题?


这个不是主要的问题,我所说的总线被钳住指的是你在操作的时候,将总线一直处于0X5F的状态,而和你的硬件上面没什么多大的问题


但是我也检查过数据总线,当我让数据口为输入状态的时候,而CH375没有被片选的时候,数据口输入为0xFF,而当片选打开的时候,我请求CHECK_EXIST命令,它返回的是0x5F,然后我马上请求GET_STATUS,它返回的为0x20,这能不能说明数据总线没被钳住?

以下是我测试的主程序:

//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个引脚,我现在的电路没有连那2 个引脚。这是不是原因呢。还有今天我试了一下连接那2个引脚,把RST通过一个10K电阻接地,然后把RST#通过一个4.7K的电阻接5V,但是所有的返回都为0xff了,然后我把那2个引脚悬空,返回也还都是0xff了,这是怎么回事,是不是我把芯片烧了?

救命啊


这2个引脚是复位输出脚,不需要连接的,正常复位的话,RST为低电平,RST#为高电平


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