在线时间8 小时
UID422361
注册时间2014-10-24
NXP金币0
TA的每日心情 | 开心 2016-10-31 14:01 |
---|
签到天数: 2 天 连续签到: 1 天 [LV.1]初来乍到
注册会员

- 积分
- 128
- 最后登录
- 2017-8-2
|
板子到手先打印来看看;
贴贴串口代码:
- // setup_debug_uart, hard coded to UART0, desired_baudrate/8/N/1
- void setup_debug_uart(uint32_t sbond) {
- // Select the baud rate
- const uint32_t desired_baud = sbond;
- // Turn on relevant clocks
- LPC_SYSCON->SYSAHBCLKCTRL |= (UART0 | SWM);
- // Connect UART0 TXD, RXD signals to port pins
- ConfigSWM(U0_TXD, P0_4); // Use with USB-to-RS232 break-out cable
- ConfigSWM(U0_RXD, P0_0); // Use with USB-to-RS232 break-out cable
- //ConfigSWM(U0_TXD, TARGET_TX); // For MBED serial port (requires board mod.)
- //ConfigSWM(U0_RXD, TARGET_RX); // For MBED serial port (requires board mod.)
-
- // UART BRG calculation:
- // For asynchronous mode (UART mode) the BRG formula is:
- // (BRG + 1) * (1 + (m/256)) * (UARTCLKDIV) * (16 * baudrate Hz.) = MainClock Hz.
- // As long as UARTCLKDIV = AHBCLKDIV, and FRG = 1, the System Clock and the UARTn_PCLKs will be the same.
- // For this example, we set m = 0 (so FRG = 1), and UARTCLKDIV = AHBCLKDIV.
- // Then, we can use the SystemCoreClock variable, as set by the function SystemCoreClockUpdate(),
- // in our BRG calculation as follows:
- // BRG = (SystemCoreClock Hz. / (16 * desired_baud Hz.)) - 1
- // Configure the UARTCLKDIV, default for calculation below is same as AHBCLKDIV
- LPC_SYSCON->UARTCLKDIV = LPC_SYSCON->SYSAHBCLKDIV;
- // Configure the FRG (default for calculation below is divide-by-1)
- LPC_SYSCON->UARTFRGMULT = 0;
- LPC_SYSCON->UARTFRGDIV = 255;
- // Give USART0 a reset
- LPC_SYSCON->PRESETCTRL &= (UART0_RST_N);
- LPC_SYSCON->PRESETCTRL |= ~(UART0_RST_N);
- // Get the System Clock frequency for the BRG calculation.
- SystemCoreClockUpdate();
-
- // Write calculation result to BRG register
- LPC_USART0->BRG = (SystemCoreClock / (16 * desired_baud)) - 1;
- // Configure the USART0 CFG register:
- // 8 data bits, no parity, one stop bit, no flow control, asynchronous mode
- LPC_USART0->CFG = DATA_LENG_8|PARITY_NONE|STOP_BIT_1;
- // Configure the USART0 CTL register (nothing to be done here)
- // No continuous break, no address detect, no Tx disable, no CC, no CLRCC
- LPC_USART0->CTL = 0;
- // Clear any pending flags (Just to be safe, isn't necessary after the peripheral reset)
- LPC_USART0->STAT = 0xFFFF;
- // Don't enable the USART0 RX Ready Interrupt, this function assumes a polled use case
- //LPC_USART0->INTENSET = RXRDY;
- //NVIC_EnableIRQ(UART0_IRQn);
- // Enable USART0
- LPC_USART0->CFG |= UART_EN;
-
- }
- // This is for Keil projects.
- uint8_t sendchar (uint8_t ch) {
- while (!((LPC_USART0->STAT) & TXRDY)); // Wait for TX Ready
- return (LPC_USART0->TXDAT = ch); // Write one character to TX data register
- }
- void Uprintf(uint8_t *schar)
- {
- while(*schar !='\0')
- {
- sendchar(*schar);
- schar++;
- }
- }
复制代码
|
|