优先级笔记
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
{
assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
}
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置优先级分组
//输入参数范围
#define NVIC_PriorityGroup_0 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority
4 bits for subpriority /
#define NVIC_PriorityGroup_1 ((uint32_t)0x600) /!< 1 bits for pre-emption priority
3 bits for subpriority /
#define NVIC_PriorityGroup_2 ((uint32_t)0x500) /!< 2 bits for pre-emption priority
2 bits for subpriority /
#define NVIC_PriorityGroup_3 ((uint32_t)0x400) /!< 3 bits for pre-emption priority
1 bits for subpriority /
#define NVIC_PriorityGroup_4 ((uint32_t)0x300) /!< 4 bits for pre-emption priority
0 bits for subpriority */
#define IS_NVIC_PRIORITY_GROUP(GROUP) (((GROUP) == NVIC_PriorityGroup_0) ||
((GROUP) == NVIC_PriorityGroup_1) ||
((GROUP) == NVIC_PriorityGroup_2) ||
((GROUP) == NVIC_PriorityGroup_3) ||
((GROUP) == NVIC_PriorityGroup_4))
MDK中NVIC寄存器结构体
typedef struct
{
__IO uint32_t ISER[8]; /*!< Offset: 0x000 Interrupt Set Enable Register /
uint32_t RESERVED0[24];
__IO uint32_t ICER[8]; /!< Offset: 0x080 Interrupt Clear Enable Register /
uint32_t RSERVED1[24];
__IO uint32_t ISPR[8]; /!< Offset: 0x100 Interrupt Set Pending Register /
uint32_t RESERVED2[24];
__IO uint32_t ICPR[8]; /!< Offset: 0x180 Interrupt Clear Pending Register /
uint32_t RESERVED3[24];
__IO uint32_t IABR[8]; /!< Offset: 0x200 Interrupt Active bit Register /
uint32_t RESERVED4[56];
__IO uint8_t IP[240]; /!< Offset: 0x300 Interrupt Priority Register (8Bit wide) /
uint32_t RESERVED5[644];
__O uint32_t STIR; /!< Offset: 0xE00 Software Trigger Interrupt Register */
} NVIC_Type;
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct); //设置抢占优先级函数 设置中断使能
typedef struct
{
uint8_t NVIC_IRQChannel; //设置中断通道
uint8_t NVIC_IRQChannelPreemptionPriority;//设置响应优先级
uint8_t NVIC_IRQChannelSubPriority; //设置抢占优先级
FunctionalState NVIC_IRQChannelCmd; //使能/使能
} NVIC_InitTypeDef;
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//串口1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1 ;// 抢占优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;// 子优先级位2 响应优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据上面指定的参数初始化NVIC寄存器
串口笔记
常用的串口相关寄存器
USART_SR 状态寄存器
USART_DR 数据寄存器 (发送,读取数据)
USART_BRR 波特率寄存器
USART_CR 使能寄存器
串口操作相关库函数(省略入口参数):
void USART_Init(); //串口初始化:波特率,数据字长,奇偶校验,硬件流控以及收发使能
void USART_Cmd();//使能串口
void USART_ITConfig();//使能相关中断
void USART_SendData();//发送数据到串口,
DR
uint16_t USART_ReceiveData();//接受数据,从DR读取接受到的数据
FlagStatus USART_GetFlagStatus();//获取状态标志位
void US