MKE06Z UART问题

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MKE06Z UART问题

1,851 Views
yudongjin
Contributor II

有没有人使用SDK_2.3.0_MKE06Z128xxx4编写UART程序的?我在使用SDK中提供的例程进行UART初始化时,UART相关的寄存器内容不变,最终UART不工作!求解

0 Kudos
3 Replies

1,458 Views
yudongjin
Contributor II

问题解决:谢谢各位。

1、在keil mdk  DEBUG环境下,系统参数窗口显示uart0/1/2的寄存器值均为0的问题,我认为是IDE问题(不完全确定),实际参数已写入,但窗口就是不显示内容,而同工程下,ADC、TIMER等寄存器参数都能显示正常,这个问题调了很长时间。

2、TX没有输出波形,是因为我使用UART0,使用PTA2,PTA3引脚,而MKE06Z唯有这两引脚需上拉电阻,这个是我没细看说明书。

谢谢各位!

0 Kudos

1,458 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Yudong:

建议你参考下官方例程, 这些例程都是可以工作的

SDK_2.3.0_FRDM-KE06Z\boards\frdmke06z\driver_examples\uart

我测试了interrupt,  例程初始化uart 1, register都是正常的

Regards

Daniel

0 Kudos

1,458 Views
yudongjin
Contributor II
我的初始化程序如下,编译通过,但运行后,uart0的寄存器均为0!而同一个工程中,ADC、定时器等的寄存器内容都初始化及时变的。有人遇到过吗?急!!!
void uart_init(void)
{
   UART_ConfigType sConfig = {0};
    u8IsSendDone = 1;
    sConfig.u32SysClkHz = 20970000;
    sConfig.u32Baudrate = 9600;
    sConfig.sSettings.b9bitModeEn = 0;
    sConfig.sSettings.bParityEn = 0;
    UARTx_Init(UART0, &sConfig);
  
    UART_SetTxDoneCallback(UART0, UART_SendDone);
    UART_SetCallback(UART_HandleInt);  
    NVIC_EnableIRQ(UART0_IRQn);   
}
void UARTx_Init(UART_Type *pUART, UART_ConfigType *pConfig)
{
    uint16_t u16Sbr;
    uint8_t u8Temp;
    uint32_t u32SysClk = pConfig->u32SysClkHz;
    uint32_t u32Baud = pConfig->u32Baudrate;
    uint8_t b9bitModeEn = pConfig->sSettings.b9bitModeEn;
    uint8_t bParityEn = pConfig->sSettings.bParityEn;
    uint8_t bParityType = pConfig->sSettings.bParityType;
    /* Sanity check */
//    ASSERT((pUART == UART0) || (pUART == UART1) || (pUART == UART2));
 
 /* Enable the clock to the selected UART */   
    if (pUART == UART0)
    {
        SIM->SCGC |= SIM_SCGC_UART0_MASK;
    }
#if defined(CPU_KE02)  | defined(CPU_KE06)
    else if (pUART == UART1)
    {
        SIM->SCGC |= SIM_SCGC_UART1_MASK;
    }
    else
    {
        SIM->SCGC |= SIM_SCGC_UART2_MASK;
    }
#endif  
    /* Make sure that the transmitter and receiver are disabled while we
     * change settings.
     */
    pUART->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK );
   
    /* Configure the UART for 8-bit mode, no parity */
    pUART->C1 = 0;
    //8-bit mode config
    if (b9bitModeEn)
    {
        //if not the default 8-bit mode, then enable 9-bit mode
        pUART->C1 |= UART_C1_M_MASK;
    }
    //parity check config
    if (bParityEn)
    {
        pUART->C1 |= UART_C1_PE_MASK;
        if (bParityType)
        {
            //if not defult even parity type, enable odd parity type
            pUART->C1 |= UART_C1_PT_MASK;
        }
    }
   
    /* Calculate baud settings */
    u16Sbr = (((u32SysClk)>>4) + (u32Baud>>1))/u32Baud;
   
    /* Save off the current value of the UARTx_BDH except for the SBR field */
    u8Temp = pUART->BDH & ~(UART_BDH_SBR_MASK);
   
    pUART->BDH = u8Temp |  UART_BDH_SBR(u16Sbr >> 8);
    pUART->BDL = (uint8_t)(u16Sbr & UART_BDL_SBR_MASK);
    /* Enable receiver and transmitter */
    pUART->C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK );
}
0 Kudos