cancel
Showing results for 
Search instead for 
Did you mean: 

DCMI DR (data register) problem

hitsumen
Associate II
Posted on July 08, 2013 at 07:49

Good day,

I have some problems with uint32_t DCMI_ReadData(void); function.

I always have 0 data from that DCMI->DR register.

I use STM32F4DISCOVERY board, (stm32f407vgt6 MCU).

My interupt handler:

void DCMI_IRQHandler(void)

{

    if(DCMI_GetFlagStatus(DCMI_FLAG_VSYNCRI) == SET)

    {

        if(vsync == 0)

        {

            vsync = 1;

        }

        else

        {

            vsync = 0;

        }

    }

    else if(DCMI_GetFlagStatus(DCMI_FLAG_LINERI) == SET)

    {

        if(vsync == 1)

        {

            href++;

        }

        else

        {

            href = 0;

        }

    }

    else if(DCMI_GetFlagStatus(DCMI_FLAG_FRAMERI) == SET)

    {

        err = 1;

    }

    else if(DCMI_GetFlagStatus(DCMI_FLAG_ERRRI) == SET)

    {

        err = 2;

    }

    else if(DCMI_GetFlagStatus(DCMI_FLAG_OVFRI) == SET)

    {

        err = 3;

    }

 

 

    DCMI_ClearFlag(DCMI_FLAG_VSYNCRI);

    DCMI_ClearFlag(DCMI_FLAG_LINERI);

    DCMI_ClearFlag(DCMI_FLAG_FRAMERI);

    DCMI_ClearFlag(DCMI_FLAG_ERRRI);

    DCMI_ClearFlag(DCMI_FLAG_OVFRI);

 

}

My DCMI config:

void DCMI_Config(void)

{

  DCMI_InitTypeDef DCMI_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

//DMA_InitTypeDef  DMA_InitStructure;

  /* Enable DCMI GPIOs clocks */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOE | 

                         RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE); 

  /* Enable DCMI clock */

  RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);

  /* Connect DCMI pins to AF13 ************************************************/

  /* PCLK */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);

  /* D0-D7 */

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource0, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource1, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource4, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_DCMI);

  GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_DCMI);

  /* VSYNC */

  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);

  /* HSYNC */

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI);

  

  /* DCMI GPIO configuration **************************************************/

  /* D0 D1(PC6/7) */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;  

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* D2..D4(PE0/1/4) D6/D7(PE5/6) */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 

                              | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;

  GPIO_Init(GPIOE, &GPIO_InitStructure);

  /* D5(PB6), VSYNC(PB7) */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* PCLK(PA6) HSYNC(PA4)*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

  

  DCMI_DeInit();

DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;

DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;

DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b;

DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low;

DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;

DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;

DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;

DCMI_Init(&DCMI_InitStructure);

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  

  NVIC_Init(&NVIC_InitStructure); 

//----- mask interrupt for DCMI -----

  DCMI_ITConfig(DCMI_IT_VSYNC, ENABLE);

  DCMI_ITConfig(DCMI_IT_LINE, ENABLE);

  DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);

  DCMI_ITConfig(DCMI_IT_OVF, ENABLE);

  DCMI_ITConfig(DCMI_IT_ERR, ENABLE);

// Enable DCMI Capture mode

DCMI_Cmd(ENABLE);

DCMI_CaptureCmd(ENABLE);

}

while(1)

{

if(vsync&&href){

sprintf(to_uart, ''\n%d %d %d'', vsync, href, DCMI_ReadData());

sendstring(to_uart);

}

}

and the output (looks like vsync, href and pclk are working correctly, I actually can calculate the pclk in href, its 320):

...

1 201 0

1 203 0

1 205 0

1 206 0

1 208 0

1 210 0

1 212 0

1 214 0

1 216 0

1 218 0

1 220 0

1 222 0

1 224 0

1 226 0

1 228 0

1 230 0

1 232 0

1 234 0

1 236 0

1 238 0

1 240 0

1 240 0

1 1 0

1 2 0

1 3 0

1 5 0

....

Can somebody explain how to read the data from DCMI->DR register??
1 REPLY 1
hitsumen
Associate II
Posted on July 08, 2013 at 10:50

Problem was with the polarity of vsync signal..