|
本帖最后由 max 于 2012-4-21 13:17 编辑
没找到USB版,因为68013里有个增强的51,所以就发到51区了
根据本站一位网友的资料,使用68013+MT9M001制作了一个USB摄像头,按照网友的资料制作的是使MT9M001工作在snapshot模式,然后要采集图像的时候,通过USB的控制管道发命令来触发MT9M001采集一帧图片,在这种情况下,采集的图片的正常的。后来我使用libusb重写了上位机,测试时采集30帧使用了3秒时间。
然后我想连续采集,使MT9M001工作在连续模式,但这样采集的图片都是不正常的。尝试了一些方法,比如通过帧同步信号,在一帧结束的时候,再判断端点缓冲区空,然后通过中断通道向上位机发信号,上位机收到后再采集图片,这个方法得到的图片还是不正确的。然后又试了在一帧开始的时候发信号,上位机再接收,还是有问题。电路图与关键程序如下,请有熟悉的网友指点一下。谢谢
固件代码
- //初始化
- void TD_Init(void) // Called once at startup
- {
- // set the CPU clock to 48MHz
- CPUCS = ((CPUCS & ~bmCLKSPD) | bmCLKSPD1 | bmCLKOE) ;
- SYNCDELAY;
- // set the slave FIFO interface to 48MHz
- IFCONFIG = 0x43;
- SYNCDELAY;
- // configure REVCTL
- REVCTL = 0x03;
- SYNCDELAY;
- Rwuen = TRUE; // Enable remote-wakeup
- // Registers which require a synchronization delay, see section 15.14
- // FIFORESET FIFOPINPOLAR
- // INPKTEND OUTPKTEND
- // EPxBCH:L REVCTL
- // GPIFTCB3 GPIFTCB2
- // GPIFTCB1 GPIFTCB0
- // EPxFIFOPFH:L EPxAUTOINLENH:L
- // EPxFIFOCFG EPxGPIFFLGSEL
- // PINFLAGSxx EPxFIFOIRQ
- // EPxFIFOIE GPIFIRQ
- // GPIFIE GPIFADRH:L
- // UDMACRCH:L EPxGPIFTRIG
- // GPIFTRIG
-
- // Note: The pre-REVE EPxGPIFTCH/L register are affected, as well...
- // ...these have been replaced by GPIFTC[B3:B0] registers
- // default: all endpoints have their VALID bit set
- // default: TYPE1 = 1 and TYPE0 = 0 --> BULK
- // default: EP2 and EP4 DIR bits are 0 (OUT direction)
- // default: EP6 and EP8 DIR bits are 1 (IN direction)
- // default: EP2, EP4, EP6, and EP8 are double buffered
- // configure the OEx registers
- OED = 0xff;
- IOD = 0x80; //1000_0000, RESET=1, others=0
-
- // enable external interrup 0
- PORTACFG |= 1; // enable PA0 as INT0#
- IT0 = 1; //When ITx = 1, INTx# is edge-sensitive and the EZ-USB sets the IEx flag when the INTx# pin is sampled high then low on consecutive samples.
- EX0 = 1;
- //EZUSB_InitI2C(); // Initialize the hardware I2C controller
- //Set CMOS Sensor as Snapshot Mode
- //i2cdata[0] = 0x1e; //address
- //i2cdata[1] = 0x81; //1000_0001
- //i2cdata[2] = 0x00; //0000_0000
- // EZUSB_WriteI2C(CAM_ADDR, 3, i2cdata);
- // configure varies EndPoints
- EP1OUTCFG = (EP1OUTCFG & 0x7F); // default values...
- SYNCDELAY; // see TRM section 15.14
- EP1INCFG = 0xB0; // default values...en
- SYNCDELAY; // see TRM section 15.14
- EP2CFG = 0xE8; // enabled, quad buffered, 1024B, IN, bulk fifo
- SYNCDELAY; // see TRM section 15.14
- EP4CFG = (EP4CFG & 0x7F); // disabled...
- SYNCDELAY; // see TRM section 15.14
- EP6CFG = (EP6CFG & 0x7F); // disabled, quad buffered, 512B(?), OUT, bulk fifo
- SYNCDELAY; // see TRM section 15.14
- EP8CFG = (EP8CFG & 0x7F); // disabled...
- SYNCDELAY;
- // configure the EPxFIFOCFG
- EP2FIFOCFG = 0x08; // autoin, bytewide
- SYNCDELAY; // see TRM section 15.14
- SYNCDELAY;
- EP4FIFOCFG = 0x00;
- SYNCDELAY;
- SYNCDELAY;
- EP6FIFOCFG = 0x00; // no-autoOUT, bytewide
- SYNCDELAY;
- SYNCDELAY;
- EP8FIFOCFG = 0x00;
- SYNCDELAY;
- SYNCDELAY;
-
- FIFOPINPOLAR = 0x0F; // set SLWR, FF & EF active high, others active low
- SYNCDELAY;
-
- EP2AUTOINLENH = 0x04; // EZ-USB automatically commits data in 1024-byte chunks
- SYNCDELAY;
- EP2AUTOINLENL = 0x00;
- SYNCDELAY;
- // enable dual autopointer(s)
- AUTOPTRSETUP |= 0x01;
- // flaga - pf, flagb - full flag, flagc - empty flag
- //PINFLAGSAB = 0x8a;
- //PINFLAGSCD = 0x08;
- // reset all fifos
- FIFORESET = 0x80; // reset all FIFOs
- SYNCDELAY;
- FIFORESET = 0x02;
- SYNCDELAY;
- FIFORESET = 0x04;
- SYNCDELAY;
- FIFORESET = 0x06;
- SYNCDELAY;
- FIFORESET = 0x08;
- SYNCDELAY;
- FIFORESET = 0x00;
- SYNCDELAY;
- }
- //使用帧同步发信号
- void external_intr0(void) interrupt INT0_VECT
- {
- EP1INBUF[0] = 0;
- EP1INBUF[1] = 0xFF;
- EP1INBUF[2] = 0x88;
- //EP1INBUF[3] = 0;
- //EP1INBUF[4] = 0xFF;
- EP1INBC = 5;
- }
复制代码 libusb上位机程序
- unsigned char f_buf[5];
- //接收一帧开始的信号
- r = libusb_interrupt_transfer(devh, EP_INT, f_buf,5, &actual_length, 0);
- if (r < 0) {
- fprintf(stderr, "libusb interrupt transfer fail\n", r);
- goto out;
- }
- if (actual_length == 5 && f_buf[0] == 0 && f_buf[1] == 0xFF && f_buf[2] == 0x88/* && f_buf[3] == 0 && f_buf[4] == 0xFF */) {
- printf("frame header ok.\n");
- }
-
- //开始接收图像数据
- r = libusb_bulk_transfer(devh, EP_IN, ((struct my_bmp *)(bmp + 2))->data,1310720, &actual_length, 0);
复制代码 得到的图片如下
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|