gpt4 book ai didi

c - MicroChip dsPic33,UART RX 中断未被调用

转载 作者:行者123 更新时间:2023-11-30 17:32:47 25 4
gpt4 key购买 nike

下午好,

我使用以下简单函数配置了 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.3Vdspic33的实际型号是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;

最佳答案

检查该引脚是否具有附加功能。通常这是 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初始化:

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;

关于c - MicroChip dsPic33,UART RX 中断未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24000836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com