21ic问答首页 - GD32F303RCT6 USART0的空闲中断进不去,仿真打断点也进不去中断
GD32F303RCT6 USART0的空闲中断进不去,仿真打断点也进不去中断
tianlan飞机2024-11-06
int main(void)
{ //¿ÉÒÔ×öµ½´«ÊäÊý¾Ý³öÀ´£¬¶¨µã´«ÊäÊý¾Ý³öÀ´
uint32_t Status2 =0;
uint32_t Status3;
uint16_t x;
dma_parameter_struct dma_init_struct2;
gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE); //ÏÂÔØ¿ÚNJTRSTÒý½Åµ±×öÆÕͨI/O¿Ú
rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);
systick_config(); //1ms systick
gpio_config(); //PA1,PA2,PA3¹Ü½ÅÅäÖÃ
/************************************************/
//UART0_init
rcu_periph_clock_enable(RCU_AF);//Need!!!!
//usart_halfduplex_enable(USART0);
rcu_periph_clock_enable(RCU_USART0); //ʹÄÜUSART0ʱÖÓ
gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
usart_deinit(USART0); //³õʼ»¯ //¸´Î»Ê±ÖÓ
usart_baudrate_set(USART0, 19200U); //¶¨Ò岨ÌØÂÊ
usart_receive_config(USART0, USART_RECEIVE_ENABLE); //½ÓÊÕʹÄÜ
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); //·¢ËÍʹÄÜ
usart_interrupt_enable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖжÏ
usart_interrupt_enable(USART0, USART_INT_IDLE); //¿ÕÏÐÖжÏ
usart_enable(USART0); //Ä£¿éʹÄÜ USART_INT_TC
nvic_irq_enable(USART0_IRQn, 0, 1);
RX0_DMAquest_StartOrInit();
TX0_DMAquest_StartOrInit();
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
usart_dma_transmit_config(USART0, USART_DENT_ENABLE);
//NVICEXTI_config();
// timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0);
// timer_interrupt_enable(TIMER0, TIMER_INT_CH0);
// usart_dma_transmit_config(USART0, USART_DENT_ENABLE);
// usart_dma_receive_config(USART0, USART_DENR_ENABLE);
/******************************************************/
/* configure DMA mode */
// dma_circulation_disable(DMA1, DMA_CH4); //²»Ñ»·
rcu_periph_clock_enable(RCU_CRC);
gpio_bit_set(GPIOB, GPIO_PIN_5);
dma_parameter_struct dma_init_struct;
while(1)
{
// if(++Tx_Delay >= 0x300)
// {
// Tx_Delay=0;
// usart_dma_transmit_config(UART3, USART_DENT_DISABLE);
// dma_channel_disable(DMA1, DMA_CH2); //¹Ø±ÕRx
// dma_channel_enable(DMA1, DMA_CH2);
// usart_dma_transmit_config(UART3, USART_DENT_ENABLE);
//6E 32 2E 76 61 6C 3D 31 32 33 ff ff ff
delay_1ms(500);
if(rxflag)
{
rxflag=0;
dma_parameter_struct dma_init_struct;
rcu_periph_clock_enable(RCU_DMA0); //¿ªÊ±ÖÓ
dma_deinit(DMA0, DMA_CH3); //³õʼ»¯Í¨µÀ3
dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; //ÄÚ´æµ½ÍâÉè
dma_init_struct.memory_addr = (uint32_t)&MyBuffRxUart3[0]; //¶¨Ò建³åÇøhostMainControl Uart3transmitt_buff
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; //
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; //8λλ¿í
dma_init_struct.number = 20;//ARRAYNUM(transmitter_buffer); //ÕâÀïÊÇ·¢ËÍÊý¾ÝµÄÊýÁ¿
dma_init_struct.periph_addr = ((uint32_t)0x40013804); //´®¿ÚµØÖ·
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; //¶¨¼Ä´æÆ÷
dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; //8λλ¿í
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; //×î¸ßÓÅÏȼ¶
dma_init(DMA0, DMA_CH3, &dma_init_struct);
dma_circulation_disable(DMA0, DMA_CH3);
dma_channel_enable(DMA0, DMA_CH3);
}
中断如下:
extern void RX0_DMAquest_StartOrInit(void);
extern uint8_t rxflag;
extern dma_parameter_struct dma_data_parameter;
void USART0_IRQHandler(void)
{
uint32_t clear;
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_TC)) //·¢ËÍcomplete±ê־λΪ1
{ /* transmit data */
usart_flag_clear(USART0, USART_FLAG_TC);
dma_channel_disable(DMA0, DMA_CH3);
// usart_interrupt_enable(USART0, USART_INT_IDLE); //¿ÕÏÐÖжÏ
// usart_interrupt_disable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖжÏ
dma_channel_enable(DMA0, DMA_CH3);
gpio_bit_reset(GPIOB, GPIO_PIN_5); //µãÁÁLED
}
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) //·¢ËÍnuLL±ê־λΪ1
{
dma_channel_disable(DMA0, DMA_CH4);
clear= USART_STAT0(USART0);
clear = USART_DATA(USART0);
usart_receive_config(USART0, USART_RECEIVE_ENABLE); //½ÓÊÕʹÄÜ
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
RX0_DMAquest_StartOrInit();
dma_channel_enable(DMA0, DMA_CH4);
// usart_interrupt_disable(USART0, USART_INT_IDLE); //¿ÕÏÐÖжÏ
// usart_interrupt_enable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖжÏ
rxflag=1;
}
}
{ //¿ÉÒÔ×öµ½´«ÊäÊý¾Ý³öÀ´£¬¶¨µã´«ÊäÊý¾Ý³öÀ´
uint32_t Status2 =0;
uint32_t Status3;
uint16_t x;
dma_parameter_struct dma_init_struct2;
gpio_pin_remap_config(GPIO_SWJ_NONJTRST_REMAP, ENABLE); //ÏÂÔØ¿ÚNJTRSTÒý½Åµ±×öÆÕͨI/O¿Ú
rcu_ahb_clock_config(RCU_AHB_CKSYS_DIV1);
systick_config(); //1ms systick
gpio_config(); //PA1,PA2,PA3¹Ü½ÅÅäÖÃ
/************************************************/
//UART0_init
rcu_periph_clock_enable(RCU_AF);//Need!!!!
//usart_halfduplex_enable(USART0);
rcu_periph_clock_enable(RCU_USART0); //ʹÄÜUSART0ʱÖÓ
gpio_pin_remap_config(GPIO_USART0_REMAP,ENABLE);
usart_deinit(USART0); //³õʼ»¯ //¸´Î»Ê±ÖÓ
usart_baudrate_set(USART0, 19200U); //¶¨Ò岨ÌØÂÊ
usart_receive_config(USART0, USART_RECEIVE_ENABLE); //½ÓÊÕʹÄÜ
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE); //·¢ËÍʹÄÜ
usart_interrupt_enable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖжÏ
usart_interrupt_enable(USART0, USART_INT_IDLE); //¿ÕÏÐÖжÏ
usart_enable(USART0); //Ä£¿éʹÄÜ USART_INT_TC
nvic_irq_enable(USART0_IRQn, 0, 1);
RX0_DMAquest_StartOrInit();
TX0_DMAquest_StartOrInit();
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
usart_dma_transmit_config(USART0, USART_DENT_ENABLE);
//NVICEXTI_config();
// timer_interrupt_flag_clear(TIMER0, TIMER_INT_FLAG_CH0);
// timer_interrupt_enable(TIMER0, TIMER_INT_CH0);
// usart_dma_transmit_config(USART0, USART_DENT_ENABLE);
// usart_dma_receive_config(USART0, USART_DENR_ENABLE);
/******************************************************/
/* configure DMA mode */
// dma_circulation_disable(DMA1, DMA_CH4); //²»Ñ»·
rcu_periph_clock_enable(RCU_CRC);
gpio_bit_set(GPIOB, GPIO_PIN_5);
dma_parameter_struct dma_init_struct;
while(1)
{
// if(++Tx_Delay >= 0x300)
// {
// Tx_Delay=0;
// usart_dma_transmit_config(UART3, USART_DENT_DISABLE);
// dma_channel_disable(DMA1, DMA_CH2); //¹Ø±ÕRx
// dma_channel_enable(DMA1, DMA_CH2);
// usart_dma_transmit_config(UART3, USART_DENT_ENABLE);
//6E 32 2E 76 61 6C 3D 31 32 33 ff ff ff
delay_1ms(500);
if(rxflag)
{
rxflag=0;
dma_parameter_struct dma_init_struct;
rcu_periph_clock_enable(RCU_DMA0); //¿ªÊ±ÖÓ
dma_deinit(DMA0, DMA_CH3); //³õʼ»¯Í¨µÀ3
dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; //ÄÚ´æµ½ÍâÉè
dma_init_struct.memory_addr = (uint32_t)&MyBuffRxUart3[0]; //¶¨Ò建³åÇøhostMainControl Uart3transmitt_buff
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; //
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; //8λλ¿í
dma_init_struct.number = 20;//ARRAYNUM(transmitter_buffer); //ÕâÀïÊÇ·¢ËÍÊý¾ÝµÄÊýÁ¿
dma_init_struct.periph_addr = ((uint32_t)0x40013804); //´®¿ÚµØÖ·
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; //¶¨¼Ä´æÆ÷
dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; //8λλ¿í
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; //×î¸ßÓÅÏȼ¶
dma_init(DMA0, DMA_CH3, &dma_init_struct);
dma_circulation_disable(DMA0, DMA_CH3);
dma_channel_enable(DMA0, DMA_CH3);
}
中断如下:
extern void RX0_DMAquest_StartOrInit(void);
extern uint8_t rxflag;
extern dma_parameter_struct dma_data_parameter;
void USART0_IRQHandler(void)
{
uint32_t clear;
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_TC)) //·¢ËÍcomplete±ê־λΪ1
{ /* transmit data */
usart_flag_clear(USART0, USART_FLAG_TC);
dma_channel_disable(DMA0, DMA_CH3);
// usart_interrupt_enable(USART0, USART_INT_IDLE); //¿ÕÏÐÖжÏ
// usart_interrupt_disable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖжÏ
dma_channel_enable(DMA0, DMA_CH3);
gpio_bit_reset(GPIOB, GPIO_PIN_5); //µãÁÁLED
}
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) //·¢ËÍnuLL±ê־λΪ1
{
dma_channel_disable(DMA0, DMA_CH4);
clear= USART_STAT0(USART0);
clear = USART_DATA(USART0);
usart_receive_config(USART0, USART_RECEIVE_ENABLE); //½ÓÊÕʹÄÜ
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
RX0_DMAquest_StartOrInit();
dma_channel_enable(DMA0, DMA_CH4);
// usart_interrupt_disable(USART0, USART_INT_IDLE); //¿ÕÏÐÖжÏ
// usart_interrupt_enable(USART0, USART_INT_TC); //·¢ËÍÍê³ÉÖжÏ
rxflag=1;
}
}
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
赞0
评论
2024-11-14
您需要登录后才可以回复 登录 | 注册