新會員
Joined
: 2010/2/1 14:26 最後登入時間
: 2018/4/30 11:19
Group:
註冊會員
Level : 3 HP : 0 / 52 MP : 6 / 2239 EXP : 9
|
我用24HJ128GP502作UART傳輸,TX有輸出,但是用電腦終端機送出Data,RX都收不到資料也跳不進去中斷,但是設定成Loopback時,TX丟出資料時,RX就可以進中斷也收的到資料,請問是哪邊設定有錯
這是我的程式
int main(void) { Initialize_PPS(); Initialize_UART(); while(1) { ClrWdt(); } }
//PPS設定 void Initialize_PPS(void) { PPSUnLock; //Unlock the PPS lock feature iPPSOutput(OUT_PIN_PPS_RP0,OUT_FN_PPS_U1TX); //Uart1 Tx iPPSInput(IN_FN_PPS_U1RX,IN_PIN_PPS_RP1); //Uart1 Rx iPPSOutput(OUT_PIN_PPS_RP4,OUT_FN_PPS_U2TX); //Uart2 Tx iPPSOutput(OUT_PIN_PPS_RP3,OUT_FN_PPS_OC1); //PWM iPPSOutput(OUT_PIN_PPS_RP15,OUT_FN_PPS_C1TX); //ECAN1 Tx iPPSInput(IN_FN_PPS_C1RX,IN_PIN_PPS_RP14); //ECAN1 Rx PPSLock; }
//UART 設定 void Initialize_UART(void) { UINT16 UxMODEvalue,UxSTAvalue; CloseUART1(); ConfigIntUART1(UART_RX_INT_EN & UART_RX_INT_PR5 & UART_TX_INT_EN & UART_TX_INT_PR2); UxMODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & \ UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE & \ UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_UXRX_IDLE_ONE & \ UART_BRGH_FOUR & UART_NO_PAR_8BIT & UART_1STOPBIT; UxSTAvalue = UART_INT_TX_BUF_EMPTY & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED & \ UART_TX_ENABLE & UART_INT_RX_CHAR & UART_ADR_DETECT_DIS & \ UART_RX_OVERRUN_CLEAR; OpenUART1(UxMODEvalue,UxSTAvalue,51); //38400 FCY=FOSC/2 /*UxBRG = ( (FCY/Desired Baud Rate)/4)-1 EX:((8MHz/38400)/4)-1=25 */
CloseUART2(); ConfigIntUART2(UART_RX_INT_DIS & UART_RX_INT_PR0 & UART_TX_INT_EN & UART_TX_INT_PR2); UxMODEvalue = UART_EN & UART_IDLE_CON & UART_IrDA_DISABLE & \ UART_MODE_SIMPLEX & UART_UEN_00 & UART_DIS_WAKE & \ UART_DIS_LOOPBACK & UART_EN_ABAUD & UART_UXRX_IDLE_ONE & \ UART_BRGH_SIXTEEN & UART_NO_PAR_8BIT & UART_1STOPBIT; UxSTAvalue = UART_INT_TX_LAST_CH & UART_IrDA_POL_INV_ZERO & UART_SYNC_BREAK_DISABLED & \ UART_TX_ENABLE & UART_INT_RX_CHAR &UART_ADR_DETECT_DIS & \ UART_RX_OVERRUN_CLEAR; OpenUART2(UxMODEvalue,UxSTAvalue,51); //9600 /*UxBRG = ( (FCY/Desired Baud Rate)/16)-1 EX:((8MHz/9600)/16)-1=51 */ }
//UART RX中斷 void __attribute__((interrupt,no_auto_psv)) _U1RXInterrupt(void) { unsigned char Key_code; IFS0bits.U1RXIF = 0; Key_code = ReadUART1(); }
發表於: 2010/2/12 14:24
|