本帖最后由 lishuoff 于 2022-9-6 10:42 编辑
void nvic_init(void)
{
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
nvic_irq_enable(USART1_IRQn, 0,0);
}
int main(void)
{
/* configure systick */
systick_config();
nvic_init();
/* configure EVAL_COM0 */
gd_eval_com_init(USART1);
/* configure USART DMA */
usart_dma_config();
/* enable USART0 DMA channel transmission and reception */
dma_channel_enable(DMA0, DMA_CH5);
/* USART DMA enable for transmission and reception */
usart_dma_receive_config(USART1, USART_DENR_ENABLE);//USART_CTL2 DENR µÚ6bit
usart_dma_transmit_config(USART1, USART_DENT_ENABLE);
while(1){;}
}
void gd_eval_com_init(uint32_t com)
{
/* enable GPIO clock */
rcu_periph_clock_enable(RCU_GPIOA);
/* enable USART clock */
rcu_periph_clock_enable(RCU_USART1);
/* connect port to USARTx_Tx */
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_2);
/* connect port to USARTx_Rx */
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_3);
/* USART configure */
usart_deinit(com);
usart_baudrate_set(com, 9600U);
usart_word_length_set(com, USART_WL_8BIT);
usart_stop_bit_set(com, USART_STB_1BIT);
usart_parity_config(com, USART_PM_NONE);
usart_receive_config(com, USART_RECEIVE_ENABLE);
usart_transmit_config(com, USART_TRANSMIT_ENABLE);
<blockquote>usart_interrupt_enable(com, USART_INT_IDLE);
void usart_dma_config(void)
{
dma_parameter_struct dma_init_struct;
/* enable DMA0 */
rcu_periph_clock_enable(RCU_DMA0);
/* deinitialize DMA channel3(USART0 tx) */
dma_deinit(DMA0, DMA_CH5);
dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_init_struct.memory_addr = (uint32_t)rx_buffer;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT;
dma_init_struct.number = ARRAYNUM(tx_buffer);
dma_init_struct.periph_addr = USART1_DATA_ADDRESS;
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT;
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_init(DMA0, DMA_CH5, &dma_init_struct);
/* configure DMA mode */
dma_circulation_disable(DMA0, DMA_CH5);
dma_memory_to_memory_disable(DMA0, DMA_CH5);
}
void USART1_IRQHandler(void)
{
<blockquote><span style="white-space:pre"> </span>if(SET == usart_interrupt_flag_get(USART1, USART_INT_FLAG_IDLE))
仿真调试,可以收到数据
但是不能进入空闲中断,请大家看看什么问题
调试发现,USART1的status寄存器ilde与rbne并没有置位
|