各位前輩: 我在調(diào)試CH375時(shí)遇到以下問題: 設(shè)置好內(nèi)置固件模式后,安裝驅(qū)動(dòng)程序正常,USB設(shè)備枚舉成功,用調(diào)試工具傳數(shù)據(jù)時(shí),程序也能進(jìn)入中斷,準(zhǔn)備中斷程序中看一下時(shí)否能正確接收數(shù)據(jù),以為很順利,可是發(fā)現(xiàn)問題了,用CH375_RD_DAT_PORT()讀數(shù)據(jù)時(shí),發(fā)現(xiàn)總是返回0xff,程序的都檢查了好多次,還是這樣,非常郁悶,為什么寫命令和數(shù)據(jù)都能成功,可是讀的時(shí)候不行了呢? 請(qǐng)那位好心我?guī)蛶臀野?拜謝!
/******************************************* CH375B驅(qū)動(dòng)程序V0.1 MCU:ATmega128L OSC:8MHz *******************************************/ #include "CH375INC.H" #include /******************************************* INT:pin26(PD1) CH375_CS:pin39(PC4),對(duì)于USB設(shè)備可以將此引腳接地 CH375_A0:pin40(PC5) CH375_WR:pin12(PB2) CH375_RD:pin13(PB3) ********************************************/
#define CH375_WR PORTB.2 #define CH375_RD PORTB.3 #define CH375_CS PORTC.4 #define CH375_A0 PORTC.5 #define CH375_DQ PORTA #define CH375_DQ1 PINA
void CH375_WR_CMD_PORT( unsigned char cmd ) { /* 向CH375的命令端口寫入命令,周期不小于4uS,如果單片機(jī)較快則延時(shí) */ DDRA = 0xff; DDRB |= 0x06; DDRC |= 0x30; delay_us(2); CH375_DQ = cmd; CH375_A0 = 1; //選擇CH375的命令口 CH375_RD = 1; CH375_CS = 0; //使能ch375 CH375_WR = 0; #asm("NOP"); //CH375_WR產(chǎn)生寬度至少為80nS的低電平脈沖 CH375_WR = 1; CH375_CS = 1; CH375_A0 = 0; // DDRA = 0x00; //將數(shù)據(jù)端口置為輸入 // PORTA = 0xff; //使能內(nèi)部上拉電阻 delay_us(2); }
void CH375_WR_DAT_PORT( unsigned char dat ) { /* 向CH375的數(shù)據(jù)端口寫入數(shù)據(jù),周期不小于1.5uS,如果單片機(jī)較快則延時(shí) */ DDRA = 0xff; DDRB |= 0x06; DDRC |= 0x30; delay_us(1); CH375_DQ = dat; CH375_A0 = 0; CH375_RD = 1; CH375_CS = 0; CH375_WR = 0; #asm("NOP"); //CH375_WR產(chǎn)生寬度至少為80nS的低電平脈沖 CH375_WR = 1; CH375_CS = 1; // DDRA = 0x00; // PORTA = 0xFF; //使能內(nèi)部上拉電阻 delay_us(1); }
unsigned char CH375_RD_DAT_PORT(void) { /* 從CH375的數(shù)據(jù)端口讀出數(shù)據(jù),周期不小于1.5uS,如果單片機(jī)較快則延時(shí) */ unsigned char dat = 0; DDRA = 0x00; //將數(shù)據(jù)端口設(shè)置為輸入 DDRB |= 0x06; DDRC |= 0x30; CH375_A0 = 0; CH375_WR = 1; CH375_CS = 0; CH375_RD = 0; dat = PINA; CH375_RD = 1; CH375_CS = 1; return dat; }
void CH375_INIT() { unsigned char i; unsigned char str[10]; lcd_init(); /* 測(cè)試CH375是否正常工作,可選操作,通常不需要 */ CH375_WR_CMD_PORT(CMD_CHECK_EXIST); //測(cè)試CH375是否正常工作 CH375_WR_DAT_PORT(0x55); //寫入測(cè)試數(shù)據(jù) i = CH375_RD_DAT_PORT(); //返回?cái)?shù)據(jù)應(yīng)該是測(cè)試數(shù)據(jù)取反 sprintf(str,"#######%x",i); print_str(1,0,str); if(i != ~0x55) { /* CH375不正常 */ for ( i=80; i!=0; i-- ) { CH375_WR_CMD_PORT(CMD_RESET_ALL); //多次重復(fù)發(fā)命令,執(zhí)行硬件復(fù)位 */ CH375_RD_DAT_PORT(); } CH375_WR_CMD_PORT(0); delay_ms(50); //延時(shí)50ms } CH375_WR_CMD_PORT(CMD_SET_USB_MODE); CH375_WR_DAT_PORT(0x02); //設(shè)置為使用內(nèi)置固件的USB設(shè)備方式 */ delay_us(20); if(CH375_RD_DAT_PORT() == CMD_RET_SUCCESS) { sprintf(str,"枚舉成功!"); print_str(1,0,str); } /*******************外部中斷1初始化*************************/ EIMSK = 0x02; //使用外部中斷1 EICRA &= 0xf3; //低電平觸發(fā) #asm("sei"); //開全局中斷使能 }
[b]文字[/b][size=6]文字[/size][b]文字[/b]