1、开启时钟
2、配置GOIO口
3、配置串口初始化
4、开启串口中断
5、编写串口发送函数与中断接收函数
1、开启时钟
void rcc_periph_clock_enable(void)
{
//启动GPIOA时钟
rcu_periph_clock_enable(RCU_GPIOA);
//开启串口时钟
rcu_periph_clock_enable(RCU_USART0);
}
2、配置GOIO口
void GPIO_MOde_init(void)
{
//设置引脚复用1(USART)
gpio_af_set(GPIOA,GPIO_AF_1,GPIO_PIN_9);
gpio_af_set(GPIOA,GPIO_AF_1, GPIO_PIN_10);
//设置引脚输出
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_9);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_9);
gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP, GPIO_PIN_10);
gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, GPIO_PIN_10);
}
3、配置串口初始化
void com_usart_init(void)
{
//设置缺省值
usart_deinit(USART0);
//配置串口波特率
usart_baudrate_set(USART0,65536U);//波特率115200
//配置数据位
usart_word_length_set(USART0, USART_WL_8BIT);//8个数据位
//配置停止位
usart_stop_bit_set(USART0, USART_STB_1BIT); //1个停止位
//配置奇偶校验位
usart_parity_config(USART0, USART_PM_NONE);//无奇偶校验
//RTS流控关闭
usart_hardware_flow_rts_config(USART0, USART_RTS_DISABLE);
//CTS流控关闭
usart_hardware_flow_cts_config(USART0, USART_CTS_DISABLE);
//配置串口接收使能
usart_receive_config(USART0, USART_RECEIVE_ENABLE);
//配置串口发送使能
usart_transmit_config(USART0, USART_TRANSMIT_ENABLE);
//初始化串口配置
usart_enable(USART0);
}
## 4、开启串口中断
void usart_IRQn_init(void)
{
//使能中断
usart_interrupt_enable(USART0,USART_INT_RBNE);
//使能中断优先级
nvic_irq_enable(USART0_IRQn, 0U);
}
5、编写串口发送函数与中断接收函数
/*!
\brief 串口发送字节函数
\param[in] none
\param[out] none
\retval none
*/
void USART0_Send_Byte(uint8_t Send_Byte)
{
usart_data_transmit(USART0, Send_Byte);
while ( usart_flag_get(USART0, USART_FLAG_TBE)== RESET) ;
}
/*!
\brief 串口发送字符串函数
\param[in] none
\param[out] none
\retval none
*/
void USART0_Send_Str(uint8_t *Str)
{
while((*Str)!='\0')
{
USART0_Send_Byte(*Str);
Str++;
}
}
/*!
\brief 重定向c库函数printf到串口,重定向后可使用printf函数
\param[in] none
\param[out] none
\retval none
*/
int fputc(int ch, FILE *f)
{
/* 发送一个字节数据到串口 */
USART0_Send_Byte((uint8_t) ch);
return (ch);
}
uint8_t receiver_buffer[10];
void EXTI0_1_IRQHandler(void)
{
if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE)){
/* receive data */
receiver_buffer[0] = usart_data_receive(USART0);
//判断数据内容,进行逻辑处理
if(receiver_buffer[0] == 0x1A)
{
}
}
}
After looking at a handful of the articles on your
site, I really like your way of blogging.
I book-marked it to my bookmark website list and will be checking back soon. Take a look at my web
site too and tell me your opinion.
I’m really inspired along with your writing skills and
also with the structure to your blog. Is that this
a paid subject or did you modify it your self? Anyway keep up the nice quality writing, it is uncommon to peer a nice blog like
this one nowadays..
I’ve read some just right stuff here. Definitely worth bookmarkiing for revisiting.
I surprise how so much effort you set to create one of these magnificent informative
site.
Have a look at my blog post – taipan77-slot, ultfoms.ru,
Dear immortals, I need some wow gold inspiration to create.
Agora que muitas pessoas estão usando smartphones, podemos considerar o posicionamento do telefone móvel por meio de redes sem fio ou estações base. https://www.xtmove.com/pt/how-to-track-location-of-someone-phone-without-their-knowledge/
87045 339057Wonderful post, Im seeking forward to hear far more from you!! 974958
23691 212176Paper rolls really fantastic read you know alot about this subject i see! 53203
Vous pouvez également personnaliser la surveillance de certaines applications, et il commencera immédiatement à capturer régulièrement des instantanés de l’écran du téléphone.
am siteleri tthighereduhryyy.RgeBNLQLNFd
You can use parent management software to guide and supervise children’s behavior on the Internet. With the help of the following 10 smartest parent management software, you can track your child’s call history, browsing history, dangerous content access, apps they install, etc.
748098 702565extremely nice post, i undoubtedly enjoy this fabulous internet site, persist with it 79627
Wow, awesome blog format! How lengthy have you been running a blog for?
you made running a blog look easy. The whole look of
your website is wonderful, let alone the content!
You can see similar here e-commerce
Wow, superb weblog structure! How long have you ever been blogging
for? you made running a blog look easy. The entire look of your
site is fantastic, as neatly as the content material!
You can see similar here najlepszy sklep