AnsweredAssumed Answered

OV7670 and DCMI problem

Question asked by t.muhammad on Jul 27, 2014
Latest reply on Jul 2, 2015 by tag.aseok
I have been trying to get the OV7670 cam working with STM32F207zg but seems like something is not clear , first i need to know what is the buffer size to set the DMA to when i want to transfer a snapshot from the cam to External SRAM (since i can not directly send it to the LCD) , say i want 240 * 320 pixels  (RGB565) , and the external RAM is 16-bit wide , so what should be the buffer size for the DMA ? ........
also im not sure if the documentation is clear about the VSYNC and HSYNC , the camera module has the VSYNC active high (i,e Data r not sampled when its high) and HSYNC active low , so what should the DCMI settings for VSYNC and HSYNC ?
with the following code , i get DMA FIFO ERROR , and I get the frame flag set , but when i display the frame (even if not complete) , the LCD shows noise
    DMA_InitTypeDef DMA_DCMI;
    // Configure the DCMI
    // Enable the Clck of the DCMI module
    RCC_AHB2PeriphClockCmd (RCC_AHB2Periph_DCMI , ENABLE);
    // Reset the DCMI Registers
RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_DCMI, ENABLE);
   RCC_AHB2PeriphResetCmd(RCC_AHB2Periph_DCMI, DISABLE);
    //
    // Configure the DCMI
    DCMI_Struct.DCMI_CaptureMode=DCMI_CaptureMode_SnapShot;
    DCMI_Struct.DCMI_CaptureRate=DCMI_CaptureRate_All_Frame;
    DCMI_Struct.DCMI_ExtendedDataMode=DCMI_ExtendedDataMode_8b;
    DCMI_Struct.DCMI_HSPolarity=DCMI_HSPolarity_Low;
    DCMI_Struct.DCMI_PCKPolarity=DCMI_PCKPolarity_Rising;
    DCMI_Struct.DCMI_VSPolarity=DCMI_VSPolarity_High;
    DCMI_Struct.DCMI_SynchroMode=DCMI_SynchroMode_Hardware;
    DCMI_Init(&DCMI_Struct);
    //
    // Enable the NVIC for the DCMI
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
    NVIC_DCMI.NVIC_IRQChannel=DCMI_IRQn;
    NVIC_DCMI.NVIC_IRQChannelCmd=ENABLE;
    NVIC_DCMI.NVIC_IRQChannelPreemptionPriority=1;
    NVIC_DCMI.NVIC_IRQChannelSubPriority=2;
    NVIC_Init(&NVIC_DCMI);
    //
    //
    NVIC_DCMI.NVIC_IRQChannel=DMA2_Stream1_IRQn;
    NVIC_DCMI.NVIC_IRQChannelCmd=ENABLE;
    NVIC_DCMI.NVIC_IRQChannelPreemptionPriority=1;
    NVIC_DCMI.NVIC_IRQChannelSubPriority=1;
    NVIC_Init(&NVIC_DCMI);
    
    //
    // Enable the DCMI Interrupts
    DCMI_ITConfig(DCMI_IT_VSYNC, ENABLE);
 DCMI_ITConfig(DCMI_IT_LINE, ENABLE);
  DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);
//  DCMI_ITConfig(DCMI_IT_ERR, ENABLE);    //
//    //
    // Enable DMA2 Clock
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);  
    // Configure the DMA
     DMA_DCMI.DMA_Channel = DMA_Channel_1;  
  DMA_DCMI.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;    
  DMA_DCMI.DMA_Memory0BaseAddr = 0x64000000;
  DMA_DCMI.DMA_DIR = DMA_DIR_PeripheralToMemory;
  DMA_DCMI.DMA_BufferSize = 320*240*2;
  DMA_DCMI.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
  DMA_DCMI.DMA_MemoryInc = DMA_MemoryInc_Enable;
  DMA_DCMI.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
  DMA_DCMI.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
  DMA_DCMI.DMA_Mode = DMA_Mode_Normal;
  DMA_DCMI.DMA_Priority = DMA_Priority_High;
  DMA_DCMI.DMA_FIFOMode = DMA_FIFOMode_Enable;         
  DMA_DCMI.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
  DMA_DCMI.DMA_MemoryBurst = DMA_MemoryBurst_Single;
  DMA_DCMI.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
    DMA_Init(DMA2_Stream1, &DMA_DCMI);
    DMA_ITConfig(DMA2_Stream1 , DMA_IT_TC , ENABLE);
    DMA_ITConfig(DMA2_Stream1 , DMA_IT_FE  , ENABLE);

// Enable the Capture mode
      DMA_Cmd(DMA2_Stream1, ENABLE);
    /* Enable DCMI interface */
    DCMI_Cmd(ENABLE);
    /* Start Image capture */
    DCMI_CaptureCmd(ENABLE);
    //
//
//
.
.
.

void DCMI_IRQHandler()
{
    
if (DCMI_GetITStatus(DCMI_IT_VSYNC) != RESET)
    {                    
        DCMI_ClearITPendingBit(DCMI_IT_VSYNC);
    }
    
    if (DCMI_GetITStatus(DCMI_IT_LINE) != RESET)
    {
        DCMI_ClearITPendingBit(DCMI_IT_LINE);      
    }
    
    if (DCMI_GetITStatus(DCMI_IT_FRAME) != RESET)
    {
        DCMI_ClearITPendingBit(DCMI_IT_FRAME);
        for(count=0; count<76800 ; count++)
        {
        LCD_REG=0x22;
        LCD_RAM=BUFF[count];
        }
    }
    if (DCMI_GetITStatus(DCMI_IT_ERR) != RESET)
    {
        DCMI_ClearITPendingBit(DCMI_IT_ERR);
    }

}
..
..
Any ideas? ...... Is it cam settings , is it the DCMI ? >>>>>> thx in advance .

Outcomes