本帖最后由 zhuludiqing 于 2016-8-13 10:55 编辑
两块单片机串口通信,单片机型号为PIC32MX775,两块单片机在一块板子上,单片机1的UART5和单片机2的UART6交叉互联,UART5初始化为
void intUart5()
{
UARTConfigure(UART5, UART_ENABLE_PINS_TX_RX_ONLY );
UARTSetFifoMode(UART5, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(UART5, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE| UART_STOP_BITS_1);
UARTSetDataRate(UART5,GetPeripheralClock(), 57600);
UARTEnable(UART5, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
INTEnable(INT_SOURCE_UART_RX(UART5), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART5), INT_PRIORITY_LEVEL_2);
INTSetVectorSubPriority(INT_VECTOR_UART(UART5), INT_SUB_PRIORITY_LEVEL_0);
}
UART6初始化如下:
void intUart6()
{
UARTConfigure(UART6, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode(UART6, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(UART6, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE| UART_STOP_BITS_1);
UARTSetDataRate(UART6, GetPeripheralClock(), 57600);
UARTEnable(UART6, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
INTEnable(INT_SOURCE_UART_RX(UART6), INT_ENABLED);
INTSetVectorPriority(INT_VECTOR_UART(UART6), INT_PRIORITY_LEVEL_1);
INTSetVectorSubPriority(INT_VECTOR_UART(UART6), INT_SUB_PRIORITY_LEVEL_0);
}
UART6发送,UART5通过中断接收。但是UART5不能进入中断,接收不到数据;反过来,UART5发送,UART6接收也是同样的问题。通过串口助手接收,可以证明发送是都没有问题的。为什么会出现这样的问题,是我程序设置有问题吗,请各位赐教。
|