MicroChip dsPic33,未调用UART RX中断

时间:2014-06-02 18:18:20

标签: c serial-port uart microchip mplab

下午好,

我使用以下简单功能配置了我的RX中断。

char c;
void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt( void ) 
{ 
    IFS0bits.U1RXIF = 0; // Clear RX Interrupt flag 
    c = U1RXREG;
} 

问题是,UART传输正常,但是当发送一个字符时,中断服务程序永远不会进入。我可以使用范围跟踪实际发送的字符没有问题,但中断不会被触发。

用于通信的设备是TTL-232R-3v3。该器件的工作电压为3.3V dspic33的实际型号是p33FJ128MC802 编程环境是Mplab 8,编译的是XC16

是否缺少可能启用中断的设置?可能会遗漏什么?

谢谢, 这是UART初始化代码。

U1MODEbits.UARTEN = 0;  // Bit15 TX, RX DISABLED, ENABLE at end of func
U1MODEbits.USIDL = 0;   // Bit13 Continue in Idle
U1MODEbits.IREN = 0;    // Bit12 No IR translation
U1MODEbits.RTSMD = 0;   // Bit11 Simplex Mode
U1MODEbits.UEN = 0;     // Bits8,9 TX,RX enabled, CTS,RTS not
U1MODEbits.WAKE = 0;    // Bit7 No Wake up (since we don't sleep here)
U1MODEbits.LPBACK = 0;  // Bit6 No Loop Back
U1MODEbits.ABAUD = 0;   // Bit5 No Autobaud (would require sending '55')
U1MODEbits.URXINV = 0;  // Bit4 IdleState = 1  (for dsPIC)
U1MODEbits.BRGH = 0;    // Bit3 16 clocks per bit period
U1MODEbits.PDSEL = 0;   // Bits1,2 8bit, No Parity
U1MODEbits.STSEL = 0;   // Bit0 One Stop Bit

//  U1BRG = (Fcy / (16 * BaudRate)) - 1
//  U1BRG = (36850000 / (16 * 9600)) - 1
//  U1BRG = 238.908854 //Round to 239

U1BRG = 239;

U1STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
U1STAbits.UTXINV = 0;   //Bit14 N/A, IRDA config
U1STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
U1STAbits.UTXBRK = 0;   //Bit11 Disabled
U1STAbits.UTXEN = 0;    //Bit10 TX pins controlled by periph
U1STAbits.UTXBF = 0;    //Bit9 *Read Only Bit*
U1STAbits.TRMT = 0; //Bit8 *Read Only bit*
U1STAbits.URXISEL = 0;  //Bits6,7 Int. on character recieved
U1STAbits.ADDEN = 0;    //Bit5 Address Detect Disabled
U1STAbits.RIDLE = 0;    //Bit4 *Read Only Bit*
U1STAbits.PERR = 0;     //Bit3 *Read Only Bit*
U1STAbits.FERR = 0;     //Bit2 *Read Only Bit*
U1STAbits.OERR = 0;     //Bit1 *Read Only Bit*
U1STAbits.URXDA = 0;    //Bit0 *Read Only Bit*

RPINR18bits.U1RXR = 0b00010;//7; //RX is Pin RP2
RPOR1bits.RP3R = 0b00011;   //TX is pin RP3

U1MODEbits.UARTEN = 1;  // And turn the peripheral on
U1STAbits.UTXEN = 1;

1 个答案:

答案 0 :(得分:0)

检查引脚是否具有其他功能。通常这是AD(模拟引脚)。确保通过ADP或ANSEL寄存器关闭所有模拟信号(类型和数量因芯片而异)例如。我有这个例程(我使用33F和33E以及两者中的高和低pincount,因此ifdefs)

void analogoff(void){
#if defined(__dsPIC33F__)
    ADPCFG  =0xFFFF;
    AD1PCFGH=0xFFFF;
    AD1PCFGL=0xFFFF;
#endif
#if defined(__dsPIC33E__)
#if !defined(__dsPIC33EP256MU806__)
    ANSELA=0;
#endif
    ANSELB=0;
    ANSELC=0;
    ANSELD=0;
    ANSELE=0;

    ANSELG=0;
#endif
}

另外,尽管TX具有正确的波特率(范围!),但要确保振荡器和部件的速度是正确的。

我的uart1 init:

U1BRG  = brgval;
U1MODE = 0x8000;        // Reset UART to 8-n-1, alt pins, and enable lowspeed (=bit 3)
U1MODEbits.USIDL =0;    // disable module when device is idle.
U1MODEbits.IREN  =0;    // IRDA disable
U1MODEbits.RTSMD =0;    // flow control mode (1= simplex mode)
U1MODEbits.UEN   =0;    // RTS en CTS controlled by PORTlatches
U1MODEbits.WAKE  =0;    // no wakeup enabled;
U1MODEbits.LPBACK=0;    // loopback disabled
U1MODEbits.ABAUD =0;    // no autobaud
#if !defined(__PIC24F__)
U1MODEbits.URXINV =0;   // RXINV inversion RX. (0= idle = '1')
#endif
U1MODEbits.BRGH  =1;    // high speed.
U1MODEbits.PDSEL =0;    // 8 bit no parity
U1MODEbits.STSEL =0;    // 1 stopbit.                 

U1STA  = 0x0440; 
U1STAbits.URXISEL0=0;// Reset status register and enable TX & RX. 
U1STAbits.URXISEL1=0;   // rx interrupt on a char. 
_U1RXIF=0;               // Clear UART RX Interrupt Flag
_U1RXIE = 1;             // Interruption active pour la reception
_U1RXIP=2;
_U1TXIP=2;
_U1TXIF=0;
_U1TXIE=0;             // only enabled when actually sending
U1MODEbits.UARTEN=1;