我在用中斷的方式處理CH432接收數(shù)據(jù)時(shí),發(fā)現(xiàn)一個(gè)奇怪的問(wèn)題,詳細(xì)如下:
?
CH432初始化:
?
void InitCH432(void)??? /* 初始化CH432 */
{
??? UINT16 CH432div;
??
?? UINT8 DLM;
? UINT8 CH432DLL;
/**************************************************************************
????????? 設(shè)置CH432串口0的寄存器
**************************************************************************/
?? ?
??? CH432div = ( Fpclk >> 4 ) / CH432_BPS;
??? DLM = CH432div >> 8;
??? CH432DLL = CH432div & 0xff;
?
??? WriteCH432Data( CH432_IER_PORT,? BIT_IER_RESET);? //端口復(fù)位//
??? WriteCH432Data( CH432_LCR_PORT, BIT_LCR_DLAB );??? /* 設(shè)置DLAB為1 */
??? WriteCH432Data( CH432_DLL_PORT, CH432DLL );??? /* 設(shè)置波特率 */
??? WriteCH432Data( CH432_DLM_PORT, DLM );
??? WriteCH432Data( CH432_FCR_PORT,? BIT_FCR_FIFOEN? );??? /* 設(shè)置FIFO模式,觸發(fā)點(diǎn)為1 */
??? WriteCH432Data( CH432_LCR_PORT, BIT_LCR_WORDSZ1
????????????????????????????????? | BIT_LCR_WORDSZ0 );??? /* 字長(zhǎng)8位,1位停止位、無(wú)校驗(yàn) */
/**************************************************************************
????????? 設(shè)置CH432串口1的寄存器
**************************************************************************/
??? CH432div = ( Fpclk >> 4 ) / CH432_BPS1;
??? DLM = CH432div >> 8;
??? CH432DLL = CH432div & 0xff;
??
??WriteCH432Data( CH432_IER1_PORT,? BIT_IER_RESET);? //端口復(fù)位//
??? WriteCH432Data( CH432_LCR1_PORT, BIT_LCR_DLAB );??? /* 設(shè)置DLAB為1 */
??? WriteCH432Data( CH432_DLL1_PORT, CH432DLL );??? /* 設(shè)置波特率 */
??? WriteCH432Data( CH432_DLM1_PORT, DLM );
??? WriteCH432Data( CH432_FCR1_PORT,? BIT_FCR_RECVTG1 | BIT_FCR_FIFOEN );??? /* 設(shè)置FIFO模式,觸發(fā)點(diǎn)為8 bytes */
??? WriteCH432Data( CH432_LCR1_PORT,
???????????????????????????????????? BIT_LCR_WORDSZ1
????????????????????????????????? | BIT_LCR_WORDSZ0 );??? /* 字長(zhǎng)8位,1位停止位、無(wú)校驗(yàn) */
??? WriteCH432Data( CH432_IER1_PORT,?? BIT_IER_IERECV? );??? /* 允許接收到數(shù)據(jù)中斷 */
??? WriteCH432Data( CH432_MCR1_PORT, BIT_MCR_OUT2? );??? /* 允許中斷輸出,DTR,RTS為1 */
}
?
?
中斷處理子程序:
?
void CH432Interrupt(void)??? /* 中斷方式處理 */
{
??? UINT8 InterruptStatus;
??? UINT8 RcvNum = 0;
?? UINT8 i;
//?? UINT8 Status;
?
??? InterruptStatus = ReadCH432Data( CH432_IIR_PORT ) & ( ~ CH432_IIR_FIFOS_ENABLED );
??? if( ( InterruptStatus & 0x01 ) )??? /* 沒(méi)有中斷轉(zhuǎn)到串口1 */
??? {
??????? InterruptStatus = ReadCH432Data( CH432_IIR1_PORT ) & ( ~ CH432_IIR_FIFOS_ENABLED );??? /* 讀串口1的中斷狀態(tài) */
??????? if( ( InterruptStatus & 0x01 ) ) return;??? /* 沒(méi)有中斷退出 */
??????? else
??????? {
????????????Delay_ms(30);//必須加上
??????????? ReadCH432Data( CH432_FCR1_PORT );? //這句不知什么意思,必須加上才接收正常
??????????? ReadCH432Data( CH432_LSR1_PORT );? //這句不知什么意思,必須加上才接收正常
?????????? ReadCH432Data( CH432_MCR1_PORT );? //這句不知什么意思,必須加上才接收正常
????
??????????? switch( InterruptStatus )
??????????? {
???????? case INT_MODEM_CHANGE:
?????????? ReadCH432Data(CH432_MSR1_PORT);? //不處理
?????????? break;
??????????????? case INT_NOINT:??? /* 沒(méi)有中斷 */
??????????????????? break;
??????????????? case INT_THR_EMPTY:??? /* 發(fā)送保持寄存器空中斷 */
??????????????????? ReadCH432Data(CH432_IIR1_PORT);? //不處理
??????????????????? break;
??????????????? case INT_RCV_SUCCESS:??? /* 串口接收可用數(shù)據(jù)中斷 */
????????case INT_RCV_OVERTIME:??? /* 接收數(shù)據(jù)超時(shí)中斷 */?
??????????????????? RcvNum = CH432Seril1Rcv( buf );
??????????for(i=0;i??????????{
???????????if(rb_can_write(&u_ring_buff) > 0)
???????????{
????????????rb_write(&u_ring_buff, &buf[i], 1);
???????????}?????
??????????}?
??????????print_buf((U8 *)u_ring_buff.rb_buff,RcvNum,"RcvData");
??????????????????? break;
??????????????? case INT_RCV_LINES:??? /* 接收線路狀態(tài)中斷 */
??????????????????? ReadCH432Data( CH432_LSR1_PORT);? //不處理
??????????????????? break;
??????????????
??????????????? default:??? /* 不可能發(fā)生的中斷 */
??????????????????? break;
??????????? }
??????? }
??? }
??? else
??? {
???
??????? switch( InterruptStatus )
??????? {
??????????? case INT_MODEM_CHANGE:
??????????????? ReadCH432Data( CH432_MSR_PORT );? //不處理
??????????????? break;
??????????? case INT_NOINT:??? /* 沒(méi)有中斷 */
??????????????????? break;
??????????? case INT_THR_EMPTY:??? /* 發(fā)送保持寄存器空中斷 */
??????????????????? ReadCH432Data(CH432_IIR_PORT);? //不處理
??????????????????? break;
??????????? case INT_RCV_SUCCESS:??? /* 串口接收可用數(shù)據(jù)中斷 */
?????????????
??????????????????? RcvNum = CH432Seril0Rcv( buf );
??????????for(i=0;i??????????{
???????????if(rb_can_write(&u_ring_buff) > 0)
???????????{
????????????rb_write(&u_ring_buff, &buf[i], 1);
???????????}?????
??????????}?
??????
??????????????????? break;
??????????? case INT_RCV_LINES:??? /* 接收線路狀態(tài)中斷 */
??????????????????? ReadCH432Data( CH432_LSR_PORT);? //不處理
??????????????????? break;
??????????? case INT_RCV_OVERTIME:??? /* 接收數(shù)據(jù)超時(shí)中斷 */
??????????????????? RcvNum = CH432Seril0Rcv( buf );
??????????for(i=0;i??????????{
???????????if(rb_can_write(&u_ring_buff) > 0)
???????????{
????????????rb_write(&u_ring_buff, &buf[i], 1);
???????????}?????
??????????}??
??????????????????? break;
??????????? default:??? /* 不可能發(fā)生的中斷 */
??????????????????? break;
??????? }
??? }
}
現(xiàn)在問(wèn)題就是,在中斷子程序里必須加上下面這四個(gè)語(yǔ)句,接收數(shù)據(jù)才正常,不加的話就無(wú)法接收到任何數(shù)據(jù):
????????????Delay_ms(30);//必須加上
??????????? ReadCH432Data( CH432_FCR1_PORT );? //這句不知什么意思,必須加上才接收正常
??????????? ReadCH432Data( CH432_LSR1_PORT );? //這句不知什么意思,必須加上才接收正常
?????????? ReadCH432Data( CH432_MCR1_PORT );? //這句不知什么意思,必須加上才接收正常
?
不加上這四句,LSR的數(shù)值就一直為0xE3,而且INT中斷引腳一直被拉低,無(wú)法恢復(fù)到高電平,不知是什么原因,有哪位大神知道原因的,麻煩幫解答一下,謝謝了