我对比官方的例程做的感觉没啥不同啊,不过官方是用的usart0,是uart3不能用USART_INT_RBNE??这边中断一触发直接死机进入hardfault实在无法理解,工程中只有一个systick中断,把systick中断的优先级和工程堆栈加大都没有用,照样死
void uart3_config(void)
{
/* enable GPIO clock */
rcu_periph_clock_enable(UART3_GPIO_TX_CLOCK);
rcu_periph_clock_enable(UART3_GPIO_RX_CLOCK);
/* enable USART clock */
rcu_periph_clock_enable(UART3_CLOCK);
/* connect port to USARTx_Tx */
gpio_af_set(UART3_GPIO_TX, UART3_GPIO_TX_AF, UART3_TX_PIN);
/* connect port to USARTx_Rx */
gpio_af_set(UART3_GPIO_RX, UART3_GPIO_RX_AF, UART3_RX_PIN);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(UART3_GPIO_TX, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART3_TX_PIN);
gpio_output_options_set(UART3_GPIO_TX, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART3_TX_PIN);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(UART3_GPIO_RX, GPIO_MODE_AF, GPIO_PUPD_PULLUP, UART3_RX_PIN);
gpio_output_options_set(UART3_GPIO_RX, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, UART3_RX_PIN);
/* configure USART */
usart_deinit(UART3);
usart_baudrate_set(UART3, 115200U);
usart_receive_config(UART3, USART_RECEIVE_ENABLE);
usart_transmit_config(UART3, USART_TRANSMIT_ENABLE);
// usart_dma_receive_config(UART3, USART_RECEIVE_DMA_ENABLE);
usart_enable(UART3);
nvic_irq_enable(UART3_IRQn, 0, 0);
usart_interrupt_enable(UART3, USART_INT_RBNE);
}
uint16_t val=0;
void UART3_IRQHandler(void)
{
if(RESET != usart_interrupt_flag_get(UART3, USART_INT_RBNE)){
/* clear IDLE flag */
val= usart_data_receive(UART3);
}
}
|