HC32F460,MCU可以接收到串口工具发送的数据,但是MCU发送电脑收不到,参考华大例程。
#include "project.h"
#define USART_CH (M4_USART3)
#define USART_BAUDRATE (115200ul)
#define USART_TX_PORT (PortC)
#define USART_TX_PIN (Pin07)
#define USART_TX_FUNC (Func_Usart3_Tx)
#define USART_RX_PORT (PortC)
#define USART_RX_PIN (Pin08)
#define USART_RX_FUNC (Func_Usart3_Rx)
#define USART_RI_NUM (INT_USART3_RI) //接收中断
#define USART_EI_NUM (INT_USART3_EI) //Empty中断(R/T?)
#define USART_TI_NUM (INT_USART3_TI) //发送中断
#define USART_TCI_NUM (INT_USART3_TCI) //发送完成中断
void UART_InBuff(uint8_t UART);
void USART3_SendStr(uint8_t *SendBuf,uint16_t length);
uint8_t hello[]="hello Aramis \r\n";
#define poweron "system poweron\r\n"
/*******************************************************************************
** \brief USART RX irq callback function.
**
** \param [in] None
**
** \retval None
**
******************************************************************************/
static uint16_t m_u16RxData;
static void UsartRxIrqCallback(void)
{
m_u16RxData = USART_RecData(USART_CH);
while (Reset == USART_GetStatus(USART_CH, UsartTxEmpty));
USART_SendData(USART_CH, m_u16RxData);
USART3_SendStr(hello,14);
// USART_FuncCmd(USART_CH, UsartTxAndTxEmptyInt, Enable);
}
void main(){
en_result_t enRet = Ok;
stc_irq_regi_conf_t stcIrqRegiCfg;
uint32_t u32Fcg1Periph = PWC_FCG1_PERIPH_USART1 | PWC_FCG1_PERIPH_USART2 | \
PWC_FCG1_PERIPH_USART3 | PWC_FCG1_PERIPH_USART4;
const stc_usart_uart_init_t stcInitCfg = {
UsartIntClkCkNoOutput,
UsartClkDiv_1,
UsartDataBits8,
UsartDataLsbFirst,
UsartOneStopBit,
UsartParityNone,
UsartSamleBit8,
UsartStartBitFallEdge,
UsartRtsEnable,
};
sysCLK_Init(); //PCLK0 40MHz
/* Enable peripheral clock */
PWC_Fcg1PeriphClockCmd(u32Fcg1Periph, Enable);
/* Initialize USART IO */
PORT_SetFunc(USART_RX_PORT, USART_RX_PIN, USART_RX_FUNC, Disable);
PORT_SetFunc(USART_TX_PORT, USART_TX_PIN, USART_TX_FUNC, Disable);
USART_UART_Init(USART_CH, &stcInitCfg);
USART_SetBaudrate(USART_CH, USART_BAUDRATE);
/* Set USART RX IRQ */
stcIrqRegiCfg.enIRQn = Int000_IRQn;
stcIrqRegiCfg.pfnCallback = &UsartRxIrqCallback;
stcIrqRegiCfg.enIntSrc = USART_RI_NUM;
enIrqRegistration(&stcIrqRegiCfg);
NVIC_SetPriority(stcIrqRegiCfg.enIRQn, DDL_IRQ_PRIORITY_DEFAULT);
NVIC_ClearPendingIRQ(stcIrqRegiCfg.enIRQn);
NVIC_EnableIRQ(stcIrqRegiCfg.enIRQn);
/*Enable RX && RX interupt function*/
USART_FuncCmd(USART_CH, UsartRx, Enable);
USART_FuncCmd(USART_CH, UsartRxInt, Enable);
USART3_SendStr(hello,sizeof(hello)-1);
USART3_SendStr(poweron,sizeof(poweron)-1);
while(1){
}
}
#ifndef UARTBUFF_SIZE
#define UARTBUFF_SIZE 200 //UART缓冲区大小,发送心跳返回长度290(AAAA反馈),但不影响判断_ack,这里定义280...
#endif
uint8_t UARTBuff[UARTBUFF_SIZE]={0}; //定义UART缓冲队列数组(FIFO)
//signed char UART_IndexW=0; //UART缓冲队列写入指针(头指针)
//signed char UART_IndexR=0; //UART缓冲队列读取指针(尾指针)
uint16_t UART_Count=0; //UART缓冲队列数据数
/*******************************************************************************
*名 称:USART1_SendStr
*功 能:UART发送一定长度的数据
*入口参数:*SendBuf--发送数组指针 length--发送长度
*说 明:
*******************************************************************************/
void USART3_SendStr(uint8_t *SendBuf,uint16_t length)
{
uint16_t i = 0;
while(length--){ /* Loop until the end of transmission */
while (Reset == USART_GetStatus(USART_CH, UsartTxEmpty)); /* Warit Tx data register empty */
USART_SendData(USART_CH, SendBuf[i++]);
}
}
|