这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 企业专区 » Microchip » PIC32串口通信问题

共9条 1/1 1 跳转至

PIC32串口通信问题

菜鸟
2014-07-30 14:12:53     打赏
#include <plib.h>
#pragma config POSCMOD=XT,FNOSC=PRIPLL//#pragma config POSCMOD=OFF,FNOSC=FRCPLL
#pragma config FPLLMUL=MUL_20,FPLLIDIV=DIV_2,FPLLODIV=DIV_4
#pragma config  FPBDIV = DIV_2,FWDTEN=OFF,CP=OFF,BWP=OFF
#pragma config JTAGEN = OFF,FUSBIDIO = OFF
#define SYS_FREQ (20000000L)
#define pbclk 10000000
#define DESIRED_BAUDRATE (9600)
void __ISR(_UART_1_VECTOR, ipl2) IntUart1Handler(void)
{
    // Is this an RX interrupt?
    if(INTGetFlag(INT_SOURCE_UART_RX(UART1)))
    {
        PutCharacter(UARTGetDataByte(UART1));
        INTClearFlag(INT_SOURCE_UART_RX(UART1));
    }
    // We don't care about TX interrupt
    if (INTGetFlag(INT_SOURCE_UART_TX(UART1)))
    {
        INTClearFlag(INT_SOURCE_UART_TX(UART1));
    }
}
void PutCharacter(const char character)
{
        while(!UARTTransmitterIsReady(UART1)) ;
        UARTSendDataByte(UART1, character);
        while(!UARTTransmissionHasCompleted(UART1));
}
UARTinit()
{
    PPSInput(3,U1RX,RPA2);      // Assign RPA2 as input pin for U1RX
    PPSOutput(1,RPB3,U1TX);     // Set RB3 pin as output for U1TX
    UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART1, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART1,pbclk, DESIRED_BAUDRATE);
    UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
    INTEnable(INT_SOURCE_UART_RX(UART1), INT_ENABLED);
    INTSetVectorPriority(INT_VECTOR_UART(UART1), INT_PRIORITY_LEVEL_2);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART1), INT_SUB_PRIORITY_LEVEL_0);
}
int main (void)
{
    SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
    UARTinit();
    INTEnableInterrupts();
    while(1);

}

 想实现接收数据回显,回显总是00,8M晶振,求大神指点


菜鸟
2023-01-17 10:43:49     打赏
2楼

写得什么乱七八槽的。


专家
2023-01-17 10:51:53     打赏
3楼

看看!


专家
2023-01-17 10:53:01     打赏
4楼

谢谢分享


专家
2023-01-17 11:43:58     打赏
5楼

谢谢分享


专家
2023-01-17 15:33:55     打赏
6楼

感谢分享


高工
2023-01-18 06:04:24     打赏
7楼

感谢分享


高工
2023-07-31 08:42:36     打赏
8楼

根据例程做下试验吧


助工
2024-09-24 17:20:35     打赏
9楼

进来学习一下,


共9条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]