打印
[技术问答]

HC32L15xx开发板的UART问题

[复制链接]
685|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 crystal001 于 2020-3-3 15:30 编辑

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

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

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

#define UARTRX  UARTCH6
#define UARTTX  UARTCH6

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[u8RxCnt] = Uart_ReceiveData(UARTRX);
    u8RxCnt++;
        
        Uart_DisableIrq(UARTRX, UartRxIrq);
        Uart_SendData(UARTTX, u8TxData[u8Cnt]);
        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_t  stcUartRxIrqCb;

    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[u8Cnt]);
                if(u8Cnt<10)
                {
                        u8Cnt++;
                }               
                else u8Cnt=0;
                delay1ms(1);
        }
}


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

1

帖子

0

粉丝