硬件准备
ADSP-EDU-BF533:BF533开发板
AD-HP530ICE:ADI DSP仿真器
软件准备
Visual DSP++软件
硬件链接
功能介绍
板卡上设计了一个摄像头接口,可以连接与板卡匹配的 ADSP-EDU-CMOS 子卡板。摄像头接口采用 20PIN 插针接入,将插针的 PIN3 脚剪去,摄像头子卡板对应的接口被堵上,以防止摄像头板卡反向插入。
ADSP-EDU-CMOS 子卡板采用了 OV9650 CMOS 感光芯片的模组,OV9650 为 OmniVision 公司生产的 130 万像素的摄像头芯片,其最大成像点阵为 1300*1028,其具体参数如表:
OV9650 IIC 器件地址: Slave address W 为 60H ,Slave address R 为 61H
CMOS 和 LCD 公用一个 PPI 接口,采用 CPLD 来切换 PPI 时钟
DEVICE_OE 寄存器(读/写):
DEVICE_OE 寄存器地址:0x20320000
DEVICE_OE 寄存器设置硬件设备上一些控制管脚的电平状态。
DEVICE_OE 寄存器位功能:
PPI_SET1~0:PPI 选择位
00:选通 CMOS PPI 时钟,使能 CMOS
01:选通 TFT PPI 时钟
选通 板卡为扩展接口的 PPICLK 提供时钟
1x:选通 PPI 时钟由扩展接口输入
选通摄像头需将 PPI_SET0 位设置为 0,PPI_SET1 位设置为 0。
硬件连接示意图
硬件原理图
代码实现功能
代码实现了通过配置 PPI 接口和摄像头,从摄像头采集一幅图像放置到指定的内存中,通过 Visual DSP ++软件的 image viwe 工具,将数据还原为图像。
测试步骤
1. 将仿真器(ICE)与 ADSP-EDU-BF53x 开发板和计算机连接好,将 ADSP-EDU-CMOS 子卡板镜头朝板外接入摄像头接口。
2. 先给 ADSP-EDU-BF53x 开发板上电,再为仿真器(ICE)上电。
3. 运行 VisualDSP++ 5.0 软件,选择合适的 BF53x 的 session 将仿真器与软件连接。
4. 加载 VisualDSP++ 5.0 工程文件 BF53x_CMOS.dpj 文件,编译并全速运行。
测试结果
1.当看到如下信息打印时,将代码停止,选择 Visual DSP++5.0 菜单下“View -->DebugWindows–>image viewer…”选项。
2. 按下图配置选项:
3.点“OK”后会弹出图像输出窗口,待刷新进度到 100%后,即可看到拍到的图片
程序源码
cmos.c
#include
#include"i2c.h"
#define OV9653_ADDRESS 0x60
static i2c_device mcu_i2c;
void init_OV9653(void);
int ov9653_write(unsigned char addr, unsigned char dat);
int ov9653_read(unsigned char addr, unsigned char * buf);
/****************************************************************************
/****************************************************************************
名称 :Init_OV9653
功能 : CMOS 130万 内部寄存器配置信息
入口参数 :无
出口参数 :无
****************************************************************************/
void init_OV9653(void)
{
mcu_i2c.sclk = PF0; //时钟PF脚
mcu_i2c.sdata = PF1; //数据PF脚
mcu_i2c.low_ns = 7000; //低电平延时 ns
mcu_i2c.high_ns = 6000; //高电平延时 ns
i2c_init(&mcu_i2c);
ov9653_write(0x12,0x80);
ov9653_write(0x12,0x80);
ov9653_write(0x11,0x81);
ov9653_write(0x6b,0x0a);
ov9653_write(0x6a,0x3e);
ov9653_write(0x3b,0x09);
ov9653_write(0x13,0xe0);
ov9653_write(0x01,0x80);
ov9653_write(0x02,0x80);
ov9653_write(0x00,0x00);
ov9653_write(0x10,0x00);
ov9653_write(0x13,0xe5);
ov9653_write(0x39,0x43);
ov9653_write(0x38,0x12);
ov9653_write(0x37,0x00);
ov9653_write(0x35,0x91);
ov9653_write(0x0e,0x20);
ov9653_write(0x1e,0x34);
ov9653_write(0xA8,0x80);
ov9653_write(0x12,0x40);
ov9653_write(0x04,0x00);
ov9653_write(0x0c,0x04);
ov9653_write(0x0d,0x80);
ov9653_write(0x18,0xc6);
ov9653_write(0x17,0x26);
ov9653_write(0x32,0xad);
ov9653_write(0x03,0x00);
ov9653_write(0x1a,0x3d);
ov9653_write(0x19,0x01);
ov9653_write(0x3f,0xa6);
ov9653_write(0x14,0x1a);
ov9653_write(0x15,0x02);
ov9653_write(0x41,0x12);
ov9653_write(0x42,0x08);
ov9653_write(0x1b,0x00);
ov9653_write(0x16,0x06);
ov9653_write(0x33,0xe2);
ov9653_write(0x49,0x60);
ov9653_write(0x34,0x16);
ov9653_write(0x96,0x04);
ov9653_write(0x3a,0x00);
ov9653_write(0x8e,0x00);
ov9653_write(0x3c,0x77);
ov9653_write(0x8B,0x06);
ov9653_write(0x94,0x88);
ov9653_write(0x95,0x88);
ov9653_write(0x40,0xc1);
ov9653_write(0x29,0x3f);
ov9653_write(0x0f,0x42);
ov9653_write(0x3d,0x92);
ov9653_write(0x69,0x40);
ov9653_write(0x5C,0xb9);
ov9653_write(0x5D,0x96);
ov9653_write(0x5E,0x10);
ov9653_write(0x59,0xc0);
ov9653_write(0x5A,0xaf);
ov9653_write(0x5B,0x55);
ov9653_write(0x43,0xf0);
ov9653_write(0x44,0x10);
ov9653_write(0x45,0x68);
ov9653_write(0x46,0x96);
ov9653_write(0x47,0x60);
ov9653_write(0x48,0x80);
ov9653_write(0x5F,0xe0);
ov9653_write(0x60,0x8c);
ov9653_write(0x61,0x20);
ov9653_write(0xa5,0xd9);
ov9653_write(0xa4,0x74);
ov9653_write(0x8d,0xc2);
ov9653_write(0x13,0xe7);
ov9653_write(0x4f,0x3a);
ov9653_write(0x50,0x3d);
ov9653_write(0x51,0x03);
ov9653_write(0x52,0x12);
ov9653_write(0x53,0x26);
ov9653_write(0x54,0x38);
ov9653_write(0x55,0x40);
ov9653_write(0x56,0x40);
ov9653_write(0x57,0x40);
ov9653_write(0x58,0x0d);
ov9653_write(0x8C,0x23);
ov9653_write(0x3E,0x02);
ov9653_write(0xa9,0xb8);
ov9653_write(0xaa,0x92);
ov9653_write(0xab,0x0a);
ov9653_write(0x8f,0xdf);
ov9653_write(0x90,0x00);
ov9653_write(0x91,0x00);
ov9653_write(0x9f,0x00);
ov9653_write(0xa0,0x00);
ov9653_write(0x3A,0x01);
ov9653_write(0x24,0x80);
ov9653_write(0x25,0x70);
ov9653_write(0x26,0xd3);
ov9653_write(0x2a,0x10);
ov9653_write(0x2b,0x40);
ov9653_write(0x6c,0x40);
ov9653_write(0x6d,0x30);
ov9653_write(0x6e,0x4b);
ov9653_write(0x6f,0x60);
ov9653_write(0x70,0x70);
ov9653_write(0x71,0x70);
ov9653_write(0x72,0x70);
ov9653_write(0x73,0x70);
ov9653_write(0x74,0x60);
ov9653_write(0x75,0x60);
ov9653_write(0x76,0x50);
ov9653_write(0x77,0x48);
ov9653_write(0x78,0x3a);
ov9653_write(0x79,0x2e);
ov9653_write(0x7a,0x28);
ov9653_write(0x7b,0x22);
ov9653_write(0x7c,0x04);
ov9653_write(0x7d,0x07);
ov9653_write(0x7e,0x10);
ov9653_write(0x7f,0x28);
ov9653_write(0x80,0x36);
ov9653_write(0x81,0x44);
ov9653_write(0x82,0x52);
ov9653_write(0x83,0x60);
ov9653_write(0x84,0x6c);
ov9653_write(0x85,0x78);
ov9653_write(0x86,0x8c);
ov9653_write(0x87,0x9e);
ov9653_write(0x88,0xbb);
ov9653_write(0x89,0xd2);
ov9653_write(0x8a,0xe6);
}
cpu.c
#include
/**********************************************************************************
/****************************************************************************
void Init_EBIU(void)
{
*pEBIU_AMBCTL0 = 0x7bb07bb0;
*pEBIU_AMBCTL1 = 0xffc0ffc0;
*pEBIU_AMGCTL = 0x000f;
}
/****************************************************************************
/****************************************************************************
iic.c
#include
#include “i2c.h”
#define CORE_CLK_IN 25 * 1000 * 1000
#define SET_PF(pf)
do{
*pFIO_FLAG_S = (pf);
ssync();
}while(0)
#define CLR_PF(pf)
do{
*pFIO_FLAG_C = (pf);
ssync();
}while(0)
#define SET_PF_OUTPUT(pf)
do{
*pFIO_INEN &= ~(pf);
*pFIO_DIR |= (pf);
ssync();
}while(0)
#define SET_PF_INPUT(pf)
do{
*pFIO_DIR &= ~(pf);
*pFIO_INEN |= (pf);
ssync();
}while(0)
int get_core_clk(void)
{
int tempPLLCTL;
int _DF;
int VCO;
int MSEL1;
tempPLLCTL = *pPLL_CTL;
MSEL1 = ((tempPLLCTL & 0x7E00) >> 9);
_DF = tempPLLCTL & 0x0001;
VCO = MSEL1 * __CORE_CLK_IN__;
if(_DF == 1)
VCO /= 2;
return VCO;
}
void delay_ns(unsigned int core_clock, unsigned long long count)
{
count *= core_clock;
count /= 1000000000;
while(count–);
}
int _get_sdata(i2c_device * dev)
{
return ((*pFIO_FLAG_D & dev->sdata) ? 1 : 0);
}
void i2c_init(i2c_device * dev)
{
dev->core_clock = get_core_clk();
dev->delay_ns = delay_ns;
*pFIO_DIR |= dev->sclk | dev->sdata;
ssync();
}
void i2c_deinit(i2c_device * dev)
{
dev->sclk = 0;
dev->sdata = 0;
*pFIO_DIR &= ~(dev->sclk | dev->sdata);
ssync();
}
void i2c_start(i2c_device * dev)
{
SET_PF_OUTPUT(dev->sdata);
SET_PF_OUTPUT(dev->sclk);
SET_PF(dev->sdata);
SET_PF(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns);
CLR_PF(dev->sdata);
delay_ns(dev->core_clock, dev->low_ns);
CLR_PF(dev->sclk);
delay_ns(dev->core_clock, dev->low_ns);
}
void i2c_stop(i2c_device * dev)
{
CLR_PF(dev->sclk);
delay_ns(dev->core_clock, dev->low_ns);
SET_PF_OUTPUT(dev->sdata);
CLR_PF(dev->sdata);
delay_ns(dev->core_clock, dev->low_ns);
SET_PF_INPUT(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns);
SET_PF_INPUT(dev->sdata);
delay_ns(dev->core_clock, dev->high_ns);
}
int i2c_read_ack(i2c_device * dev)
{
int ret = 0;
SET_PF_INPUT(dev->sdata);
delay_ns(dev->core_clock, dev->high_ns/3);
SET_PF(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns/3);
ret = _get_sdata(dev);
delay_ns(dev->core_clock, dev->high_ns/3);
CLR_PF(dev->sclk);
delay_ns(dev->core_clock, dev->low_ns);
SET_PF_OUTPUT(dev->sdata);
return ret;
}
int i2c_wait_slave(i2c_device * dev, unsigned int time_out)
{
int ret;
int count = time_out * 2 / dev->high_ns;
SET_PF_INPUT(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns/2);
do{
ret = *pFIO_FLAG_D & dev->sclk;
if(ret)
break;
delay_ns(dev->core_clock, dev->high_ns/2);
}while(count--);
SET_PF_OUTPUT(dev->sclk);
return !ret;
}
void i2c_write_ack(i2c_device * dev)
{
SET_PF_OUTPUT(dev->sdata);
CLR_PF(dev->sdata);
delay_ns(dev->core_clock, dev->high_ns/2);
SET_PF(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns);
CLR_PF(dev->sclk);
delay_ns(dev->core_clock, dev->low_ns);
}
int i2c_write(i2c_device * dev, unsigned char value, int need_ack)
{
int ret = -1;
unsigned char index;
SET_PF_OUTPUT(dev->sdata);
//send 8 bits to slave
for(index = 0; index < 8; index++){
//send one bit to the i2c bus
if((value<sdata);
} else {
CLR_PF(dev->sdata);
}
delay_ns(dev->core_clock, dev->low_ns/2);
SET_PF(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns);
CLR_PF(dev->sclk);
delay_ns(dev->core_clock, dev->low_ns/2);
}
if(need_ack){
ret = i2c_read_ack(dev);
}
return ret;
}
int i2c_read(i2c_device * dev, unsigned char * value, int send_ack)
{
unsigned char index;
*value = 0x00;
SET_PF_INPUT(dev->sdata);
delay_ns(dev->core_clock, dev->high_ns/2);
//get 8 bits from the device
for(index = 0; index < 8; index++){
SET_PF(dev->sclk);
delay_ns(dev->core_clock, dev->high_ns/2);
*value <<= 1;
*value |= _get_sdata(dev);
delay_ns(dev->core_clock, dev->high_ns/2);
CLR_PF(dev->sclk);
delay_ns(dev->core_clock, dev->low_ns);
}
// send ack to slave
if(send_ack){
i2c_write_ack(dev);
}
return *value;
}
main.c
#include
/****************************************************************************
ppi.c
#include
#include
EX_INTERRUPT_HANDLER(DMA0_PPI_ISR);
/****************************************************************************
/****************************************************************************
/****************************************************************************
EX_INTERRUPT_HANDLER(DMA0_PPI_ISR)
{
*pDMA0_IRQ_STATUS = 0x1;
*pPPI_CONTROL &= 0xfffe;
printf( “\nSuccess Capture One Frame: 640 * 480\n”);
printf( " YUYV422(YUV422) Format\n" );
printf( " The data address is 0 \n" );
}