2025-01-20 01:00 AM - edited 2025-01-20 02:03 AM
Hi,
I would like to ask a question about DCMI. I am working on one task with STM32H743VIT6 MCU. My task is take an image from MT9M114 sensor using DCMI.
MT9M114 is a camera sensor to capture images. Interfacing MT9M114 sensor through DCMI with STM32H743VIT6.
I Configured camera sensor through I2C like (Pixel format, Resolution) by referring the below data sheet.
MT9M114 - 1/6‐inch 720p High‐Definition (HD) System‐On‐a‐Chip (SOC) Digital Image Sensor.
At now i configured sensor with below settings,
Pixel format as "RGB565" and Resolution as " 320*240 "
And initialized DCMI and DMA and UART configurations like below,
DCMI_HandleTypeDef hdcmi;
DMA_HandleTypeDef hdma_dcmi;
I2C_HandleTypeDef hi2c1;
UART_HandleTypeDef huart3;
DMA_HandleTypeDef hdma_usart3_tx;
static void MX_DCMI_Init(void)
{
/* USER CODE BEGIN DCMI_Init 0 */
/* USER CODE END DCMI_Init 0 */
/* USER CODE BEGIN DCMI_Init 1 */
/* USER CODE END DCMI_Init 1 */
hdcmi.Instance = DCMI;
hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN DCMI_Init 2 */
/* USER CODE END DCMI_Init 2 */
}
static void MX_DMA_Init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA2_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Stream1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn);
/* DMA2_Stream1_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Stream1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
}
static void MX_USART3_UART_Init(void)
{
/* USER CODE BEGIN USART3_Init 0 */
/* USER CODE END USART3_Init 0 */
/* USER CODE BEGIN USART3_Init 1 */
/* USER CODE END USART3_Init 1 */
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1;
huart3.Init.Parity = UART_PARITY_NONE;
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart3) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USART3_Init 2 */
/* USER CODE END USART3_Init 2 */
}
Now i am trying to print some patterns which are sensor supported like below image.
I configured FLAT field pattern(register values) through I2C in specific register. And reading again through I2C from pattern register, got same value which i configured. So which means pattern is configured properly.
Taking DCMI data like below and passing through UART,
#define IMAGE_BUFFER_SIZE (320*240)
uint8_t frame_buffer[IMAGE_BUFFER_SIZE] = "";
HAL_StatusTypeDef mt9m114_stopCap(){
HAL_DCMI_Stop(&hdcmi);
return HAL_OK;
}
HAL_StatusTypeDef mt9m114_startCap()
{
mt9m114_stopCap();
HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)frame_buffer, 320*240);
HAL_UART_Transmit_DMA(&huart3, frame_buffer, sizeof(frame_buffer));
memset(frame_buffer,sizeof(frame_buffer),0);
return HAL_OK;
}
At present i'm getting DCMI Data like below image. This below image is screen shot of DCMI data in putty terminal.
By using this RGB to Image converter "" https://codestation.ch/ "" result as like below. I'm unable to get Exact pattern which i expected.
Can anyone help on this issue , if i made anything wrong on DCMI part.
Thanks in advance.
2025-01-21 06:40 AM
Hello @Naveen_N and welcome to the Community,
Is the cache enabled? If yes try to disabled.
Try to send for "hello world" first via serial before sending the image.
I recommend you to look to this post and to AN5020 precisely section 8 DCMI application examples may help you.
Thank you.
Kaouthar
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-01-21 07:09 AM
How on earth is this going to work? You've got no synchronization, the DMA functions return immediately, and then you clear the buffer. Not to mention the DCMI is continuous, and there's a huge disparity in the input vs output rates.
HAL_StatusTypeDef mt9m114_startCap()
{
mt9m114_stopCap();
HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)frame_buffer, 320*240);
HAL_UART_Transmit_DMA(&huart3, frame_buffer, sizeof(frame_buffer));
memset(frame_buffer,sizeof(frame_buffer),0);
return HAL_OK;
}