我的初始化程序如下,编译通过,但运行后,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 );
}