串口0,1,2都正常,能打印信息,串口2配置之后没反应,看了一下,配置应该和串口1是差不多的,但就是不清楚为什么没数据出来,请大家帮忙看看,非常感谢
配置代码如下:
串口1:
void uart1Init (INT32U ulBaudRate,
INT8U ucParityEnable,
INT8U ucParityType,
INT8U ucDataLength,
INT8U ucStopBit)
{
UART_MemMapPtr uartPtr = UART1_BASE_PTR;
register INT16U usBaudRate = 0;
#if UART_PARAM_DEBUG
UART_CHECK_PARAM(UART_PARAM_LENGTH(ucDataLength));
UART_CHECK_PARAM(UART_PARAM_STOP(ucStopBit));
UART_CHECK_PARAM(UART_PARAM_LOGIC(ucParityEnable));
UART_CHECK_PARAM(UART_PARAM_PARITY(ucParityType));
#endif
SIM_SCGC4 |= SIM_SCGC4_UART1_MASK; /* ÔÊÐíÍâÉèʱÖÓ */
uart1TranControl(UART_TX_DISABLE, UART_RX_DISABLE); /* Ê×ÏȽûֹͨÐÅ */
#if 0
PORTC_PCR4 = PORT_PCR_MUX(0x3); /* UART1_TXD */
PORTC_PCR3 = PORT_PCR_MUX(0x3); /* UART1_RXD */
#endif
#if 0
PORTC_PCR4 = PORT_PCR_MUX(0x3); /* UART1_TXD */
PORTC_PCR3 = PORT_PCR_MUX(0x3); /* UART1_RXD */
#endif
#if 1
PORTE_PCR0 = PORT_PCR_MUX(0x3); /* UART1_TXD */
PORTE_PCR1 = PORT_PCR_MUX(0x3); /* UART1_RXD */
#endif
UART_C1_REG(uartPtr) &= ~(UART_C1_M_MASK | /* Êý¾Ý³¤¶È */
UART_C1_PT_MASK | /* УÑéλÀàÐÍ */
UART_C1_PE_MASK); /* УÑéλ */
UART_C1_REG(uartPtr) |= ((ucDataLength - 8UL) << UART_C1_M_SHIFT)|
(ucParityEnable << UART_C1_PE_SHIFT)|
(ucParityType << UART_C1_PT_SHIFT);
usBaudRate = SystemBusClock/(ulBaudRate * 16);
UART_BDH_REG(uartPtr) = (usBaudRate & 0x1F00) >> 8; /* ²¨ÌØÂÊ */
UART_BDL_REG(uartPtr) = (INT8U)(usBaudRate & UART_BDL_SBR_MASK);
UART_BDH_REG(uartPtr) &= ~UART_BDH_SBNS_MASK; /* ֹͣλ */
UART_BDH_REG(uartPtr) |= (ucStopBit - 1) << UART_BDH_SBNS_SHIFT;
UART_C2_REG(uartPtr) &= ~(UART_C2_TIE_MASK | UART_C2_TCIE_MASK| /* Çå³ýÖжÏÉèÖà */
UART_C2_RIE_MASK | UART_C2_ILIE_MASK);
while ((UART_S1_REG(uartPtr) & UART_S1_RDRF_MASK) &&
(UART_D_REG(uartPtr))); /* Çå½ÓÊÕ»º³åÇø */
#if UART0_DEFAULT_OPEN
uart1TranControl(UART_TX_ENABLE, UART_RX_ENABLE); /* ÅäÖÃÍê³ÉÔÊÐíͨÐÅ */
#endif
#if UART1_IRQ_ENABLE
#if UART1_SEND_IRQ
UART_C2_REG(uartPtr) |= UART_C2_TCIE_MASK;
#endif
#if UART1_RECEIVE_IRQ
UART_C2_REG(uartPtr) |= UART_C2_RIE_MASK;
#endif
NVIC_EnableIRQ(UART1_IRQn);
NVIC_SetPriority(UART1_IRQn,3); /* Óû§×Ô¼º¶¨Òå */
#endif
}
串口2:
void uart2Init (INT32U ulBaudRate,
INT8U ucParityEnable,
INT8U ucParityType,
INT8U ucDataLength,
INT8U ucStopBit)
{
UART_MemMapPtr uartPtr = UART2_BASE_PTR;
register INT16U usBaudRate = 0;
#if UART_PARAM_DEBUG
UART_CHECK_PARAM(UART_PARAM_LENGTH(ucDataLength));
UART_CHECK_PARAM(UART_PARAM_STOP(ucStopBit));
UART_CHECK_PARAM(UART_PARAM_LOGIC(ucParityEnable));
UART_CHECK_PARAM(UART_PARAM_PARITY(ucParityType));
#endif
SIM_SCGC4 |= SIM_SCGC4_UART2_MASK; /* ÔÊÐíÍâÉèʱÖÓ */
uart2TranControl(UART_TX_DISABLE, UART_RX_DISABLE); /* Ê×ÏȽûֹͨÐÅ */
#if 0
PORTD_PCR3 = PORT_PCR_MUX(0x3); /* UART2_TXD */
PORTD_PCR2 = PORT_PCR_MUX(0x3); /* UART2_RXD */
#endif
#if 1
PORTD_PCR5 = PORT_PCR_MUX(0x3); /* UART2_TXD */
PORTD_PCR4 = PORT_PCR_MUX(0x3); /* UART2_RXD */
#endif
#if 0
PORTE_PCR22 = PORT_PCR_MUX(0x4); /* UART2_TXD */
PORTE_PCR23 = PORT_PCR_MUX(0x4); /* UART2_RXD */
#endif
UART_C1_REG(uartPtr) &= ~(UART_C1_M_MASK | /* Êý¾Ý³¤¶È */
UART_C1_PT_MASK | /* УÑéλÀàÐÍ */
UART_C1_PE_MASK); /* УÑéλ */
UART_C1_REG(uartPtr) |= ((ucDataLength - 8UL) << UART_C1_M_SHIFT)|
(ucParityEnable << UART_C1_PE_SHIFT)|
(ucParityType << UART_C1_PT_SHIFT);
usBaudRate = SystemBusClock/(ulBaudRate * 16);
UART_BDH_REG(uartPtr) = (usBaudRate & 0x1F00) >> 8; /* ²¨ÌØÂÊ */
UART_BDL_REG(uartPtr) = (INT8U)(usBaudRate & UART_BDL_SBR_MASK);
UART_BDH_REG(uartPtr) &= ~UART_BDH_SBNS_MASK; /* ֹͣλ */
UART_BDH_REG(uartPtr) |= (ucStopBit - 1) << UART_BDH_SBNS_SHIFT;
UART_C2_REG(uartPtr) &= ~(UART_C2_TIE_MASK | UART_C2_TCIE_MASK| /* Çå³ýÖжÏÉèÖà */
UART_C2_RIE_MASK | UART_C2_ILIE_MASK);
while ((UART_S1_REG(uartPtr) & UART_S1_RDRF_MASK) &&
(UART_D_REG(uartPtr))); /* Çå½ÓÊÕ»º³åÇø */
#if UART2_IRQ_ENABLE
#if UART2_SEND_IRQ
UART_C2_REG(uartPtr) |= UART_C2_TCIE_MASK;
#endif
#if UART2_RECEIVE_IRQ
UART_C2_REG(uartPtr) |= UART_C2_RIE_MASK;
#endif
NVIC_EnableIRQ(UART2_IRQn);
NVIC_SetPriority(UART2_IRQn,5); /* Óû§×Ô¼º¶¨Òå */
#endif
}
主函数调用:
int main()
{
SystemCoreClockUpdate();
SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK
| SIM_SCGC5_PORTB_MASK
| SIM_SCGC5_PORTC_MASK
| SIM_SCGC5_PORTD_MASK
| SIM_SCGC5_PORTE_MASK );
uart1Init(115200,0,0,8,1);
uart0Init(115200,0,0,8,1);
uart2Init(115200,0,0,8,1);
while(1){ /* ²»¶Ï·×ªIO£¬LEDÉÁ˸ */
// GPIO_TOGGLE(MKL_PORTA,5);
// myDelay(200);
// GPIO_TOGGLE(MKL_PORTA,5);
myDelay(200);
// GPIO_TOGGLE(MKL_PORTA,5);
myDelay(200);
uart0SendString("打印信息
");
uart1SendString("打印信息ò
");
uart2SendString("打印信息
");
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>