void rs422_uart_init(uint32_t baudrate, uint16_t data_bits,uint16_t parity, uint16_t stopbits)
{
rcu_periph_clock_enable(AS32_GPIO_RX_RCC);
rcu_periph_clock_enable(AS32_GPIO_TX_RCC);
rcu_periph_clock_enable(AS32_UART_RCC);
/* connect port to USARTx_Tx */
gpio_af_set(AS32_GPIO_TX_PORT, AS32_UART_AF, AS32_GPIO_TX_PIN);
/* connect port to USARTx_Rx */
gpio_af_set(AS32_GPIO_RX_PORT, AS32_UART_AF, AS32_GPIO_RX_PIN);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(AS32_GPIO_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, AS32_GPIO_TX_PIN);
gpio_output_options_set(AS32_GPIO_TX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, AS32_GPIO_TX_PIN);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(AS32_GPIO_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, AS32_GPIO_RX_PIN);
gpio_output_options_set(AS32_GPIO_RX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, AS32_GPIO_RX_PIN);
usart_deinit(AS32_UART);
usart_baudrate_set(AS32_UART, baudrate);
usart_transmit_config(AS32_UART, USART_TRANSMIT_ENABLE);
usart_receive_config(AS32_UART, USART_RECEIVE_ENABLE);
nvic_irq_enable(AS32_UART_IRQ, 1, 1);
#ifdef AS32_DIR_PORT
rcu_periph_clock_enable(AS32_DIR_RCC);
gpio_output_options_set(AS32_DIR_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, AS32_DIR_PIN);
gpio_mode_set(AS32_DIR_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, AS32_DIR_PIN);
gpio_bit_reset(AS32_DIR_PORT, AS32_DIR_PIN);
#endif
usart_interrupt_flag_clear(RS485_UART,USART_INT_FLAG_RBNE_ORERR);
usart_interrupt_enable(AS32_UART,USART_INT_RBNE);
usart_enable(AS32_UART);
usart_transmit_config(AS32_UART, USART_TRANSMIT_ENABLE);
usart_receive_config(AS32_UART, USART_RECEIVE_ENABLE);
}
ST-link 调试, 寄存器STAT REA位,没法变换为1 , 也就是 接收核心部分没有工作,
同样的代码 使用USART0 就可以, 这是为什么? |