C 代码问题 - 使用 e2studio 设置 UART



我目前正在做一个项目,使用RL78G14作为微控制器。该项目涉及制作红外遥控器和控制面板。如果一直在尝试编写代码来设置 UART。在传递 TxBuf 和 RxBuf 时,我收到一些传递不兼容指针类型的警告消息,并且我的 UART 似乎不起作用。谁能帮我写代码?

void main(void)
{
    R_MAIN_UserInit();
uart1Status = R_UART1_Receive(&RxBuf[0],1); // Prime UART1 Rx
while (1U)
{
    //Check if byte received on UART
            if (RxFlag)
            {
                // clear rx flag
                RxFlag = 0U;
                //Echo back the received character
                TxBuf[0] = RxBuf[0];
                //Send TX buffer, and specify how many characters to write
                uart1Status = R_UART1_Send(TxBuf,1);
                // re-Prime UART Rx
                uart1Status = R_UART1_Receive(RxBuf,1);
            }

            //If a character has been transmitted
            if (TxFlag)
            {
                // End of UART2 transmit
                TxFlag = 0U;   // clear tx flag
            }
}
/***********************************************************************************************************************
* Function Name: R_UART1_Receive
* Description  : This function receives UART1 data.
* Arguments    : rx_buf -
*                    receive buffer pointer
*                rx_num -
*                    buffer size
* Return Value : status -
*                    MD_OK or MD_ARGERROR
***********************************************************************************************************************/
MD_STATUS R_UART1_Receive(uint8_t * const rx_buf, uint16_t rx_num)
{
    MD_STATUS status = MD_OK;
if (rx_num < 1U)
{
    status = MD_ARGERROR;
}
else
{
    g_uart1_rx_count = 0U;
    g_uart1_rx_length = rx_num;
    gp_uart1_rx_address = rx_buf;
}
return (status);
}
/***********************************************************************************************************************
* Function Name: R_UART1_Send
* Description  : This function sends UART1 data.
* Arguments    : tx_buf -
*                    transfer buffer pointer
*                tx_num -
*                    buffer size
* Return Value : status -
*                    MD_OK or MD_ARGERROR
***********************************************************************************************************************/
MD_STATUS R_UART1_Send(uint8_t * const tx_buf, uint16_t tx_num)
{
    MD_STATUS status = MD_OK;
if (tx_num < 1U)
{
    status = MD_ARGERROR;
}
else
{
    gp_uart1_tx_address = tx_buf;
    g_uart1_tx_count = tx_num;
    STMK1 = 1U;    /* disable INTST1 interrupt */
    TXD1 = *gp_uart1_tx_address;
    gp_uart1_tx_address++;
    g_uart1_tx_count--;
    STMK1 = 0U;    /* enable INTST1 interrupt */
}
return (status);
}
  1. 如果您使用的是开发板,请检查R11引脚。它连接到CAN RXD芯片TJA1050T,因此不接收任何数据。切下 R11 跳线,它将开始工作。

  2. 你启动了UART1吗? 需要在初始化中启动它。

最新更新