不进DCMI DMA传输完成中断
检查出现了传输错误中断,哪位大神帮忙分析下!!!
//DCMI DMA配置
//mem0addr:存储器地址0 将要存储摄像头数据的内存地址(也可以是外设地址)
//mem1addr:存储器地址1 当只使用mem0addr的时候,该值必须为0
//memblen:存储器位宽,可以为
MA_MDATAALIGN_BYTE/DMA_MDATAALIGN_HALFWORD/DMA_MDATAALIGN_WORD
//meminc:存储器增长方式,可以为
MA_MINC_ENABLE/DMA_MINC_DISABLE
void DCMI_DMA_Init(u32 mem0addr,u32 mem1addr,u16 memsize,u32 memblen,u32 meminc)
{
__HAL_RCC_DMA2_CLK_ENABLE(); //使能DMA2时钟
__HAL_LINKDMA(&DCMI_Handler,DMA_Handle,DMADMCI_Handler); //将DMA与DCMI联系起来
__HAL_DMA_DISABLE_IT(&DMADMCI_Handler,DMA_IT_TC); //先关闭DMA传输完成中断(否则在使用MCU屏的时候会出现花屏的情况)
DMADMCI_Handler.Instance=DMA2_Stream1; //DMA2数据流1
DMADMCI_Handler.Init.Channel=DMA_CHANNEL_1; //通道1
DMADMCI_Handler.Init.Direction=DMA_PERIPH_TO_MEMORY; //外设到存储器
DMADMCI_Handler.Init.PeriphInc=DMA_PINC_DISABLE; //外设非增量模式
DMADMCI_Handler.Init.MemInc=DMA_MINC_ENABLE; //存储器增量模式
DMADMCI_Handler.Init.PeriphDataAlignment=DMA_MDATAALIGN_WORD; //外设数据长度:32位
DMADMCI_Handler.Init.MemDataAlignment=DMA_MDATAALIGN_WORD; //存储器数据长度:8/16/32位
DMADMCI_Handler.Init.Mode=DMA_CIRCULAR; //使用循环模式
DMADMCI_Handler.Init.Priority=DMA_PRIORITY_HIGH; //高优先级
DMADMCI_Handler.Init.FIFOMode=DMA_FIFOMODE_ENABLE; //使能FIFO
DMADMCI_Handler.Init.FIFOThreshold=DMA_FIFO_THRESHOLD_HALFFULL; //使用1/2的FIFO
DMADMCI_Handler.Init.MemBurst=DMA_MBURST_SINGLE; //存储器突发传输
DMADMCI_Handler.Init.PeriphBurst=DMA_PBURST_SINGLE; //外设突发单次传输
HAL_DMA_DeInit(&DMADMCI_Handler); //先清除以前的设置
HAL_DMA_Init(&DMADMCI_Handler); //初始化DMA
//在开启DMA之前先使用__HAL_UNLOCK()解锁一次DMA,因为HAL_DMA_Statrt()HAL_DMAEx_MultiBufferStart()
//这两个函数一开始要先使用__HAL_LOCK()锁定DMA,而函数__HAL_LOCK()会判断当前的DMA状态是否为锁定状态,如果是
//锁定状态的话就直接返回HAL_BUSY,这样会导致函数HAL_DMA_Statrt()和HAL_DMAEx_MultiBufferStart()后续的DMA配置
//程序直接被跳过!DMA也就不能正常工作,为了避免这种现象,所以在启动DMA之前先调用__HAL_UNLOC()先解锁一次DMA。
__HAL_UNLOCK(&DMADMCI_Handler);
if(mem1addr==0) //开启DMA,不使用双缓冲
{
HAL_DMA_Start(&DMADMCI_Handler,(u32)&DCMI->DR,mem0addr,memsize);
}
else //使用双缓冲
{
HAL_DMAEx_MultiBufferStart(&DMADMCI_Handler,(u32)&DCMI->DR,mem0addr,mem1addr,memsize);//开启双缓冲
__HAL_DMA_ENABLE_IT(&DMADMCI_Handler,DMA_IT_TC); //开启传输完成中断
HAL_NVIC_SetPriority(DMA2_Stream1_IRQn,0,0); //DMA中断优先级
HAL_NVIC_EnableIRQ(DMA2_Stream1_IRQn);
}
}
void (*dcmi_rx_callback)(void);//DCMI DMA接收回调函数
//DMA2数据流1中断服务函数
void DMA2_Stream1_IRQHandler(void)
{
if(__HAL_DMA_GET_FLAG(&DMADMCI_Handler,DMA_FLAG_TCIF1_5)!=RESET)//DMA传输完成
{
__HAL_DMA_CLEAR_FLAG(&DMADMCI_Handler,DMA_FLAG_TCIF1_5);//清除DMA传输完成中断标志位
printf("DMA中断传输完成
");
dcmi_rx_callback(); //执行摄像头接收回调函数,读取数据等操作在这里面处理
SCB_CleanInvalidateDCache(); //清除无效的D-Cache
}
if(__HAL_DMA_GET_FLAG(&DMADMCI_Handler,DMA_FLAG_DMEIF1_5))
{
__HAL_DMA_CLEAR_FLAG(&DMADMCI_Handler,DMA_FLAG_DMEIF1_5);//清除DMA传输完成中断标志位
printf("DMA中断 DMA_FLAG_DMEIF1_5
");
}
if(__HAL_DMA_GET_FLAG(&DMADMCI_Handler,DMA_FLAG_FEIF1_5))
{
__HAL_DMA_CLEAR_FLAG(&DMADMCI_Handler,DMA_FLAG_FEIF1_5);//清除DMA传输完成中断标志位
printf("DMA中断 DMA_FLAG_FEIF1_5
");
}
if(__HAL_DMA_GET_FLAG(&DMADMCI_Handler,DMA_FLAG_TEIF1_5))//传输错误中断
{
__HAL_DMA_CLEAR_FLAG(&DMADMCI_Handler,DMA_FLAG_TEIF1_5);//清除DMA中断标志位
printf("DMA中断 DMA_FLAG_TEIF1_5
");
}
}
Main函数中配置
DCMI_DMA_Init((u32)dcmi_line_buf[0],(u32)dcmi_line_buf[1],IMAGE_WIDTH_CONTEXT_A,DMA_MINC_ENABLE);//DCMI DMA配置
DCMI_Start(); //启动传输
谢谢分享
{
u8 rtn = 0;
u16 version; //MT9V034版本号
PCF8574_Init(); //初始化PCF8574
MT9V034_PWDN_Set(0); //MT9V034上电
SCCB_Init(); //初始化SCCB 的IO口
version = mt9v034_ReadReg16(MTV_CHIP_VERSION_REG);
if(version == 0x1324)
{
mt9v034_WriteReg16(MTV_SOFT_RESET_REG,0x0001);// R0x0C 复位MT9V034
delay_ms(100);
mt9v034_WriteReg16(MTV_SOFT_RESET_REG,0x0000);// R0x0C 取消复位
delay_ms(100);
mt9v034_WriteReg16(MTV_LED_OUT, 0x0002); // R0x1B LED_OUT
mt9v034_WriteReg16(MTV_READ_MODE_REG_A, 0x0330); // R0x0D Read out rows from bottom to top (upside down). Read out columns from right to left (mirrored). Context A
mt9v034_WriteReg16(MTV_COLUMN_START_REG_A,(MAX_IMAGE_WIDTH - IMAGE_WIDTH_CONTEXT_A)/2 + MINIMUM_COLUMN_START);//R0x01 列开始 Context A
mt9v034_WriteReg16(MTV_ROW_START_REG_A,(MAX_IMAGE_HEIGHT - IMAGE_HEIGHT_CONTEXT_A)/2 + MINIMUM_ROW_START); //R0x02 行开始 Context A
mt9v034_WriteReg16(MTV_WINDOW_WIDTH_REG_A,IMAGE_WIDTH_CONTEXT_A); //R0x03 开窗宽度 Context A
mt9v034_WriteReg16(MTV_WINDOW_HEIGHT_REG_A,IMAGE_HEIGHT_CONTEXT_A); //R0x04 开窗高度 Context A
mt9v034_WriteReg16(MTV_HOR_BLANKING_REG_A, MAX_IMAGE_WIDTH - IMAGE_WIDTH_CONTEXT_A + MINIMUM_HORIZONTAL_BLANKING);//R0x05 水平消隐 Context A
mt9v034_WriteReg16(MTV_VER_BLANKING_REG_A, 500);//R0x06 垂直消隐 Context A
/* Chip Control
*
* bits | 15 | ... | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* -------------------------------------------------------------------
* current values | 0 | ... | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
*
* (0:2) Scan Mode (Progressive scan)
* (3:4) Sensor Operation Mode (Master mode)
* (5) Stereoscopy Mode (Disable)
* (6) Stereoscopic Master/Slave mode (not used)
* (7) Parallel Output Enable (1 Enable)
* (8) Simultaneous/Sequential Mode ( 1 Simultaneous mode)
* (9) Reserved ( default 1)
*
* (15)Context A (0) / Context B (1) (0-A MODE / 1-B MODE)
*
*/
mt9v034_WriteReg16(MTV_CHIP_CONTROL_REG, 0x0188); // R0x07 Chip Control A MODE
mt9v034_WriteReg16(MTV_HDR_ENABLE_REG, 0x10); // R0x0F High Dynamic on both contexts -- 高动态
mt9v034_WriteReg16(0x2C, 0x0006);// R0x2C VREF_ADC Control default(0x04 - 1.5V) This set 0x06-1.6V
mt9v034_WriteReg16(MTV_V1_CTRL_REG_A, 0x001F); // R0x31 V1_control:default(0X1D)-2.375V 0X1F-2.5V
mt9v034_WriteReg16(MTV_V2_CTRL_REG_A, 0x001A); // R0x32 V2_control:default(0X18)-2.0625V 0X1A-2.1875V
mt9v034_WriteReg16(MTV_V3_CTRL_REG_A, 0x0012); // R0x33 V3_control:default(0X15)-1.875V 0X12-1.6875V
mt9v034_WriteReg16(MTV_V4_CTRL_REG_A, 0x0003); // R0x34 V4_control:default(0X03) 0to5 *200mV + 0.2V. 6to63 *23.5mV + 1.62V.
mt9v034_WriteReg16(MTV_ANALOG_GAIN_CTRL_REG_A, 0x0010);//R0x35 Analog Gain:default(0X10)-gainX1 0X20-gainX2 0X30-gainX3
mt9v034_WriteReg16(0x70, 0x0004);//0x0014
mt9v034_WriteReg16(MTV_ROW_NOISE_CORR_CTRL_REG, 0x0000);// R0x70 行噪修正
mt9v034_WriteReg16(MTV_AEC_AGC_ENABLE_REG,0x0003); // R0xAF AEC_AGC ENABLE Context A
mt9v034_WriteReg16(MTV_MIN_EXPOSURE_REG, 0X20); //Min Exposure 白天 0X100 晚上 0X400
mt9v034_WriteReg16(MTV_MAX_EXPOSURE_REG, 0X40); //Max Exposure 白天 0X400 晚上 0XA00
mt9v034_WriteReg16(MTV_MAX_GAIN_REG, 0x40);//default AGC 0x40
printf("MT9V034初始化成功! ");
return 0;
}
else
{
printf("MT9V034初始化失败,读到的version为:%d ",version);
return 1;
}
}
一周热门 更多>