Skip to main content
muhammet
Associate II
August 27, 2013
Question

Can you help me about getting good picture in the STM32

  • August 27, 2013
  • 3 replies
  • 704 views
Posted on August 27, 2013 at 11:23

I can get this Picture.But I don't know how I can correct this mistake!

0690X000006050ZQAQ.png

My code:

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

  DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;

  DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;

  DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;

  DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_High;

  DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_High;

  DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame;

  DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_10b;

 

  DCMI_Init(&DCMI_InitStructure);

  /* DCMI Interrupts config ***************************************************/

  DCMI_ITConfig(DCMI_IT_VSYNC, ENABLE);

  DCMI_ITConfig(DCMI_IT_LINE, ENABLE);

  DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);

  DCMI_ITConfig(DCMI_IT_ERR, ENABLE);

     

       

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = DCMI_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 15;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 

  NVIC_Init(&NVIC_InitStructure);

  /* Configures the DMA2 to transfer Data from DCMI to the LCD ****************/

  /* Enable DMA2 clock */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); 

 

  /* DMA2 Stream1 Configuration */ 

 

 DMA_DeInit(DMA2_Stream1);

 

 DMA_InitStructure.DMA_Channel = DMA_Channel_1; 

 //DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS; 

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(DCMI_BASE + 0x28); 

 DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)&buffer_A ;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;

  DMA_InitStructure.DMA_BufferSize = 0xffff;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;        

  DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;

  DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;

  DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;   

 

 DMA_Init(DMA2_Stream1, &DMA_InitStructure);

 

}

/**

  * @brief  Set PA8 Output SYSCLK/2.

  * @param  None

  * @retval None

  */

void MCO1_Init(void)

{

 GPIO_InitTypeDef GPIO_InitStructure;

 RCC_ClockSecuritySystemCmd(ENABLE);

 /* Enable GPIOs clocks */

 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

 

 GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO);

  

 /* Configure MCO (PA8) */

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 RCC_MCO1Config(RCC_MCO1Source_PLLCLK, RCC_MCO1Div_3);

}

void DCMI_0V7670_PWDN_Init(void)

{

 GPIO_InitTypeDef GPIO_InitStructure;

 /* Enable GPIOs clocks */

 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; 

 GPIO_Init(GPIOB, &GPIO_InitStructure);

 /*PWDN*/

 GPIO_ResetBits(GPIOA, GPIO_Pin_2);

 Delay_ms(10);

 GPIO_SetBits(GPIOA, GPIO_Pin_2); 

}

/**

  * @brief  Set the VGA size(640*320).

  * @param  None

  * @retval None

  */

uint8_t DCMI_OV7670_Init(void)

{

 uint8_t i;

 SCCB_GPIO_Config();

 DCMI_Config();

 MCO1_Init();

 //DCMI_0V7670_RST_PWDN_Init();

   

   Delay_ms(0xfff);

 if(DCMI_SingleRandomWrite(OV7670_COM7, SCCB_REG_RESET)!=0)

  return 0xff;

 Delay_ms(0xfff);

 

 for(i=0;i<CHANGE_REG_NUM;i++)

 {

  if(DCMI_SingleRandomWrite(change_reg[i][0],change_reg[i][1])!=0)

  {

   return 0xff;

  }

 }

 //OV7670_config_window(272,16,320,240);// set 240*320

 Delay_ms(0xfff);

 return 0;//Init ok

}

/**

  * @brief  Read the OV7670 Manufacturer identifier.

  * @param  OV7670ID: pointer to the OV7670 Manufacturer identifier.

  * @retval None

  */

uint8_t DCMI_OV7670_ReadID(OV7670_IDTypeDef* OV7670ID)

{

 uint8_t temp;

 if(DCMI_SingleRandomRead(OV7670_MIDH,&temp)!=0)

  return 0xff;

 OV7670ID->Manufacturer_ID1 = temp;

 if(DCMI_SingleRandomRead(OV7670_MIDL,&temp)!=0)

  return 0xff;

 OV7670ID->Manufacturer_ID2 = temp;

 if(DCMI_SingleRandomRead(OV7670_VER,&temp)!=0)

  return 0xff;

 OV7670ID->Version = temp;

 if(DCMI_SingleRandomRead(OV7670_PID,&temp)!=0)

  return 0xff;

 OV7670ID->PID = temp;

 return 0;

}
    This topic has been closed for replies.

    3 replies

    muhammet
    muhammetAuthor
    Associate II
    August 27, 2013
    Posted on August 27, 2013 at 13:14

    And main code:

    int main(void)

    // OV7670_IDTypeDef OV7670ID;

     RCC_ClocksTypeDef SYS_Clocks;

      /*!< At this stage the microcontroller clock setting is already configured,

           this is done through SystemInit() function which is called from startup

           file (startup_stm32f2xx.s) before to branch to application main.

           To reconfigure the default setting of SystemInit() function, refer to

            system_stm32f2xx.c file

      */

     if (SysTick_Config(SystemCoreClock / 1000))

       {

         /* Capture error */

         while (1);

       }

     RCC_GetClocksFreq(&SYS_Clocks);

     USART_Configuration();

     USART_NVIC_Config();

     DCMI_OV7670_Init();

     

       /* Enable DMA transfer */

        DMA_Cmd(DMA2_Stream1, ENABLE);

        /* Enable DCMI interface */

        DCMI_Cmd(ENABLE);

        /* Start Image capture */

        DCMI_CaptureCmd(ENABLE);

      

      SendPicture();

      while(1);

    }

    void Delay(__IO uint32_t nTime)

    {

      TimingDelay = nTime;

      while(TimingDelay != 0)

      {}

    }

    void TimingDelay_Decrement(void)

    {

      if (TimingDelay != 0x00)

      {

        TimingDelay--;

      }

    }

    void SendPicture(void)

    {

     uint16_t deger;

     uint16_t value;

     int ji=0;

     

     for(ji=0; ji<=38400; ji++)

     {

       if(ji%2==0)

       {

         while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

         value = buffer_A[ji];

         deger = (((value>>4)&0x0f)>0x09) ? (((value>>4)&0x0f)+0x37) : (((value>>4)&0x0f)+0x30);

         USART_SendData(USART2, deger);

         while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

         deger = ((value)&0x0f)>0x09 ? ((value)&0x0f)+0x37 : ((value)&0x0f)+0x30;

         USART_SendData(USART2, deger);

         

        

       }

       else

       {

         while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

         value = buffer_A[ji];

         deger = (((value>>4)&0x0f)>0x09) ? (((value>>4)&0x0f)+0x37) : (((value>>4)&0x0f)+0x30);

         USART_SendData(USART2, deger);

         while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);

         deger = ((value)&0x0f)>0x09 ? ((value)&0x0f)+0x37 : ((value)&0x0f)+0x30;

         USART_SendData(USART2, deger);

        

        

       }

     }

    armindavatgaran
    Associate III
    July 3, 2015
    Posted on July 03, 2015 at 15:09

    Hello

    How do you visualize your image?

    Tesla DeLorean
    Guru
    July 3, 2015
    Posted on July 03, 2015 at 16:06

    Don't most people just create a .BMP or .TIF file, using the documented formats for said, and copy in the video rasters, and then load that into Paint or Photoshop type applications?

    This requires you to understand the format and structure of the data involved, and fill in header information so the decoding program can process it correctly. This might also require that you handle the colour space/format of the image, building a palette table, or organize the rasters in a specific way/order.

    There are many image formats, pick one that most closely matches your source data.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..