Skip to main content
Associate III
October 25, 2023
Solved

STM32 OV2640 DCMI

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 */

}

This topic has been closed for replies.
Johi
JohiBest answer
Senior II
October 28, 2023

You start DMA, but then you need to wait until is completed before starting send via UART.

Try to send "hello world" first via serial, and then go further to the more difficult stuff.

And indeed check serial settings, especially the number of parity bits because cube includes parity bits in the total bit count, so you might need to select 9 bits and not 8 to obtain 8 databits.

11 replies

KDJEM.1
ST Technical Moderator
October 25, 2023

Hello @koksoybedirhan ,

Which STM32 device are you using?

Could you please check the Baud Rate?

If you're just sending data over UART, you aren't going to see anything useful in the terminal. You would need to save that info and process it back into an image.

Do you have any issue after converting data to the image?

Thank you.

Kaouthar

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.
Associate III
October 28, 2023

Hi @KDJEM.1 ,

Firstly thank you to reply my question.

I am using STM32H745 Nucleo Board and it has STM32H745ZIT6 microprocessor.
I tried 115200 and 9600 baud rate but I got same result for both of them.
For the sending data, I just saving DCMI datas to DMA and after I send datas to computer via HAL_UART_Transmit_DMA. I don't converting before sending data and I think that's what you say for the mistake. 

Could you share links about converting DCMI data to image data in STM32?

 

Best Regards.

Johi
JohiBest answer
Senior II
October 28, 2023

You start DMA, but then you need to wait until is completed before starting send via UART.

Try to send "hello world" first via serial, and then go further to the more difficult stuff.

And indeed check serial settings, especially the number of parity bits because cube includes parity bits in the total bit count, so you might need to select 9 bits and not 8 to obtain 8 databits.

Associate III
October 28, 2023

Hi @Johi ,

Thank you for your advice. I think firstly I have to learn more about DMA usage as you said. Also I'll try 9 bits for serial settings.

Best Regards.

Associate II
August 6, 2024

Hello! Did managed to get the data of photo yet? I'm using the same board to run ov2640 camera but I can't get the data from DMA.I can see there is data in DCMI for I watch the register from CubeProgrammer.It seems that my DMA didn't work. Would you like to share your code with me? It could saved me from a very hard situation and thank you very very much. My e-mail: syxcontactme@gmail.com  Also my bad code below.