一般程序逻辑

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)
