完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
#define IMAGE_BUFFER_SIZE 100 //以字为单位 经试验,增大这个数值速度并未提升
u32 Image_Buffer1[IMAGE_BUFFER_SIZE]={0}; u32 Image_Buffer2[IMAGE_BUFFER_SIZE]={0}; //OV2640 JPEG模式接口配置 void OV2640_JpegDcmiInit(void) { 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_CaptureMode_Continuous; DCMI_InitStructure.DCMI_SynchroMode = DCMI_SynchroMode_Hardware; DCMI_InitStructure.DCMI_PCKPolarity = DCMI_PCKPolarity_Rising;// DCMI_InitStructure.DCMI_VSPolarity = DCMI_VSPolarity_Low; DCMI_InitStructure.DCMI_HSPolarity = DCMI_HSPolarity_Low; DCMI_InitStructure.DCMI_CaptureRate = DCMI_CaptureRate_All_Frame; DCMI_InitStructure.DCMI_ExtendedDataMode = DCMI_ExtendedDataMode_8b; //初始化DCMI DCMI_Init(&DCMI_InitStructure); //使能JPG DCMI_JPEGCmd(ENABLE); /* Configures the DMA2 to transfer Data from DCMI */ /* 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 = (uint32_t)&Image_Buffer1;//传输到内部数组 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = IMAGE_BUFFER_SIZE; //以字为单位 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_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; 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 double buffer mode*///双缓冲区模式 DMA_DoubleBufferModeConfig(DMA2_Stream1,(uint32_t)&Image_Buffer2,DMA_Memory_0);//DMA_Memory_0首先被传输 DMA_DoubleBufferModeCmd(DMA2_Stream1,ENABLE); DMA_Init(DMA2_Stream1, &DMA_InitStructure); //初始化DMA Dma_FreeBuf_Ok = 0;//此时没有数据准备完成 // DMA_Cmd(DMA2_Stream1,ENABLE);//启动DMA2_Stream1 //中断使能 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); 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); DCMI_ITConfig(DCMI_IT_FRAME,ENABLE); //中断使能 NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); DMA_ITConfig(DMA2_Stream1,DMA_IT_TC,ENABLE); } //DMA传输完成中断 void DMA2_Stream1_IRQHandler(void) { DMA_InitTypeDef DMA_InitStructure; if(DMA_GetITStatus(DMA2_Stream1,DMA_IT_TCIF1) != RESET) { DMA_ClearITPendingBit(DMA2_Stream1,DMA_IT_TCIF1); Dma_FreeBuf_Ok = 1;//有准备好的数据了 } } //主循环 while(1) { //uip_polling(); if(Dma_FreeBuf_Ok == 1)//DMA有空闲缓冲区了 { usart_sendJPEGdata(); Dma_FreeBuf_Ok = 0; } //串口传输 void usart_sendJPEGdata(void) { u32 i; if(DMA_GetCurrentMemoryTarget(DMA2_Stream1) == 1) { for(i=0;i { USART_SendData(USART2,Image_Buffer1); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); USART_SendData(USART2,Image_Buffer1>>8); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); USART_SendData(USART2,Image_Buffer1>>16); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); USART_SendData(USART2,Image_Buffer1>>24); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); } } else { for(i=0;i USART_SendData(USART2,Image_Buffer2); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); USART_SendData(USART2,Image_Buffer2>>8); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); USART_SendData(USART2,Image_Buffer2>>16); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); USART_SendData(USART2,Image_Buffer2>>24); while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)==RESET); } } } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1105 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1128 浏览 1 评论
558 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
420 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1011 浏览 2 评论
1603浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
270浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
283浏览 3评论
255浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
245浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-18 17:59 , Processed in 0.860725 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号