//函数功能:初始化USART0
void USART0_Init(unsigned int bound)
{
//NVIC_PRIGROUP_PRE4_SUB0:抢占优先级为4bit(取值为0~15),子优先级为0bit(没有响应优先级)
//NVIC_PRIGROUP_PRE3_SUB1:抢占优先级为3bit(取值为0~7),子优先级为1bit(取值为0~1)
//NVIC_PRIGROUP_PRE2_SUB2:抢占优先级为2bit(取值为0~3),子优先级为2bit(取值为0~3)
//NVIC_PRIGROUP_PRE1_SUB3:抢占优先级为1bit(取值为0~1),子优先级为3bit(取值为0~7)
//NVIC_PRIGROUP_PRE0_SUB4:抢占优先级为0bit(没有抢占优先级),子优先级为3bit(取值为0~15)
//nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);//设置系统中断优先级"抢占优先级为4bit,子优先级为0bit"
nvic_irq_enable(USART0_IRQn, 0, 0);
//设置USART0_IRQn的中断优先级,抢占优先级为0,子优先级为0,USART interrupt configuration
串口初始化开始/
rcu_periph_clock_enable(RCU_GPIOA); //使能GPIOA时钟,enable GPIO clock
rcu_periph_clock_enable(RCU_USART0); //使能USART时钟,enable USART clock
gpio_init(GPIOA, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_9);
//将GPIOA9设置为AFIO口(复用IO口),输出上拉
gpio_init(GPIOA, GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, GPIO_PIN_10);
//将GPIOA10设置为浮空输入口
usart_deinit(USART0); //复位USART0,USART configure
usart_baudrate_set(USART0,bound); //设置USART0的波特率
usart_word_length_set(USART0,USART_WL_8BIT); //设置USART0数据传输格式为8位
usart_stop_bit_set(USART0,USART_STB_1BIT); //设置USART0停止位为1位
usart_parity_config(USART0,USART_PM_NONE); //设置USART0无需奇偶校验
usart_hardware_flow_rts_config(USART0,USART_RTS_DISABLE); //设置不使能USART0的RTS引脚功能
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE); //设置不使能USART0的CTS引脚功能
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
//根据USART_RECEIVE_ENABLE,设置串口控制寄存器USART_CTL0的串口接收使能
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
//根据USART_TRANSMIT_ENABLE,设置串口控制寄存器USART_CTL0的串口发送使能
usart_enable(USART0);//使能串口模块
串口初始化结束/ |