capstone_finish
Dependencies: BufferedSerial motor_sn7544
Diff: ov7670.h
- Revision:
- 4:7b63cf3d205f
- Parent:
- 3:2a3664dc6634
- Child:
- 5:53dd2abce6b3
--- a/ov7670.h Tue Aug 13 05:53:22 2019 +0000 +++ b/ov7670.h Tue Aug 13 06:01:16 2019 +0000 @@ -6,7 +6,7 @@ #define OV7670_WRITEWAIT (20) #define OV7670_NOACK (0) #define OV7670_REGMAX (201) -#define OV7670_I2CFREQ (50000) +#define OV7670_I2CFREQ (40000) // // OV7670 + FIFO AL422B camera board test @@ -14,7 +14,7 @@ class OV7670 { public: - I2C camera ; + I2C _i2c ; InterruptIn vsync,href; DigitalOut wen ; PortIn data ; @@ -36,10 +36,10 @@ PinName rt, // /RRST PinName o, // /OE PinName rc // RCLK - ) : camera(sda,scl),vsync(vs),href(hr),wen(we),data(port,mask),rrst(rt),oe(o),rclk(rc) + ) : _i2c(sda,scl),vsync(vs),href(hr),wen(we),data(port,mask),rrst(rt),oe(o),rclk(rc) { - camera.stop() ; - camera.frequency(OV7670_I2CFREQ) ; + _i2c.stop() ; + _i2c.frequency(OV7670_I2CFREQ) ; vsync.fall(this,&OV7670::VsyncHandler) ; href.rise(this,&OV7670::HrefHandler) ; CaptureReq = false ; @@ -75,36 +75,32 @@ // write to camera void WriteReg(int addr,int data) { - // WRITE 0x42,ADDR,DATA - camera.start() ; - camera.write(OV7670_WRITE) ; - wait_us(OV7670_WRITEWAIT); - camera.write(addr) ; - wait_us(OV7670_WRITEWAIT); - camera.write(data) ; - camera.stop() ; + int status; + char data_write[2]; + data_write[0]= addr; + data_write[1]= data; + status = _i2c.write(OV7670_WRITE,data_write,2,0); + if(status!=0){ +// printf("I2C configuration error(adr: %x)!\r\n",addr); + while(1){ + } + } } // read from camera int ReadReg(int addr) { - int data ; - - // WRITE 0x42,ADDR - camera.start() ; - camera.write(OV7670_WRITE) ; - wait_us(OV7670_WRITEWAIT); - camera.write(addr) ; - camera.stop() ; - wait_us(OV7670_WRITEWAIT); - - // WRITE 0x43,READ - camera.start() ; - camera.write(OV7670_READ) ; - wait_us(OV7670_WRITEWAIT); - data = camera.read(OV7670_NOACK) ; - camera.stop() ; - + char data_write[2]; + char data_read[2]; + int data; + int status; + + data_write[0]=addr; + _i2c.write(OV7670_WRITE, data_write, 1, 0); + status =_i2c.read(OV7670_READ, data_read, 1, 0); + data = (int)data_read[0]; + // printf("Data is %x\r\n",data); +// printf("Status is %d\r\n",status); return data ; } @@ -211,6 +207,13 @@ } void InitQVGAYUV(bool flipv,bool fliph) { + if (ReadReg(REG_PID) != 0x76) // check id camera + { + printf("ERROR\r\n"); + }else{ + + printf("SUCCESS\r\n"); + } WriteReg(REG_COM7, 0x00); // YUV WriteReg(REG_COM17, 0x00); // color bar disable WriteReg(REG_COM3, 0x0C); @@ -433,7 +436,7 @@ } // Data Read (PortIn) - int ReadOneWord(void) //2byte + int ReadOneWord(void) { // int r,r1,r2,r3,r4 ; // rclk = 1 ;