使用Microblaze对OV5640进行寄存器配置

Microblaze基础知识

下图为Microblaze框图:

Microblaze各端口的作用如下表:

接口作用
DLMB(data local memory bus)数据接口,本地存储器总线, 该总线为 CPU 与本地块存储器间的数据交换通道
ILMB(Instruction Local Memory Bus)指令接口,本地存储器总线, 该总线为CPU与内部块存储器间的指令通道,提供高速指令的提取
M_AXI_DP外围数据接口,可以用来连接片内BRAM,AXI_Lite类型
M_AXI_IP外围指令接口,用来挂载外部AXI总线形式的接口外设IP,AXI_Lite类型
M_AXI_DC外部存储器数据接口,AXI_FULL类型
M_AXI_IC外部存储器指令接口,AXI_FULL类型

 Processor System Reset各端口作用如下表:

接口作用
slowest_sync_clk(i)连接到系统中最慢的时钟
ext_reset_in(i)FPGA外部输入的复位信号
aux_reset_in(i)辅助复位信号,配置如ext_reset_in
mb_debug_sys_rst(i)

 microblaze核debug的复位输入信号

dcm_locked(i)PLL的locked信号,如果系统有PLL则连接其locked信号到这个端口,如果无,此端口置1或者悬空
mb_reset(o)输出到microblaze的复位信号
Peripherals_aresetn(o)外设复位信号,低有效
Peripherals_areset(o)外设复位信号,高有效
Bus Structure Reset(o)一些桥接器的复位信号,暂时不理解,很少使用(一般连接到Local Memory的复位端口)
Interconnect_aresetn(o)内部互联复位信号

创建Block Design

block design模块框图如下图

 

Block Design生成后,右键生成的.bd文件,依次执行Generate output products,Create HDL wrapper

编写microblaze代码 

iic驱动部分:iic写操作使用自带的XIic_DynInit()函数实现

#include	<stdio.h>
#include	"platform.h"
#include	"xil_printf.h"
#include	"xgpio.h"
#include	"xparameters.h"
#include	"xiic_l.h"
#include	"xiic.h"
#include	"xiic.h"
#include	"iic_regs.h"
#include	"iic_cfg_regs.h"

#define		IIC_SLAVE_ADDRESS	0x3C

int iic_dri(struct Cfg_para *ov5640_cfg_table);
int	iic_init(void);
int iic_write(XIic *InstancePtr, u8 addr_h, u8 addr_l, u8 data);

u8 buffer[3];

XGpio		Gpio;
XIic 		iic;

int main()
{
	int k=0;
	XGpio_Initialize(&Gpio, XPAR_AXI_GPIO_0_DEVICE_ID);
	XGpio_SetDataDirection(&Gpio, 1, 0);
	XGpio_DiscreteWrite(&Gpio,1,0x00000001);

	k = iic_dri(ov5640_cfg_table);
	printf("%d\n", k);

}

int iic_dri(struct Cfg_para *ov5640_cfg_table)
{
	int status;
	int i = 0;
	int cfg_num = 0;
	int sendbytenum;

	status = iic_init();
	if(status != XST_SUCCESS)
	{
		xil_printf("IIC initialization Failed1!\n");
	}

	while(i<251)
	{
		i++;
		sendbytenum = iic_write(&iic, (ov5640_cfg_table+i)->addr_h, (ov5640_cfg_table+i)->addr_l, (ov5640_cfg_table+i)->data);
		while(XIic_IsIicBusy(&iic))
		{
			xil_printf("wait...\n");
		}
		if(sendbytenum==3){
			cfg_num++;
		}
	}
	return cfg_num;
}

int iic_init()
{
	int Status;

	Status = XIic_DynInit(XPAR_IIC_0_BASEADDR);
	if(Status != XST_SUCCESS)
	{
		xil_printf("I2C初始化失败!");
		return XST_FAILURE;
	}
	return XST_SUCCESS;
}

int iic_write(XIic *InstancePtr, u8 addr_h, u8 addr_l, u8 data)
{
	u8 SendBytecount;
	u8 buffer[3] = {addr_h,addr_l,data};
	SendBytecount = XIic_DynSend(XPAR_IIC_0_BASEADDR, IIC_SLAVE_ADDRESS, buffer, 3, XIIC_STOP);
	return SendBytecount;
}

iic控制寄存器参数文件:该部分定义了iic的各种控制寄存器

#ifndef SRC_IIC_REGS_H_
#define SRC_IIC_REGS_H_

#define	GIE				0x01C
#define	ISR				0x020
#define	IER				0x028
#define	SOFTR			0x040
#define	CR				0x100
#define	SR				0x104
#define	TX_FIFO			0x108
#define	RX_FIFO			0x10C
#define	ADR				0x110
#define	TX_FIFO_OCY		0x114
#define	RX_FIFO_OCY		0x118
#define	TEN_ADR			0x11C
#define	RX_FIFO_PIRQ	0x120
#define	GPO				0x124

#endif /* SRC_IIC_REGS_H_ */

OV5640配置寄存器文件:

#ifndef SRC_IIC_CFG_REGS_H_
#define SRC_IIC_CFG_REGS_H_

#define		IMAGE_WIDTH			640
#define		IMAGE_HEIGHT		480

struct	Cfg_para
{
	u8	addr_h;
	u8	addr_l;
	u8	data;
}ov5640_cfg_table[251]={
		//{0x31, 0x03, 0x11},
		{49, 03, 17},
		{0x30, 0x08, 0x82},
		{0x30, 0x08, 0x42},
		{0x31, 0x03, 0x03},
		{0x30, 0x17, 0xff},
		{0x30, 0x18, 0xff},
		{0x30, 0x34, 0x1A},
		{0x30, 0x37, 0x13},
		{0x31, 0x08, 0x01},
		{0x36, 0x30, 0x36},
		{0x36, 0x31, 0x0e},
		{0x36, 0x32, 0xe2},
		{0x36, 0x33, 0x12},
		{0x36, 0x21, 0xe0},
		{0x37, 0x04, 0xa0},
		{0x37, 0x03, 0x5a},
		{0x37, 0x15, 0x78},
		{0x37, 0x17, 0x01},
		{0x37, 0x0b, 0x60},
		{0x37, 0x05, 0x1a},
		{0x39, 0x05, 0x02},
		{0x39, 0x06, 0x10},
		{0x39, 0x01, 0x0a},
		{0x37, 0x31, 0x12},
		{0x36, 0x00, 0x08},
		{0x36, 0x01, 0x33},
		{0x30, 0x2d, 0x60},
		{0x36, 0x20, 0x52},
		{0x37, 0x1b, 0x20},
		{0x47, 0x1c, 0x50},
		{0x3a, 0x13, 0x43},
		{0x3a, 0x18, 0x00},
		{0x3a, 0x19, 0xf8},
		{0x36, 0x35, 0x13},
		{0x36, 0x36, 0x03},
		{0x36, 0x34, 0x40},
		{0x36, 0x22, 0x01},
		{0x3c, 0x01, 0x34},
		{0x3c, 0x04, 0x28},
		{0x3c, 0x05, 0x98},
		{0x3c, 0x06, 0x00},
		{0x3c, 0x07, 0x08},
		{0x3c, 0x08, 0x00},
		{0x3c, 0x09, 0x1c},
		{0x3c, 0x0a, 0x9c},
		{0x3c, 0x0b, 0x40},
		{0x38, 0x10, 0x00},
		{0x38, 0x11, 0x10},
		{0x38, 0x12, 0x00},
		{0x37, 0x08, 0x64},
		{0x40, 0x01, 0x02},
		{0x40, 0x05, 0x1a},
		{0x30, 0x00, 0x00},
		{0x30, 0x04, 0xff},
		{0x30, 0x0e, 0x58},
		{0x30, 0x2e, 0x00},
		{0x43, 0x00, 0x60},
		{0x50, 0x1f, 0x01},
		{0x44, 0x0e, 0x00},
		{0x50, 0x00, 0xa7},
		{0x3a, 0x0f, 0x30},
		{0x3a, 0x10, 0x28},
		{0x3a, 0x1b, 0x30},
		{0x3a, 0x1e, 0x26},
		{0x3a, 0x11, 0x60},
		{0x3a, 0x1f, 0x14},
		{0x58, 0x00, 0x23},
		{0x58, 0x01, 0x14},
		{0x58, 0x02, 0x0f},
		{0x58, 0x03, 0x0f},
		{0x58, 0x04, 0x12},
		{0x58, 0x05, 0x26},
		{0x58, 0x06, 0x0c},
		{0x58, 0x07, 0x08},
		{0x58, 0x08, 0x05},
		{0x58, 0x09, 0x05},
		{0x58, 0x0a, 0x08},
		{0x58, 0x0b, 0x0d},
		{0x58, 0x0c, 0x08},
		{0x58, 0x0d, 0x03},
		{0x58, 0x0e, 0x00},
		{0x58, 0x0f, 0x00},
		{0x58, 0x10, 0x03},
		{0x58, 0x11, 0x09},
		{0x58, 0x12, 0x07},
		{0x58, 0x13, 0x03},
		{0x58, 0x14, 0x00},
		{0x58, 0x15, 0x01},
		{0x58, 0x16, 0x03},
		{0x58, 0x17, 0x08},
		{0x58, 0x18, 0x0d},
		{0x58, 0x19, 0x08},
		{0x58, 0x1a, 0x05},
		{0x58, 0x1b, 0x06},
		{0x58, 0x1c, 0x08},
		{0x58, 0x1d, 0x0e},
		{0x58, 0x1e, 0x29},
		{0x58, 0x1f, 0x17},
		{0x58, 0x20, 0x11},
		{0x58, 0x21, 0x11},
		{0x58, 0x22, 0x15},
		{0x58, 0x23, 0x28},
		{0x58, 0x24, 0x46},
		{0x58, 0x25, 0x26},
		{0x58, 0x26, 0x08},
		{0x58, 0x27, 0x26},
		{0x58, 0x28, 0x64},
		{0x58, 0x29, 0x26},
		{0x58, 0x2a, 0x24},
		{0x58, 0x2b, 0x22},
		{0x58, 0x2c, 0x24},
		{0x58, 0x2d, 0x24},
		{0x58, 0x2e, 0x06},
		{0x58, 0x2f, 0x22},
		{0x58, 0x30, 0x40},
		{0x58, 0x31, 0x42},
		{0x58, 0x32, 0x24},
		{0x58, 0x33, 0x26},
		{0x58, 0x34, 0x24},
		{0x58, 0x35, 0x22},
		{0x58, 0x36, 0x22},
		{0x58, 0x37, 0x26},
		{0x58, 0x38, 0x44},
		{0x58, 0x39, 0x24},
		{0x58, 0x3a, 0x26},
		{0x58, 0x3b, 0x28},
		{0x58, 0x3c, 0x42},
		{0x58, 0x3d, 0xce},
		{0x51, 0x80, 0xff},
		{0x51, 0x81, 0xf2},
		{0x51, 0x82, 0x00},
		{0x51, 0x83, 0x14},
		{0x51, 0x84, 0x25},
		{0x51, 0x85, 0x24},
		{0x51, 0x86, 0x09},
		{0x51, 0x87, 0x09},
		{0x51, 0x88, 0x09},
		{0x51, 0x89, 0x75},
		{0x51, 0x8a, 0x54},
		{0x51, 0x8b, 0xe0},
		{0x51, 0x8c, 0xb2},
		{0x51, 0x8d, 0x42},
		{0x51, 0x8e, 0x3d},
		{0x51, 0x8f, 0x56},
		{0x51, 0x90, 0x46},
		{0x51, 0x91, 0xf8},
		{0x51, 0x92, 0x04},
		{0x51, 0x93, 0x70},
		{0x51, 0x94, 0xf0},
		{0x51, 0x95, 0xf0},
		{0x51, 0x96, 0x03},
		{0x51, 0x97, 0x01},
		{0x51, 0x98, 0x04},
		{0x51, 0x99, 0x12},
		{0x51, 0x9a, 0x04},
		{0x51, 0x9b, 0x00},
		{0x51, 0x9c, 0x06},
		{0x51, 0x9d, 0x82},
		{0x51, 0x9e, 0x38},
		{0x54, 0x80, 0x01},
		{0x54, 0x81, 0x08},
		{0x54, 0x82, 0x14},
		{0x54, 0x83, 0x28},
		{0x54, 0x84, 0x51},
		{0x54, 0x85, 0x65},
		{0x54, 0x86, 0x71},
		{0x54, 0x87, 0x7d},
		{0x54, 0x88, 0x87},
		{0x54, 0x89, 0x91},
		{0x54, 0x8a, 0x9a},
		{0x54, 0x8b, 0xaa},
		{0x54, 0x8c, 0xb8},
		{0x54, 0x8d, 0xcd},
		{0x54, 0x8e, 0xdd},
		{0x54, 0x8f, 0xea},
		{0x54, 0x90, 0x1d},
		{0x53, 0x81, 0x1e},
		{0x53, 0x82, 0x5b},
		{0x53, 0x83, 0x08},
		{0x53, 0x84, 0x0a},
		{0x53, 0x85, 0x7e},
		{0x53, 0x86, 0x88},
		{0x53, 0x87, 0x7c},
		{0x53, 0x88, 0x6c},
		{0x53, 0x89, 0x10},
		{0x53, 0x8a, 0x01},
		{0x53, 0x8b, 0x98},
		{0x55, 0x80, 0x06},
		{0x55, 0x83, 0x40},
		{0x55, 0x84, 0x10},
		{0x55, 0x89, 0x10},
		{0x55, 0x8a, 0x00},
		{0x55, 0x8b, 0xf8},
		{0x50, 0x1d, 0x40},
		{0x53, 0x00, 0x08},
		{0x53, 0x01, 0x30},
		{0x53, 0x02, 0x10},
		{0x53, 0x03, 0x00},
		{0x53, 0x04, 0x08},
		{0x53, 0x05, 0x30},
		{0x53, 0x06, 0x08},
		{0x53, 0x07, 0x16},
		{0x53, 0x09, 0x08},
		{0x53, 0x0a, 0x30},
		{0x53, 0x0b, 0x04},
		{0x53, 0x0c, 0x06},
		{0x50, 0x25, 0x00},
		{0x30, 0x08, 0x02},
		{0x30, 0x35, 0x41},
		{0x30, 0x36, 0x69},
		{0x3c, 0x07, 0x07},
		{0x38, 0x20, 0x45},
		{0x38, 0x21, 0x03},
		{0x38, 0x14, 0x31},
		{0x38, 0x15, 0x31},
		{0x38, 0x00, 0x00},
		{0x38, 0x01, 0x00},
		{0x38, 0x02, 0x00},
		{0x38, 0x03, 0xfa},
		{0x38, 0x04, 0x0a},
		{0x38, 0x05, 0x3f},
		{0x38, 0x06, 0x06},
		{0x38, 0x07, 0xa9},
		{0x38, 0x08, IMAGE_WIDTH>>8},
		{0x38, 0x09, 0x00ff & IMAGE_WIDTH},
		{0x38, 0x0a, IMAGE_HEIGHT>>8},
		{0x38, 0x0b, 0x00ff & IMAGE_HEIGHT},
		{0x38, 0x0c, 0x07},
		{0x38, 0x0d, 0x64},
		{0x38, 0x0e, 0x02},
		{0x38, 0x0f, 0xe4},
		{0x38, 0x13, 0x04},
		{0x36, 0x18, 0x00},
		{0x36, 0x12, 0x29},
		{0x37, 0x09, 0x52},
		{0x37, 0x0c, 0x03},
		{0x3a, 0x02, 0x02},
		{0x3a, 0x03, 0xe0},
		{0x3a, 0x14, 0x02},
		{0x3a, 0x15, 0xe0},
		{0x40, 0x04, 0x02},
		{0x30, 0x02, 0x1c},
		{0x30, 0x06, 0xc3},
		{0x47, 0x13, 0x03},
//		{0x47, 0x41, 0x00},//test_pattern
//		{0x50, 0x3d, 0x00},
		{0x44, 0x07, 0x04},
		{0x46, 0x0b, 0x37},
		{0x46, 0x0c, 0x20},
		{0x48, 0x37, 0x16},
		{0x38, 0x24, 0x04},
		{0x50, 0x01, 0x83},
		{0x35, 0x03, 0x00}
};
#endif /* SRC_IIC_CFG_REGS_H_ */

仿真波形

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值