LPC1766串口发送后接收乱码问题
2019-07-15 07:21发布
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
最近使用LPC1766芯片遇到一个问题,用硬件仿真看串口发送前数据是正确的,但是用TTL-USB发送到电脑后接收乱码。使用基础串口发送代码也是这个问题。
使用12M外部晶振。各位大神有知道原因的吗?万分感谢
主程序- int main(void)
- {
- uint32_t i,j, k=0;
-
- SystemInit();
- UART0_Init(9600);
-
- UART0_SendString("hello world");
- Delay(250);
- }
复制代码
串口配置- #define FOSC 12000000
- #define FCCLK (FOSC * 8)
- #define FCCO (FCCLK * 3)
- #define FPCLK (FCCLK / 4)
- void UART0_Init (uint32_t baudrate)
- {
- uint16_t usFdiv;
- /* UART0 */
- LPC_PINCON->PINSEL0 |= (1 << 4);
- LPC_PINCON->PINSEL0 |= (1 << 6);
-
- LPC_UART0->LCR = 0x83;
- usFdiv = (FPCLK / 16) / baudrate;
- LPC_UART0->DLM = usFdiv / 256;
- LPC_UART0->DLL = usFdiv % 256;
- LPC_UART0->LCR = 0x03;
- LPC_UART0->FCR = 0x06;
- }
复制代码系统初始化代码- #if (CLOCK_SETUP) /* Clock Setup */
- LPC_SC->SCS = SCS_Val;
- if (SCS_Val & (1 << 5)) { /* If Main Oscillator is enabled */
- while ((LPC_SC->SCS & (1<<6)) == 0);/* Wait for Oscillator to be ready */
- }
- LPC_SC->CCLKCFG = CCLKCFG_Val; /* Setup Clock Divider */
- #if (PLL0_SETUP)
- LPC_SC->CLKSRCSEL = CLKSRCSEL_Val; /* Select Clock Source for PLL0 */
- LPC_SC->PLL0CFG = PLL0CFG_Val; /* configure PLL0 */
- LPC_SC->PLL0FEED = 0xAA;
- LPC_SC->PLL0FEED = 0x55;
- LPC_SC->PLL0CON = 0x01; /* PLL0 Enable */
- LPC_SC->PLL0FEED = 0xAA;
- LPC_SC->PLL0FEED = 0x55;
- while (!(LPC_SC->PLL0STAT & (1<<26)));/* Wait for PLOCK0 */
- LPC_SC->PLL0CON = 0x03; /* PLL0 Enable & Connect */
- LPC_SC->PLL0FEED = 0xAA;
- LPC_SC->PLL0FEED = 0x55;
- while (!(LPC_SC->PLL0STAT & ((1<<25) | (1<<24))));/* Wait for PLLC0_STAT & PLLE0_STAT */
- #endif
- #if (PLL1_SETUP)
- LPC_SC->PLL1CFG = PLL1CFG_Val;
- LPC_SC->PLL1FEED = 0xAA;
- LPC_SC->PLL1FEED = 0x55;
- LPC_SC->PLL1CON = 0x01; /* PLL1 Enable */
- LPC_SC->PLL1FEED = 0xAA;
- LPC_SC->PLL1FEED = 0x55;
- while (!(LPC_SC->PLL1STAT & (1<<10)));/* Wait for PLOCK1 */
- LPC_SC->PLL1CON = 0x03; /* PLL1 Enable & Connect */
- LPC_SC->PLL1FEED = 0xAA;
- LPC_SC->PLL1FEED = 0x55;
- while (!(LPC_SC->PLL1STAT & ((1<< 9) | (1<< 8))));/* Wait for PLLC1_STAT & PLLE1_STAT */
- #else
- LPC_SC->USBCLKCFG = USBCLKCFG_Val; /* Setup USB Clock Divider */
- #endif
- LPC_SC->PCLKSEL0 = PCLKSEL0_Val; /* Peripheral Clock Selection */
- LPC_SC->PCLKSEL1 = PCLKSEL1_Val;
- LPC_SC->PCONP = PCONP_Val; /* Power Control for Peripherals */
- LPC_SC->CLKOUTCFG = CLKOUTCFG_Val; /* Clock Output Configuration */
- #endif
- #if (FLASH_SETUP == 1) /* Flash Accelerator Setup */
- LPC_SC->FLASHCFG = FLASHCFG_Val;
- #endif
- }
复制代码
-
一周热门 更多>