请教个问题,基于XMC1404芯片,在调试串口接收时为什么一直无法接收数据呢?请各位大佬帮忙看一下,万分感谢?
#define UART_RX_PIN P2_12
#define UART_TX_PIN P2_13
XMC_GPIO_CONFIG_t rx_pin_config;
XMC_GPIO_CONFIG_t tx_pin_config;
XMC_USIC_CH_t *uart = XMC_UART1_CH1;
XMC_UART_CH_CONFIG_t uart_config =
{
.baudrate = 9600U,
.data_bits = 8U,
.stop_bits = 1U,
.parity_mode = XMC_USIC_CH_PARITY_MODE_NONE
};
//初始化
void init_rs485(void)
{
/UART initialization sequence/
XMC_UART_CH_Init(uart, &uart_config);
XMC_UART_CH_SetInputSource(uart, XMC_UART_CH_INPUT_RXD , USIC1_C1_DX0_P2_12); //USIC1_C1_DX0_P2_12 USIC1_C1_DX0_P2_12
XMC_UART_CH_Start(uart); // uart.CCR.mode=UART-> USIC0_CH0 is switched for UART operation mode
rx_pin_config.mode = XMC_GPIO_MODE_INPUT_PULL_UP; // Rx input with internal pull-up
XMC_GPIO_Init(UART_RX_PIN, &rx_pin_config);
tx_pin_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
tx_pin_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT7; // Tx output in ALT2
XMC_GPIO_Init(UART_TX_PIN, &tx_pin_config);
//XMC_GPIO_Init(XMC_GPIO_PORT1, 5, &tx_pin_config); // optional: configure pin1_5 as ALT2 output pin with '1'
//////////// 2. the advanced UART LLD test SW: receive from keyboard using interrupt
XMC_USIC_CH_EnableEvent(uart, XMC_USIC_CH_EVENT_STANDARD_RECEIVE); // enable interrupt RI
XMC_USIC_CH_SetInterruptNodePointer(uart, XMC_USIC_CH_INTERRUPT_NODE_POINTER_RECEIVE, 0); // set USIC0 SR5 for RI
XMC_USIC_CH_EnableEvent(uart, XMC_USIC_CH_EVENT_ALTERNATIVE_RECEIVE); // 'USIC_AI.007' -> AIR ON
XMC_USIC_CH_SetInterruptNodePointer(uart, XMC_USIC_CH_INTERRUPT_NODE_POINTER_ALTERNATE_RECEIVE, 0);
NVIC_SetPriority(IRQ9_IRQn,0); // CMSIS function for NVIC control: NVIC_SetPriority(IRQn_t IRQn, uint32_t priority): priority=0..63
NVIC_EnableIRQ(IRQ9_IRQn); // CMSIS function for NVIC control: enable IRQn
}
void IRQ9_Handler(void) // USIC0_5_IRQHandler
{
if (XMC_UART_CH_GetStatusFlag(XMC_UART1_CH1) == true)
{
received_data[cnt] = XMC_UART_CH_GetReceivedData(uart); // receive data
}
cnt++;
}
|