STM32程序逻辑---入口函数逻辑和NVIC嵌套向量中断控制器初始化

一般程序逻辑

cpp 复制代码
//这是C语言代码

#include "stm32f10x.h"
#include "delay.h"
#include "usart.h"
#include "MLX90640_API.h"
#include "MLX90640_I2C_Driver.h"
#include <stdio.h>

#define MLX90640_ADDR 0x33  
#define  FPS2HZ   0x02
#define  FPS4HZ   0x03
#define  FPS8HZ   0x04
#define  FPS16HZ  0x05
#define  FPS32HZ  0x06

paramsMLX90640 mlx90640;
float mlx90640To[768];     
uint16_t eeData[832];      
uint16_t frameData[834];   


int main(void)
{
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    delay_init();
    uart_init(115200);

    MLX90640_I2CInit();
    MLX90640_SetRefreshRate(MLX90640_ADDR, FPS8HZ);		
    MLX90640_SetChessMode(MLX90640_ADDR);	
	MLX90640_DumpEE(MLX90640_ADDR, eeData);						
	MLX90640_ExtractParameters(eeData, &mlx90640);		

    while (1)
    {
				for (unsigned char  page = 0 ;page < 2;page++)
				{
						int status = MLX90640_GetFrameData(MLX90640_ADDR, frameData);
						float Ta = MLX90640_GetTa(frameData, &mlx90640); 
						float tr = Ta - 8;
						MLX90640_CalculateTo_float(frameData, &mlx90640, 0.95, tr, mlx90640To);
				}
        for (int row = 0; row < 24; row++)
        {
            for (int col = 0; col < 32; col++)
            {
                printf("%6.2f ", mlx90640To[row * 32 + col]);
            }
            printf("\r\n");
        }
        printf("\r\n");

        delay_ms(100); 
    }
}

初始化中先配置NVIC中断控制器

cpp 复制代码
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
{
  /* Check the parameters */
  assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
  
  /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
}
cpp 复制代码
typedef struct
{
  uint8_t NVIC_IRQChannel;                    /*!< Specifies the IRQ channel to be enabled or disabled.
                                                   This parameter can be a value of @ref IRQn_Type 
                                                   (For the complete STM32 Devices IRQ Channels list, please
                                                    refer to stm32f10x.h file) */

  uint8_t NVIC_IRQChannelPreemptionPriority;  /*!< Specifies the pre-emption priority for the IRQ channel
                                                   specified in NVIC_IRQChannel. This parameter can be a value
                                                   between 0 and 15 as described in the table @ref NVIC_Priority_Table */

  uint8_t NVIC_IRQChannelSubPriority;         /*!< Specifies the subpriority level for the IRQ channel specified
                                                   in NVIC_IRQChannel. This parameter can be a value
                                                   between 0 and 15 as described in the table @ref NVIC_Priority_Table */

  FunctionalState NVIC_IRQChannelCmd;         /*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
                                                   will be enabled or disabled. 
                                                   This parameter can be set either to ENABLE or DISABLE */   
} NVIC_InitTypeDef;
cpp 复制代码
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
cpp 复制代码
/** @defgroup Preemption_Priority_Group 
  * @{
  */

#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))

#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY)  ((PRIORITY) < 0x10)

#define IS_NVIC_SUB_PRIORITY(PRIORITY)  ((PRIORITY) < 0x10)

#define IS_NVIC_OFFSET(OFFSET)  ((OFFSET) < 0x000FFFFF)
相关推荐
Jason_zhao_MR3 分钟前
米尔MYD-JR3576开发板 Android 15系统正式发布
android·linux·嵌入式硬件·嵌入式
jianqiang.xue1 小时前
多Agent同时改一套STM32固件,两版补丁冲突时该听谁的
stm32·单片机·嵌入式硬件
肖工AVRCR1 小时前
STM32性能优化
stm32·单片机·嵌入式硬件
小李不想当小白1 小时前
HAL库之定时器输入捕获(STM32 HAL库学习笔记)
笔记·stm32·单片机·嵌入式硬件·学习·嵌入式
3jjjjjjj2 小时前
多种stm32的烧录方法
stm32·单片机·嵌入式硬件
bbxyliyang2 小时前
基于ATmega16单片机四路电压监测系统设计
单片机·嵌入式硬件
NendoZen2 小时前
TinyGo安装与开发,实现统一的嵌入式开发环境(树莓派pico开发,esp32开发)
嵌入式硬件·go
jianqiang.xue3 小时前
MCU的AI开发工具怎么选:MCP、Agent Skills和专用Agent三种
人工智能·单片机·嵌入式硬件
白小飞不会飞3 小时前
【AUTOSAR】 E2E Transformer:把 E2E 库接到 RTE 上
c++·嵌入式硬件·车载系统·transformer·autosar
橘为己有4413 小时前
STM32:PWM呼吸灯实
stm32·单片机·嵌入式硬件