We are interfacing FLIR lepton 3.5 thermal camera with STM32f407VET6 to capture thermal image.
In our system, the AGC is disabled by default, we enabled VSYNC using I2C protocol.
Currently the code is reading packet number and printing it on console, our output is in attached image.
The packet number output should be between 1, 2, 3,......60 but it is coming like in image.
Help us to solve this problem.
#include "main.h" #include "stdio.h" #include "string.h" #include "stdlib.h" #include "stdbool.h" #include "LeptonFLiR.h" #include "i2c.h" #include "spi.h" #include "usart.h" #include "gpio.h" #define LEPTON_RESET_L_HIGH HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_SET) #define LEPTON_RESET_L_LOW HAL_GPIO_WritePin(GPIOC, GPIO_PIN_4, GPIO_PIN_RESET) #define LEPTON_PW_DWN_HIGH HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_SET) #define LEPTON_PW_DWN_LOW HAL_GPIO_WritePin(GPIOC, GPIO_PIN_5, GPIO_PIN_RESET) #define LEPTON_CS_HIGH HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET) #define LEPTON_CS_LOW HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET) #define PACKET_SIZE 164 LeptonFLiR flirController; uint8_t lepton_frame_packet[PACKET_SIZE]; int lost_frame_counter = 0; int frame_complete = 0; int need_resync = 0; void SystemClock_Config(void); void lepton_init(void ) { LEPTON_PW_DWN_LOW; LEPTON_RESET_L_LOW; HAL_Delay(190); LEPTON_PW_DWN_HIGH; HAL_Delay(190); LEPTON_RESET_L_HIGH; HAL_Delay(5000); flirController.printModuleInfo(); LEP_RAD_ENABLE_E_TAG mode= flirController.rad_getRadiometryControlEnable(); char msg[10]; int msg_len= sprintf(msg,"\n\r %i ",mode); HAL_UART_Transmit(&huart4, (uint8_t *)msg, msg_len, 5000); flirController.oem_setGPIO_mode(LEP_OEM_GPIO_MODE_VSYNC); flirController.oem_getGPIO_mode(); LEP_SYS_CAM_STATUS_STATES camStatus = flirController.sys_getCameraStatus(); msg_len= sprintf(msg,"\n\r %i ",camStatus); HAL_UART_Transmit(&huart4, (uint8_t *)msg, msg_len, 5000); flirController.readInitData(); HAL_Delay(5000); } void FLIR_ReadFramePacket(void) { while(1){ LEPTON_CS_LOW; HAL_SPI_Receive(&hspi1, lepton_frame_packet, PACKET_SIZE, HAL_MAX_DELAY); if(((lepton_frame_packet[0]&0xF) == 0x0F)) { lost_frame_counter++; }else{ uint8_t packet_number= lepton_frame_packet[1]; char msg[10]; int msg_len= sprintf(msg,"%d ",packet_number); HAL_UART_Transmit(&huart4, (uint8_t *)msg, msg_len, 5000); } if(lost_frame_counter>1000) { need_resync = 1; lost_frame_counter = 0; } if(need_resync) { char msg[10]; int msg_len= sprintf(msg,"%d ",58); HAL_UART_Transmit(&huart4, (uint8_t *)msg, msg_len, 5000); HAL_Delay(185); need_resync = 0; } LEPTON_CS_HIGH; } } int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_UART4_Init(); MX_SPI1_Init(); MX_I2C1_Init(); lepton_init(); while(1){ // lepton_getFrameAsync(); int vsyn = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_0); if(vsyn==1){ FLIR_ReadFramePacket(); } } } void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; __HAL_RCC_PWR_CLK_ENABLE(); __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { Error_Handler(); } } void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { char msg[10]; int msg_len= sprintf(msg,"%i ",7); HAL_UART_Transmit(&huart4, (uint8_t *)msg, msg_len, 5000); HAL_Delay(5000); } /* USER CODE END Error_Handler_Debug */ }