求助!!!!!!我现在在调试OV2640摄像头模块,可是我发现我怎么也进不了中断,大神看看void DCMI_IRQHandler(void) //dcmi.c{
if(DCMI_GetITStatus(DCMI_IT_FRAME)==SET)//
{
jpeg_data_process(); //main.c
DCMI_ClearITPendingBit(DCMI_IT_FRAME);
LED1=!LED1; //test
ov_frame++;
}
}
通过串口显示图片,LCD用来辅助调试
下面是main.c和dcmi.c,其他的文件都是配置,就不列了
main.c:
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "timer.h"
#include "ov2640.h"
#include "dcmi.h"
#include "key.h"
#include "lcd.h"
#include "usart2.h"
u8 ov2640_mode=0; //1,JPEG模式
#define jpeg_buf_size 31*1024 //定义jepg_buf数据缓存大小(*4字节)
__align(4) u32 jpeg_buf[jpeg_buf_size]; //JPEG数据缓存buf
volatile u32 jpeg_data_len=0; //buf中的JPEG有效数据长度
volatile u8 jpeg_data_ok=0; //JPEG数据采集完成标准
//0,没采集完
//1,采集完,没处理
//2,处理完,开始下一帧采集
//JPEG3ß′çÖ§3ÖáD±í
const u16 jpeg_img_size_tbl[][2]=
{
176,144, //QCIF
160,120, //QQVGA
352,288, //CIF
320,240, //QVGA
640,480, //VGA
800,600, //SVGA
1024,768, //XGA
1280,1024, //SXGA
1600,1200, //UXGA
};
const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"}; //7中特效
const u8*JPEG_SIZE_TBL[9]={"QCIF","QQVGA","CIF","QVGA","VGA","SVGA","XGA","SXGA","UXGA"}; //9中尺寸
//处理JPEG数据
//采集完一帧数据后用此函数.
void jpeg_data_process(void)
{
if(ov2640_mode)
{
if(jpeg_data_ok==0) //jpegêy¾Y»1Î′2é¼ˉíê?
{
DMA_Cmd(DMA2_Stream1,DISABLE);//í£Ö1μ±Ç°′«êä
while (DMA_GetCmdStatus(DMA2_Stream1)!=DISABLE){}//μè′yDMA2_Stream1¿éÅäÖÃ
jpeg_data_len=jpeg_buf_size-DMA_GetCurrDataCounter(DMA2_Stream1);//μÃμ½′Ë′Îêy¾Y′«êäμÄ3¤¶è
jpeg_data_ok=1; //±ê¼ÇJPEGêy¾Y2é¼ˉíê°′3é,μè′yÆäËûoˉêy′|àí
}
if(jpeg_data_ok==2) //éÏò»′ÎμÄjpegêy¾YòѾ-±»′|àíáË
{
DMA2_Stream1->NDTR=jpeg_buf_size;
DMA_SetCurrDataCounter(DMA2_Stream1,jpeg_buf_size);//′«êä3¤¶èÎajpeg_buf_size*4×Ö½ú
DMA_Cmd(DMA2_Stream1,ENABLE); //ÖØDÂ′«êä
jpeg_data_ok=0; //±ê¼Çêy¾YÎ′2é¼ˉ
}
}
}
//JPEG test
//JPEG,通过串口2发送电脑
void jpeg_test(void)
{
u32 i;
u8 *p;
//u8 key;
//u8 effect=0,saturation=2,contrast=2; //ìØD§ ±¥oí¶è ¶Ô±è¶è
u8 size=3; //默认QVGA ,320*240尺寸
u8 msgbuf[15]; //消息缓存区
usart2_init(42,115200);
//LCD_Clear(WHITE);
POINT_COLOR=BLUE;
LCD_ShowString(30,130,200,16,16,"OV2640 Mode:JPEG");
sprintf((char*)msgbuf,"JPEG Size:%s",JPEG_SIZE_TBL[size]);
LCD_ShowString(30,180,200,16,16,msgbuf); //ÏÔê¾μ±Ç°JPEG·Ö±æÂê
OV2640_JPEG_Mode(); //JPEGÄ£ê½
My_DCMI_Init(); //DCMIÅäÖÃ
DCMI_DMA_Init((u32)&jpeg_buf,jpeg_buf_size,DMA_MemoryDataSize_Word,DMA_MemoryInc_Enable);//DCMI DMA配置
OV2640_OutSize_Set(jpeg_img_size_tbl[size][0],jpeg_img_size_tbl[size][1]);//设置输出尺寸
DCMI_Start(); //dcmi.c 开始传输
while(1)
{
if(jpeg_data_ok==1) //已经采集完一帧图像
{
p=(u8*)jpeg_buf;
LCD_ShowString(30,210,210,16,16,"Sending JPEG data..."); //ìáê¾ÕyÔú′«êäêy¾Y
for(i=0;i<jpeg_data_len*4;i++) //dma′«êä1′Îμèóú4×Ö½ú,ËùòÔ3ËòÔ4.
{
USART_SendData(USART2,p[i]);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET); //循环发送,直到发送完毕
}
jpeg_data_ok=2; //处理完,采集下一帧
}
}
}
int main(void)
{
//u8 key;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //3õê¼»ˉÑóê±oˉêy
uart_init(115200); //3õê¼»ˉ′®¿ú2¨ìØÂêÎa115200
usart2_init(42,115200); //3õê¼»ˉ′®¿ú22¨ìØÂêÎa115200
LED_Init(); //3õê¼»ˉLED¶Ë¿ú
LCD_Init();
POINT_COLOR=RED;
TIM3_Int_Init(10000-1,8400-1);//10Khz¼Æêy,1ÃëÖóÖD¶Ïò»′Î
while(OV2640_Init())//3õê¼»ˉOV2640 //u8 OV2640_Init() return:0 3é1|//
{
LCD_ShowString(30,130,240,16,16,"OV2640 Init ERR");
delay_ms(200);
LCD_Fill(30,130,239,170,WHITE);
delay_ms(200);
}
LCD_ShowString(30,50,200,16,16,"OV2640 Init OK");
GPIO_ResetBits(GPIOF,GPIO_Pin_9);
//while(1)
//{
//key=KEY_Scan(0);
//if(key==KEY0_PRES)
//{
ov2640_mode=1;
//break;
//}
//delay_ms(5);
// jpeg_test();
//}
if(ov2640_mode==1)
{
jpeg_test();
}
}
dcmi.c:
#include "sys.h"
#include "dcmi.h"
#include "lcd.h"
#include "led.h"
#include "ov2640.h"
u8 ov_frame=0; //Ö¡Âê
extern void jpeg_data_process(void); //JPEGêy¾Y′|àíoˉêy
DCMI_InitTypeDef DCMI_InitStructure;
//DCMIÖD¶Ï·tÎñoˉêy//
void DCMI_IRQHandler(void)
{
if(DCMI_GetITStatus(DCMI_IT_FRAME)==SET)//2¶»ñμ½ò»Ö¡í¼Ïñ
{
jpeg_data_process(); //jpegêy¾Y′|àí
DCMI_ClearITPendingBit(DCMI_IT_FRAME);//Çå3yÖ¡ÖD¶Ï
LED1=!LED1;
ov_frame++;
}
}
//DCMI DMAÅäÖÃ
//DMA_Memory0BaseAddr:′æ′¢Æ÷μØÖ· ½«òa′æ′¢éãÏñí·êy¾YμÄÄú′æμØÖ·(ò2¿éòÔêÇíaéèμØÖ·)
//DMA_BufferSize:′æ′¢Æ÷3¤¶è 0~65535
//DMA_MemoryDataSize:′æ′¢Æ÷λ¿í @defgroup DMA_memory_data_size
MA_MemoryDataSize_Byte/DMA_MemoryDataSize_HalfWord/DMA_MemoryDataSize_Word
//DMA_MemoryInc:′æ′¢Æ÷Ôö3¤·½ê½ @defgroup DMA_memory_incremented_mode /** @defgroup DMA_memory_incremented_mode : DMA_MemoryInc_Enable/DMA_MemoryInc_Disable
void DCMI_DMA_Init(u32 DMA_Memory0BaseAddr,u16 DMA_BufferSize,u32 DMA_MemoryDataSize,u32 DMA_MemoryInc)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2,ENABLE);//DMA2ê±Öóê1Äü
DMA_DeInit(DMA2_Stream1);
while(DMA_GetCmdStatus(DMA2_Stream1)!=DISABLE){}//μè′yDMA2_Stream1¿éÅäÖÃ
/* ÅäÖÃ DMA Stream */
DMA_InitStructure.DMA_Channel=DMA_Channel_1; //
DMA_InitStructure.DMA_PeripheralBaseAddr=(u32)&DCMI->DR;//íaéèμØÖ·Îa
CMI->DR
DMA_InitStructure.DMA_Memory0BaseAddr=DMA_Memory0BaseAddr;//DMA ′æ′¢Æ÷0μØÖ·
DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralToMemory;//íaéèμ½′æ′¢Æ÷Ä£ê½
DMA_InitStructure.DMA_BufferSize =DMA_BufferSize;//êy¾Y′«êäá¿
DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;//íaéè·ÇÔöá¿Ä£ê½
DMA_InitStructure.DMA_MemoryInc =DMA_MemoryInc;//′æ′¢Æ÷Ôöá¿Ä£ê½
DMA_InitStructure.DMA_PeripheralDataSize=DMA_PeripheralDataSize_Word;//íaéèêy¾Y3¤¶è:32λ
DMA_InitStructure.DMA_MemoryDataSize=DMA_MemoryDataSize;//′æ′¢Æ÷êy¾Y3¤¶è
DMA_InitStructure.DMA_Mode=DMA_Mode_Circular;// ê1óÃÑ-»·Ä£ê½
DMA_InitStructure.DMA_Priority=DMA_Priority_High;//¸ßóÅÏ輶
DMA_InitStructure.DMA_FIFOMode=DMA_FIFOMode_Enable; //FIFOÄ£ê½
DMA_InitStructure.DMA_FIFOThreshold=DMA_FIFOThreshold_Full;//ê1óÃè«FIFO
DMA_InitStructure.DMA_MemoryBurst=DMA_MemoryBurst_Single;//íaéèí»·¢μ¥′Î′«êä
DMA_InitStructure.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;//′æ′¢Æ÷í»·¢μ¥′Î′«êä
DMA_Init(DMA2_Stream1,&DMA_InitStructure);//3õê¼»ˉDMA Stream
}
void My_DCMI_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOE, ENABLE);//ê1ÄüGPIOA B C E ê±Öó
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_DCMI,ENABLE);//ê1ÄüDCMIê±Öó
//PA4/63õê¼»ˉéèÖÃ
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_4|GPIO_Pin_6;//PA4/6 ¸′óÃ1|Äüêä3ö
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF; //¸′óÃ1|Äüêä3ö
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;//íÆíìêä3ö
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;//éÏà-
GPIO_Init(GPIOA,&GPIO_InitStructure);//3õê¼»ˉ
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_7|GPIO_Pin_6;// PB6/7 ¸′óÃ1|Äüêä3ö
GPIO_Init(GPIOB,&GPIO_InitStructure);//3õê¼»ˉ
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_11;//PC6/7/8/9/11 ¸′óÃ1|Äüêä3ö
GPIO_Init(GPIOC,&GPIO_InitStructure);//3õê¼»ˉ
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5|GPIO_Pin_6;//PE5/6 ¸′óÃ1|Äüêä3ö
GPIO_Init(GPIOE,&GPIO_InitStructure);//3õê¼»ˉ
////////¸′óÃÎaÏàó|1|Äü
GPIO_PinAFConfig(GPIOA,GPIO_PinSource4,GPIO_AF_DCMI); //PA4,AF13 DCMI_HSYNC
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_DCMI); //PA6,AF13 DCMI_PCLK
GPIO_PinAFConfig(GPIOB,GPIO_PinSource7,GPIO_AF_DCMI); //PB7,AF13 DCMI_VSYNC
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_DCMI); //PC6,AF13 DCMI_D0
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_DCMI); //PC7,AF13 DCMI_D1
GPIO_PinAFConfig(GPIOC,GPIO_PinSource8,GPIO_AF_DCMI); //PC8,AF13 DCMI_D2
GPIO_PinAFConfig(GPIOC,GPIO_PinSource9,GPIO_AF_DCMI); //PC9,AF13 DCMI_D3
GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_DCMI);//PC11,AF13 DCMI_D4
GPIO_PinAFConfig(GPIOB,GPIO_PinSource6,GPIO_AF_DCMI); //PB6,AF13 DCMI_D5
GPIO_PinAFConfig(GPIOE,GPIO_PinSource5,GPIO_AF_DCMI); //PE5,AF13 DCMI_D6
GPIO_PinAFConfig(GPIOE,GPIO_PinSource6,GPIO_AF_DCMI); //PE6,AF13 DCMI_D7
DCMI_DeInit();//Çå3yÔ-à′μÄéèÖÃ
DCMI_InitStructure.DCMI_CaptureMode=DCMI_CaptureMode_Continuous;//á¬DøÄ£ê½
DCMI_InitStructure.DCMI_CaptureRate=DCMI_CaptureRate_All_Frame;//è«Ö¡2¶»ñ
DCMI_InitStructure.DCMI_ExtendedDataMode= DCMI_ExtendedDataMode_8b;//8λêy¾Y¸ñê½
DCMI_InitStructure.DCMI_HSPolarity= DCMI_HSPolarity_Low;//HSYNC μíμçƽóDD§
DCMI_InitStructure.DCMI_PCKPolarity= DCMI_PCKPolarity_Rising;//PCLK éÏéyÑØóDD§
DCMI_InitStructure.DCMI_SynchroMode= DCMI_SynchroMode_Hardware;//ó2¼tí¬2½HSYNC,VSYNC
DCMI_InitStructure.DCMI_VSPolarity=DCMI_VSPolarity_Low;//VSYNC μíμçƽóDD§
DCMI_Init(&DCMI_InitStructure);
DCMI_Cmd(ENABLE); //DCMIê1Äü
NVIC_InitStructure.NVIC_IRQChannel=DCMI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;//ÇàÕ¼óÅÏ輶1
NVIC_InitStructure.NVIC_IRQChannelSubPriority=2; //×óóÅÏ輶3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //IRQí¨μàê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YÖ¸¶¨μÄ2Îêy3õê¼»ˉVIC¼Ä′æÆ÷
}
//DCMI,启动传输
void DCMI_Start(void)
{
LCD_SetCursor(0,0);
LCD_WriteRAM_Prepare(); //¿aê¼D′èëGRAM
DMA_Cmd(DMA2_Stream1,ENABLE);//¿aÆôDMA2,Stream1
DCMI_CaptureCmd(ENABLE); //DCMI2¶»ñê1Äü
}
//DCMI,关闭传输
void DCMI_Stop(void)
{
DCMI_CaptureCmd(DISABLE);//DCMI2¶»ñê11رÕ
while(DCMI->CR&0X01); //μè′y′«êä½áêø
DMA_Cmd(DMA2_Stream1,DISABLE);//1رÕDMA2,Stream1
}
一周热门 更多>