cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 OV2640 DCMI

koksoybedirhan
Associate III

Hi,

I would like to ask a question about STM32 OV2640 usage. My task is; take an output data from OV2640 and send to Computer via USART. When I communicate with UART, I took an output which shown in the figure. I did not is it true or wrong output but after output I'll try to convert data to image with python matplotlib library. 

image.png

/* USER CODE BEGIN Header */

/**

******************************************************************************

* @file : main.c

* @brief : Main program body

******************************************************************************

* @attention

*

* Copyright (c) 2023 STMicroelectronics.

* All rights reserved.

*

* This software is licensed under terms that can be found in the LICENSE file

* in the root directory of this software component.

* If no LICENSE file comes with this software, it is provided AS-IS.

*

******************************************************************************

*/

/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/

#include "main.h"

 

/* Private includes ----------------------------------------------------------*/

/* USER CODE BEGIN Includes */

#include "ov2640.h"

/* USER CODE END Includes */

 

/* Private typedef -----------------------------------------------------------*/

/* USER CODE BEGIN PTD */

 

/* USER CODE END PTD */

 

/* Private define ------------------------------------------------------------*/

/* USER CODE BEGIN PD */

 

#ifndef HSEM_ID_0

#define HSEM_ID_0 (0U) /* HW semaphore 0*/

#endif

 

/* USER CODE END PD */

 

/* Private macro -------------------------------------------------------------*/

/* USER CODE BEGIN PM */

 

/* USER CODE END PM */

 

/* Private variables ---------------------------------------------------------*/

 

DCMI_HandleTypeDef hdcmi;

DMA_HandleTypeDef hdma_dcmi;

 

I2C_HandleTypeDef hi2c1;

 

UART_HandleTypeDef huart3;

DMA_HandleTypeDef hdma_usart3_tx;

 

SRAM_HandleTypeDef hsram1;

 

/* USER CODE BEGIN PV */

 

/* USER CODE END PV */

 

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_DMA_Init(void);

static void MX_FMC_Init(void);

static void MX_DCMI_Init(void);

static void MX_I2C1_Init(void);

static void MX_USART3_UART_Init(void);

/* USER CODE BEGIN PFP */

 

/* USER CODE END PFP */

 

/* Private user code ---------------------------------------------------------*/

/* USER CODE BEGIN 0 */

uint16_t* camData;

double camBuf = 320*240*3;

/* USER CODE END 0 */

 

/**

* @brief The application entry point.

* @retval int

*/

int main(void)

{

/* USER CODE BEGIN 1 */

 

/* USER CODE END 1 */

/* USER CODE BEGIN Boot_Mode_Sequence_0 */

int32_t timeout;

/* USER CODE END Boot_Mode_Sequence_0 */

 

/* USER CODE BEGIN Boot_Mode_Sequence_1 */

/* Wait until CPU2 boots and enters in stop mode or timeout*/

timeout = 0xFFFF;

while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));

if ( timeout < 0 )

{

Error_Handler();

}

/* USER CODE END Boot_Mode_Sequence_1 */

/* MCU Configuration--------------------------------------------------------*/

 

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */

HAL_Init();

 

/* USER CODE BEGIN Init */

 

/* USER CODE END Init */

 

/* Configure the system clock */

SystemClock_Config();

/* USER CODE BEGIN Boot_Mode_Sequence_2 */

/* When system initialization is finished, Cortex-M7 will release Cortex-M4 by means of

HSEM notification */

/*HW semaphore Clock enable*/

__HAL_RCC_HSEM_CLK_ENABLE();

/*Take HSEM */

HAL_HSEM_FastTake(HSEM_ID_0);

/*Release HSEM in order to notify the CPU2(CM4)*/

HAL_HSEM_Release(HSEM_ID_0,0);

/* wait until CPU2 wakes up from stop mode */

timeout = 0xFFFF;

while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) == RESET) && (timeout-- > 0));

if ( timeout < 0 )

{

Error_Handler();

}

/* USER CODE END Boot_Mode_Sequence_2 */

 

/* USER CODE BEGIN SysInit */

 

/* USER CODE END SysInit */

 

/* Initialize all configured peripherals */

MX_GPIO_Init();

MX_DMA_Init();

MX_FMC_Init();

MX_DCMI_Init();

MX_I2C1_Init();

MX_USART3_UART_Init();

/* USER CODE BEGIN 2 */

ov2640_Init(0x60, CAMERA_Monitor);

uint16_t* p_lcdData;

 

HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS, p_lcdData, camBuf);

HAL_UART_Transmit_DMA(&huart3, p_lcdData, camBuf);

 

/* USER CODE END 2 */

 

/* Infinite loop */

/* USER CODE BEGIN WHILE */

while (1)

{

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

 

}

/* USER CODE END 3 */

}

10 REPLIES 10

Also for this example, I used this code: https://www.youtube.com/watch?v=auUfHaCEUIE