主函数如下:
#include "gd32vf103.h"
#include "gd32vf103v_eval.h"
#include "systick.h"
#include
extern uint32_t rxbuffer[];
extern uint16_t rxcount;
extern FlagStatus g_receive_complete;
int main(void)
{
/* USART interrupt configuration */
eclic_global_interrupt_enable();
eclic_priority_group_set(ECLIC_PRIGROUP_LEVEL3_PRIO1);
eclic_irq_enable(USART0_IRQn, 1, 0);
gd_eval_com_init(USART0);
usart_interrupt_enable(USART0, USART_INT_RBNE);
while(1)
{
if(g_receive_complete == SET) {
rxcount = 0;
g_receive_complete = RESET;
delay_1ms(500);
delay_1ms(500);
printf("%dnr",rxbuffer[0]);
printf("%dnr",rxbuffer[1]);
printf("%dnr",rxbuffer[2]);
printf("%dnr",rxbuffer[3]);
printf("%dnr",rxbuffer[4]);
}
}
}
/* retarget the C library printf function to the USART */
int _put_char(int ch)
{
usart_data_transmit(USART0, (uint8_t) ch );
while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET){
}
return ch;
}
中断函数如下:(可以进入中断,但是无法接收发送出去的数据)
uint32_t rxbuffer[RX_BUF_SIZE];
__IO uint16_t rxcount = 0;
__IO FlagStatus g_receive_complete = RESET;
void USART0_IRQHandler(void)
{
if(RESET!=usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE))
{
/* read one byte from the receive data register */
rxbuffer[rxcount++] = (uint8_t)usart_data_receive(USART0); //
if(rxcount == RX_BUF_SIZE)
{
g_receive_complete = SET;
usart_interrupt_disable(USART0, USART_INT_RBNE);
}
}
}