crystal001 发表于 2020-3-3 15:28

HC32L15xx开发板的UART问题

本帖最后由 crystal001 于 2020-3-3 15:30 编辑

求助大神们
问题描述:
串口收发测试,中断接收,轮询发送,测试过程中,接收正常,但是发送不出数据。单收和单发都正常。
原理图:串口使用PIN59和PIN60

代码如下:
#include "uart.h"
#include "gpio.h"
#include "clk.h"

uint8_t u8TxData = {1,2,3,4,5,6,7,8,9,10};//"HUADA MCU!";
uint8_t u8RxData;
uint8_t u8TxCnt = 0, u8RxCnt = 0;
uint8_t u8Cnt = 0;

#define UARTRXUARTCH6
#define UARTTXUARTCH6

static void UartIoConfig(void)
{
    Gpio_SetFunc_SIN6_0(x);
    Gpio_SetFunc_SOT6_0(x);
      M0P_GPIO->FN_SEL08_f.SCS60B= 1;
}

void RxIntCallback(void)
{
    u8RxData = Uart_ReceiveData(UARTRX);
    u8RxCnt++;
      
      Uart_DisableIrq(UARTRX, UartRxIrq);
      Uart_SendData(UARTTX, u8TxData);
      if(u8Cnt<10)
      {
                u8Cnt++;
      }                        
      else u8Cnt=0;
      delay1ms(1);
      Uart_EnableIrq(UARTRX, UartRxIrq);
}

int32_t main(void)
{      
    stc_uart_config_t stcUartTxConfig;
    stc_uart_config_t stcUartRxConfig;
    stc_uart_irq_cb_tstcUartRxIrqCb;

    DDL_ZERO_STRUCT(stcUartTxConfig);
    DDL_ZERO_STRUCT(stcUartRxConfig);

    DDL_ZERO_STRUCT(stcUartRxIrqCb);

    /* Config the UART IO */
    UartIoConfig();

    /* Init the UART */
    stcUartRxIrqCb.pfnRxIrqCb = RxIntCallback;

    /* Config the UARTTX */
      stcUartTxConfig.bCarryEnable = FALSE;
    stcUartTxConfig.bCarryPolarity = TRUE;
    stcUartTxConfig.bCompensation = TRUE;
    stcUartTxConfig.bCtsWu = FALSE;
    stcUartTxConfig.bHwFlow = FALSE;
    stcUartTxConfig.bInvertData = FALSE;
    stcUartTxConfig.bTouchNvic = FALSE;
    stcUartTxConfig.bUseExtClk = FALSE;
    stcUartTxConfig.enBitDirection = UartDataLsbFirst;
    stcUartTxConfig.enDataLength = UartEightBits;
    stcUartTxConfig.enMode = UartNormal;
    stcUartTxConfig.enParity = UartParityNone;
    stcUartTxConfig.enStopBit = UartOneStopBit;
    stcUartTxConfig.u32BaudRate = 115200;

    Uart_Init(UARTTX, &stcUartTxConfig);
      
    Uart_EnableFunc(UARTTX, UartTx);

    /* Config the UARTRX */
    stcUartRxConfig.bCarryEnable = FALSE;
    stcUartRxConfig.bCarryPolarity = FALSE;
    stcUartRxConfig.bCompensation = FALSE;
    stcUartRxConfig.bCtsWu = FALSE;
    stcUartRxConfig.bHwFlow = FALSE;
    stcUartRxConfig.bInvertData = FALSE;
    stcUartRxConfig.bTouchNvic = TRUE;
    stcUartRxConfig.bUseExtClk = FALSE;
    stcUartRxConfig.enBitDirection = UartDataLsbFirst;
    stcUartRxConfig.enDataLength = UartEightBits;
    stcUartRxConfig.enMode = UartNormal;
    stcUartRxConfig.enParity = UartParityNone;
    stcUartRxConfig.enStopBit = UartOneStopBit;
    stcUartRxConfig.u32BaudRate = 115200;
    stcUartRxConfig.pstcIrqCb = &stcUartRxIrqCb;

    Uart_Init(UARTRX, &stcUartRxConfig);

    Uart_EnableFunc(UARTRX, UartRx);
      
    /* Configure interrupt */
    Uart_EnableIrq(UARTRX, UartRxIrq);

    while(1)
      {
                Uart_SendData(UARTTX, u8TxData);
                if(u8Cnt<10)
                {
                        u8Cnt++;
                }               
                else u8Cnt=0;
                delay1ms(1);
      }
}


页: [1]
查看完整版本: HC32L15xx开发板的UART问题