SC16C2550用中断接收,查询方式发送。出现一个很奇怪的现象,在接收到几包报文后,接收中断不再产生,需要将SC16C2550重新初始化一下。在目标板中共用了3个外部中断,其中两个是SC16C2550的接收中断。串口的2个中断的优先级高于另外一个外部中断。麻烦那位大侠看看。
UINT8 com485_Init(int baud,int data,int parity,int stopbit,UINT8 chanle) { int i; int bak=0,temp=0; // 设置串口波特率 bak=3686400/16/baud; SC16C2550_Write(SC16C2550_LCR,0x80,chanle); SC16C2550_Write(SC16C2550_DLM,(UINT8)((bak&0xff00)>>8),chanle); SC16C2550_Write(SC16C2550_DLL,(UINT8)(bak&0x00FF),chanle); // 设置串口模式 bak = data-5; // 设置字长度 if(2==stopbit) bak |= 0x04; // 判断是否为2位停止位 if(0!=parity) {temp = parity-1; bak |= 0x08;} bak |= temp<<4; // 设置奇偶校? SC16C2550_Write(SC16C2550_LCR,bak,chanle);//8 data bit;1 stop bit;no parity SC16C2550_Write(SC16C2550_FCR,0xC7,chanle); //设置接收中断触发点并使能FIFO SC16C2550_Write(SC16C2550_IER,0x01,chanle);//关闭接收和发送中断 SC16C2550_Write(SC16C2550_MCR,0x08,chanle); if(chanle==1) { for(i=0;i<200;i++) { SC16C2550A_TxBuf = 0x00; SC16C2550A_RxBuf = 0x00; } a_revlen = 0; revcounta=0; watch_485a=FALSE; *SIMASK(0xf0000000)|=SIMASK_IRM4; *SIPEND(0xf0000000)|=SIPEND_IRQ4; *SIEL(0xf0000000)|=SIEL_ED4; (void) intConnect (IV_IRQ4, (VOIDFUNCPTR) IRQ4_ISR, NULL); } if(chanle==2) { for(i=0;i<200;i++) { SC16C2550B_TxBuf = 0x00; SC16C2550B_RxBuf = 0x00; } b_revlen = 0; revcountb=0; watch_485b=FALSE; *SIMASK(0xf0000000)|=SIMASK_IRM3; *SIPEND(0xf0000000)|=SIPEND_IRQ3; *SIEL(0xf0000000)|=SIEL_ED3; (void) intConnect (IV_IRQ3, (VOIDFUNCPTR) IRQ3_ISR, NULL); } return TRUE; }
void IRQ4_ISR() { UINT8 status=0,status1=0,data=0,i=0; status=SC16C2550_Read(SC16C2550_ISR,1)&0x0e; if(status==0x04) { for(i=0;i<14;i++) { data=SC16C2550_Read(SC16C2550_RHR,1); SC16C2550A_RxBuf[revcounta++]=data; } a_revlen = revcounta; } if(status==0x0c) { while((SC16C2550_Read(SC16C2550_LSR,1)&0x01)) { delay(200); data=SC16C2550_Read(SC16C2550_RHR,1); SC16C2550A_RxBuf[revcounta++]=data; } a_revlen = revcounta; } if(revcounta>200)revcounta=0; watch_485a=TRUE; *SIPEND(0xf0000000)|=SIPEND_IRQ4; //清中断 }
|