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)
相关推荐
【 STM32开发 】26 分钟前
CubeMX+STM32】SD卡U盘实现__USB+FATFS (F103 篇)
stm32·单片机·嵌入式硬件
jianqiang.xue1 小时前
3倍向量算力:Arm给最小MCU装上本地AI
arm开发·人工智能·单片机
蜀黍@猿2 小时前
ARM 汇编入门(十二):MMU、页表与虚拟内存全解析
汇编·arm开发·stm32·mcu
无敌最俊朗-15 小时前
【电感专题2:电感的感抗、电路的阻抗、电流的滞后】
单片机·嵌入式硬件·元器件·电感
wuyk55519 小时前
嵌入式故障诊断-Bug002-局部大数组压栈高温必死机
stm32·单片机·嵌入式硬件·mcu·物联网·51单片机·嵌入式实时数据库
Zwawa1 天前
嵌入式OLED表驱动菜单:用一张表、一个栈和一个窗口重写表驱动菜单
c语言·单片机·嵌入式
Dev_XH1 天前
【成品设计】基于沁恒单片机的电动汽车充电站智慧调度系统
stm32·单片机·嵌入式硬件·物联网
shimly1234561 天前
(done) 嵌入式硬件电路图 (5) 重要的元器件特性之二极管三极管
嵌入式硬件
Zw-awa1 天前
嵌入式OLED表驱动菜单:用一张表、一个栈和一个窗口重写表驱动菜单
stm32