STM32f103 双串口配置和中断

这篇博客介绍了如何在STM32F103上配置两个串口并启用中断处理。内容涵盖了使用IAR 7.1编译器和stm32_uart.h头文件进行串口初始化及中断函数设置的基础步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//代码仅仅是配置使能串口和相应的中断处理函数,具体功能需要自己定义 

//IAR 7.1

#include "stm32_uart.h"

uint8_t card_ture=0;
uint16_t add_count=0;
uint8_t Key_Data[1]={0};
uint8_t Media_Flag=0;

uint8_t card_code[4];  //[5:1]save the card SN, [0]valid or invalid
uint8_t Temp_Card_Num[4];
uint8_t cardcode_rx_complete = 0;

uint32_t uart_config_record_map[4] = {
    0,
    UART_CONFIG_UART_MEMORY_ADDR,
    FIRMWARE_VERSION_MEMORY_ADDR,
    SCHEME_SPECIFIC_MEMORY_ADDR
};

UartConfig_TypeDef the_uart_config;

void stm32_uart_init(uint8_t uart_port, uint32_t BaudRate)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    USART_InitTypeDef USART_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;

    /*Fill the structure of uart init*/
    if(uart_port == UART2)
    {
        /*Fill the structure of uart init*/
        USART_InitStructure.USART_BaudRate = BaudRate;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b; 
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No;   
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        /*Enable priph clock*/
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
        
        
        /*Config gpio as uart pin */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;    
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
        
        /*Config gpio as uart pin */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值