程序中写死发送固定数据,但是串口工具接收显示与发送并不一致,修改波特率后还是这样。什么原因会导致这种情况呢。[code]void SYS_Init(void)
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Enable Internal RC 22.1184MHz clock */
CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
/* Waiting for Internal RC clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
/* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
/* Enable external XTAL 12MHz clock */
CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
/* Waiting for external XTAL clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);
/* Set core clock as PLL_CLOCK from PLL */
CLK_SetCoreClock(PLL_CLOCK);
/* Enable UART module clock */
CLK_EnableModuleClock(UART0_MODULE);
// CLK_EnableModuleClock(UART1_MODULE);
/* Select UART module clock source */
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
// CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set P3 multi-function pins for UART0 RXD and TXD */
SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0);
/* Set P1 multi-function pins for UART1 RXD and TXD */
// SYS->P1_MFP &= ~(SYS_MFP_P12_Msk | SYS_MFP_P13_Msk);
// SYS->P1_MFP |= (SYS_MFP_P12_RXD1 | SYS_MFP_P13_TXD1);
/* Set P0 multi-function pins for UART1 RTS */
// SYS->P0_MFP = SYS->P0_MFP & (~SYS_MFP_P01_Msk) | SYS_MFP_P01_RTS1;
// SYS->P3_MFP = SYS->P3_MFP & (~SYS_MFP_P32_Msk) | SYS_MFP_P32_RTS1;
}
void UART0_Init()
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART */
/*---------------------------------------------------------------------------------------------------------*/
/* Reset UART0 module */
SYS_ResetModule(UART0_RST);
/* Configure UART0 and set UART0 Baudrate */
UART_Open(UART0, 9600);
}
int32_t main(void)
{
uint8_t i,j;
uint32_t u32i;
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
/* Init UART0 for printf */
UART0_Init();
/* Init UART1 for testing */
// UART1_Init();
/*---------------------------------------------------------------------------------------------------------*/
/* SAMPLE CODE */
/*---------------------------------------------------------------------------------------------------------*/
// UART_EnableFlowCtrl(UART0);
// /* Send 1k bytes data */
// for(u32i = 0; u32i < 1024; u32i++)
// {
// /* Send 1 byte data */
// UART_WRITE(UART0, u32i & 0xFF);
// /* Wait if Tx FIFO is full */
// while(UART_IS_TX_FULL(UART0));
// }
//
/* Configure P1.2 as Output mode and P4.1 as Input mode */
// GPIO_SetMode(P4, BIT2, GPIO_PMD_OUTPUT);
while(1)
{
for(i=1;i<5;i++)
{
UART_Write(UART0, &i, 1);
// j++;
CLK_SysTickDelay(100000);
}
//// printf("hello world\n");
// CLK_SysTickDelay(100000);
// my_RS485_9bitModeMaster();
//// printf("\n\nUART Sample Program\n");
// for( i=0;i<0xFFFF;i++)
// {
//
// }
}
}
|