LPCUART1如何使用

Home 论坛 开发和更新问题 LPCUART1如何使用

  • This topic has 1 个回复, 2 个参与人, and was last updated 5 years 前 by HowardHoward.
正在查看 2 帖子:1-2 (共 2 个帖子)
  • 作者
    帖子
  • #1947
    hehunghehung
    参与者

    按照例程的方式可以使用串口UART0,但是按照相同的方式不能使用UART1.

     

    pin_mux.c

     

    #define PIN25_IDX 25u /*!< Pin number for pin 7 in a port */
    #define PIN26_IDX 26u /*!< Pin number for pin 8 in a port */

    void BOARD_InitPins(void) {
    CLOCK_EnableClock(kCLOCK_PortC); /* Clock Gate Control: 0x01u */
    CLOCK_EnableClock(kCLOCK_PortA); /* Clock Gate Control: 0x01u */

    PORT_SetPinMux(PORTC, PIN7_IDX, kPORT_MuxAlt3); /* PORTC7 (pin N2) is configured as LPUART0_RX */
    PORT_SetPinMux(PORTC, PIN8_IDX, kPORT_MuxAlt3); /* PORTC8 (pin P3) is configured as LPUART0_TX */
    PORT_SetPinMux(PORTA, PIN25_IDX, kPORT_MuxAlt3); /* PORTC25 (pin N2) is configured as LPUART0_RX */
    PORT_SetPinMux(PORTA, PIN26_IDX, kPORT_MuxAlt3); /* PORTC26 (pin P3) is configured as LPUART0_TX */
    }

    board.c

     

    /* Initialize debug console. */
    void BOARD_InitDebugConsole(void)
    {
    CLOCK_SetIpSrc(kCLOCK_Lpuart0, kCLOCK_IpSrcFircAsync);
    CLOCK_SetIpSrc(kCLOCK_Lpuart1, kCLOCK_IpSrcFircAsync);

    uint32_t uartClkSrcFreq = BOARD_DEBUG_UART_CLK_FREQ;

    DbgConsole_Init(BOARD_DEBUG_UART_BASEADDR, BOARD_DEBUG_UART_BAUDRATE, BOARD_DEBUG_UART_TYPE, uartClkSrcFreq);
    }

     

    main.c

    /*******************************************************************************
    * Definitions
    ******************************************************************************/
    #define DEMO_LPUART LPUART1
    #define DEMO_LPUART_CLKSRC kCLOCK_ScgFircAsyncDiv2Clk
    #define DEMO_LPUART_CLK_FREQ CLOCK_GetFreq(kCLOCK_ScgFircAsyncDiv2Clk)

    int main(void)
    {
    uint8_t ch;
    lpuart_config_t config;

    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    /*
    * config.baudRate_Bps = 115200U;
    * config.parityMode = kLPUART_ParityDisabled;
    * config.stopBitCount = kLPUART_OneStopBit;
    * config.txFifoWatermark = 0;
    * config.rxFifoWatermark = 0;
    * config.enableTx = false;
    * config.enableRx = false;
    */
    LPUART_GetDefaultConfig(&config);
    config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
    config.enableTx = true;
    config.enableRx = true;

    LPUART_Init(DEMO_LPUART, &config, DEMO_LPUART_CLK_FREQ);

    LPUART_WriteBlocking(DEMO_LPUART, txbuff, sizeof(txbuff) – 1);

    while (1)
    {
    LPUART_ReadBlocking(DEMO_LPUART, &ch, 1);
    LPUART_WriteBlocking(DEMO_LPUART, &ch, 1);
    }
    }

     

     

    上述代码操作不能实现串口传输,UART1和UART0有什么需要区别配置的吗?

     

    #1950
    HowardHoward
    参与者

    你是参照哪个例子?这里给你一些信息:

    1. 检查Pin_mux配置是否正确
    2. 检查对应模块的clock是否enable
    3. 如果用中断方式,看看RISC-V核对应的中断向量分配,看看对应的模块中断是不是通过INTMUX触发中断的。如果是建议看看论坛其他帖子关于INTMUX中断的问题
正在查看 2 帖子:1-2 (共 2 个帖子)
  • 抱歉,回复话题必需登录。