原子哥,我配置DCMI跟DMA,配置之后收不到数据。开行、场中断会进中断。然后关所有中断,在主循环里判断DCMI的FIFO是不是有数据,一直无有效数据。最后我把引脚配置成通用输入引脚,分别用PCLK、行、场、引脚中断,都可以进中断。下面是我的配置代码,是不是有问题啊?
[mw_shl_code=c,true]定义的接收地址及缓存,缓存放在SDRAM中,SDRAM测试过、读写数据没问题。
#define DCMI_DR_ADDRESS 0x50050028
#define FSMC_LCD_ADDRESS 0xD0000000//未用开启LCD控制器,这里用做SDRAM首地址
#define BUFFER_SIZE (40960)
U32 YUV422BUF1[40960] __attribute__((at(FSMC_LCD_ADDRESS)));
U32 YUV422BUF2[40960] __attribute__((at(FSMC_LCD_ADDRESS + (40960 * 4))));
引脚配置:
/*** Configures the DCMI GPIOs to interface with the OV2640 camera module ***/
/* Enable DCMI GPIOs clocks */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB |
RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE);
/* Connect DCMI pins to AF13 */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_DCMI);//DCMI_D0
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_DCMI);//DCMI_D1
GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_DCMI);//DCMI_D2
GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_DCMI);//DCMI_D3
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_DCMI);//DCMI_D4
GPIO_PinAFConfig(GPIOD, GPIO_PinSource3, GPIO_AF_DCMI);//DCMI_D5
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_DCMI);//DCMI_D6
GPIO_PinAFConfig(GPIOE, GPIO_PinSource6, GPIO_AF_DCMI);//DCMI_D7[/mw_shl_code]
[mw_shl_code=c,true]
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_DCMI);//DCMI_VSYNC
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_DCMI);//DCMI_HSYNC
GPIO_PinAFConfig(GPIOA, GPIO_PinSource6, GPIO_AF_DCMI);//PCLK
/* DCMI GPIO configuration */
/* D0..D4(PC6/7/8/9/11) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 |
GPIO_Pin_9 | GPIO_Pin_11;
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_InitStructure.GPIO_Mode = GPIO_Mode_IN;
// 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);
/* D5(PD3)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* D6(PB8),VSYNC(PB7)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_7;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* D7(PD3)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* HSYNC(PA4)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* PCLK(PA6) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DCMI跟DMA配置
/****************************************************/
DCMI_InitTypeDef DCMI_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure; //NVIC
/*** Configures the DCMI to interface with the OV2640 camera module ***/
/* Enable DCMI clock */
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI, ENABLE);
/* DCMI configuration */
DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_Continuous;
// DCMI_InitStructure.DCMI_CaptureMode = DCMI_CaptureMode_SnapShot;
DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware;
DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Falling;
// DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_Low;
// DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low;
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_8b;
/* DCMI configuration */
DCMI_Init(&DCMI_InitStructure);
[mw_shl_code=c,true] DCMI_ITConfig(DCMI_IT_FRAME, ENABLE);[/mw_shl_code]
/* Configures the DMA2 to transfer Data from DCMI */
//Interrupt Init
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);
/* 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_Memory0BaseAddr = FSMC_LCD_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)YUV422BUF1;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = BUFFER_SIZE;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
//DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_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_Circular;
//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_DoubleBufferModeConfig(DMA2_Stream1,(uint32_t)&YUV422BUF2,DMA_Memory_0);//DMA_Memory_0;
DMA_DoubleBufferModeCmd(DMA2_Stream1,ENABLE);
DMA_ITConfig(DMA2_Stream1,DMA_IT_TC,ENABLE);
DMA_Init(DMA2_Stream1, &DMA_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
int main(void)
{ [/mw_shl_code]
[mw_shl_code=c,true] unsigned int i;
SDRAM_Init();//SDRAM[/mw_shl_code]
[mw_shl_code=c,true] for(i = 0;i < BUFFER_SIZE;i++)
{
YUV422BUF1 = i;
YUV422BUF2 = BUFFER_SIZE - i;
}
[/mw_shl_code]
[mw_shl_code=c,true] PORT_Init();
DCMIDMA_Init();
DCMI_Cmd(ENABLE);
DMA_Cmd(DMA2_Stream1, ENABLE);
while(1)
{
}
}[/mw_shl_code]
|