stm32f103c8t6串口发送 OV2640的图像,分辨率可选。网络上资料大部分是低分辨率的,这个可以做高分辨率
完整工程打包,包含VB串口显示界面:
Stm32标准库函数5-OV2640PA0-7F103C8T64500000联合VB高分辨率资源-单片机文档类资源-CSDN下载
用串口传送图像数据,串口波特率为4500000(ch340达不到这么高的波特率,pl2303可以,但稳定性要差些。也可以自行设置成其他波特率,降低帧率),调试时,先设定为低分辨率,看联线是否正常。如果VB界面不显示,可以用串口助手,向stm32发送任意一字节任意数据,查看返回数据是否是图像(jpg格式为压缩格式,其有对应的信息头和信息尾标志)。
//14fps: JPEG_160x120 JPEG_176x144 JPEG_320x240 JPEG_352x288
//7.5fps: JPEG_640x480 JPEG_800x600
//1.5fps: JPEG_1024x768 JPEG_1024x1024 JPEG_1280x1024 JPEG_1600x1200
//串口发送一字节任意数据,返回一幅图像
#include "stm32f10x.h"
#include
#include "Delay/Delay.h"
#include "USART/USART.h"
#include "OV2640/dcmi_ov2640.h"
#include "../BMP/BMP.h"
#include "timer.h"
#include "stm32f10x_tim.h"
extern unsigned char VsyncCnt; //场同步标志
extern u32 JpegDataCnt;
//extern u8 JpegBuffer[10240];
extern u8 VsyncActive;
OV2640_IDTypeDef OV2640_Camera_ID;
//定时器3中断服务程序
void TIM3_IRQHandler(void) //TIM3中断
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //检查TIM3更新中断发生与否
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //清除TIMx更新中断标志
USART1_Transmit('Q');
}
}
int main(void)
{
// u16 i = 0;
Delay_Init(72);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);//使能PB3与PB4
USART1_Init(4500000); //在与VB通讯时可以选用 115200 4500000
NVIC_usart();
// USART_SendString("uart init ok!\r\n");
OV2640_HW_Init(); //IIC初始化
// memset(&OV2640_Camera_ID,0x0,sizeof(OV2640_IDTypeDef));
// USART_SendString("uart IIC ok!\r\n");
OV2640_ReadID(&OV2640_Camera_ID); //读取OV2640ID,测试硬件,依次为:0x7F,0xA2,0x26,0x42
//14fps: JPEG_160x120 JPEG_176x144 JPEG_320x240 JPEG_352x288
//7.5fps: JPEG_640x480 JPEG_800x600
//1.5fps: JPEG_1024x768 JPEG_1024x1024 JPEG_1280x1024 JPEG_1600x1200
OV2640_JPEGConfig(JPEG_1024x768);
//设置自动曝光和白平衡
OV2640_BrightnessConfig(0x20);
OV2640_AutoExposure(2);
OV2640_CaptureGpioInit(); //数据采集引脚初始化
EXTI->IMR &= ~EXTI_Line3; //关闭场同步中断
EXTI->EMR &= ~EXTI_Line3;
EXTI->IMR &= ~EXTI_Line4; //关闭像素同步中断
EXTI->EMR &= ~EXTI_Line4;
Delay_nMS(10); //等待图像输出稳定
EXTI->IMR |= EXTI_Line3; //使能场同步中断,准备下次采集
EXTI->EMR |= EXTI_Line3;
while(1)
{
if(VsyncActive == 2)
{
//封帧格式为:0xAA CMD 0x55
if(get_flag_usart()==1)
{
// TIM3_Int_Init(49999,7199);//10Khz的计数频率,计数到50000为5000ms
set_flag_usart(0);
EXTI->IMR |= EXTI_Line3; //使能场同步中断,准备下次采集
EXTI->EMR |= EXTI_Line3;
//VsyncCnt = 0; //开始下一帧数据采集
}
}
}
}