I made Digital Camera using Arducam & WIZwiki-W7500
Dependencies: Arduino Arducam_OV5642 SDFileSystem Arducam_UTFT_SPI WIZnetInterface_Ricky mbed
main.cpp@2:3a12c5e8b030, 2015-10-29 (annotated)
- Committer:
- justinkim
- Date:
- Thu Oct 29 07:57:09 2015 +0000
- Revision:
- 2:3a12c5e8b030
- Parent:
- 1:3a14a4c84db2
- Child:
- 3:23d439c8526b
version0.1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
justinkim | 0:e01f64037748 | 1 | #include "mbed.h" |
justinkim | 0:e01f64037748 | 2 | #include "UTFT_SPI.h" |
justinkim | 0:e01f64037748 | 3 | #include "OV5642.h" |
justinkim | 0:e01f64037748 | 4 | #include "OV5642_regs.h" |
justinkim | 0:e01f64037748 | 5 | #include "Arduino.h" |
justinkim | 0:e01f64037748 | 6 | |
justinkim | 0:e01f64037748 | 7 | void setup(); |
justinkim | 0:e01f64037748 | 8 | void loop(); |
justinkim | 0:e01f64037748 | 9 | |
justinkim | 0:e01f64037748 | 10 | ArduCAM myCAM(D11, D12, D13, D10, D14, D15); |
justinkim | 1:3a14a4c84db2 | 11 | ArduLCD myGLCD(D11, D12, D13, D10); |
justinkim | 0:e01f64037748 | 12 | Serial pc(USBTX, USBRX); |
justinkim | 0:e01f64037748 | 13 | |
justinkim | 0:e01f64037748 | 14 | int main() |
justinkim | 0:e01f64037748 | 15 | { |
justinkim | 1:3a14a4c84db2 | 16 | *(volatile uint32_t *)(0x41001014) = 0x0060100; //clock 48MHz |
justinkim | 0:e01f64037748 | 17 | |
justinkim | 0:e01f64037748 | 18 | setup(); |
justinkim | 0:e01f64037748 | 19 | |
justinkim | 0:e01f64037748 | 20 | while(1) |
justinkim | 0:e01f64037748 | 21 | { |
justinkim | 0:e01f64037748 | 22 | loop(); |
justinkim | 0:e01f64037748 | 23 | } |
justinkim | 0:e01f64037748 | 24 | } |
justinkim | 0:e01f64037748 | 25 | |
justinkim | 0:e01f64037748 | 26 | void setup() |
justinkim | 0:e01f64037748 | 27 | { |
justinkim | 0:e01f64037748 | 28 | uint8_t vid,pid; |
justinkim | 0:e01f64037748 | 29 | uint8_t temp; |
justinkim | 0:e01f64037748 | 30 | |
justinkim | 0:e01f64037748 | 31 | pc.baud(115200); |
justinkim | 0:e01f64037748 | 32 | pc.printf("ArduCAM Start!\r\n"); |
justinkim | 1:3a14a4c84db2 | 33 | |
justinkim | 1:3a14a4c84db2 | 34 | uint8_t temp1,temp2; |
justinkim | 1:3a14a4c84db2 | 35 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); //Write to test1 register by 0x55 |
justinkim | 1:3a14a4c84db2 | 36 | myCAM.write_reg(ARDUCHIP_TEST2, 0xAA); //Write to test1 register by 0xaa |
justinkim | 1:3a14a4c84db2 | 37 | wait_ms(1000); |
justinkim | 1:3a14a4c84db2 | 38 | temp1 = myCAM.read_reg(ARDUCHIP_TEST1); //Read from test1 register |
justinkim | 1:3a14a4c84db2 | 39 | temp2 = myCAM.read_reg(ARDUCHIP_TEST2); //Read from test1 register |
justinkim | 1:3a14a4c84db2 | 40 | pc.printf("temp1 : %d\r\n",temp1); |
justinkim | 1:3a14a4c84db2 | 41 | pc.printf("temp2 : %d\r\n",temp2); |
justinkim | 1:3a14a4c84db2 | 42 | wait_ms(1000); |
justinkim | 1:3a14a4c84db2 | 43 | |
justinkim | 0:e01f64037748 | 44 | myCAM.write_reg(ARDUCHIP_TEST1, 0x55); |
justinkim | 0:e01f64037748 | 45 | temp = myCAM.read_reg(ARDUCHIP_TEST1); |
justinkim | 1:3a14a4c84db2 | 46 | |
justinkim | 0:e01f64037748 | 47 | if(temp != 0x55) |
justinkim | 0:e01f64037748 | 48 | { |
justinkim | 0:e01f64037748 | 49 | pc.printf("SPI interface Error!\r\n"); |
justinkim | 0:e01f64037748 | 50 | while(1); |
justinkim | 0:e01f64037748 | 51 | } |
justinkim | 0:e01f64037748 | 52 | |
justinkim | 0:e01f64037748 | 53 | //Change MCU mode |
justinkim | 0:e01f64037748 | 54 | myCAM.set_mode(MCU2LCD_MODE); |
justinkim | 0:e01f64037748 | 55 | |
justinkim | 0:e01f64037748 | 56 | //Initialize the LCD Module |
justinkim | 1:3a14a4c84db2 | 57 | myGLCD.InitLCD(); |
justinkim | 0:e01f64037748 | 58 | |
justinkim | 0:e01f64037748 | 59 | //Check if the camera module type is OV5642 |
justinkim | 0:e01f64037748 | 60 | myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid); |
justinkim | 0:e01f64037748 | 61 | myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid); |
justinkim | 0:e01f64037748 | 62 | if((vid != 0x56) || (pid != 0x42)) |
justinkim | 0:e01f64037748 | 63 | pc.printf("Can't find OV5642 module!\r\n"); |
justinkim | 0:e01f64037748 | 64 | else |
justinkim | 0:e01f64037748 | 65 | pc.printf("OV5642 detected\r\n"); |
justinkim | 0:e01f64037748 | 66 | |
justinkim | 0:e01f64037748 | 67 | myCAM.InitCAM(); |
justinkim | 0:e01f64037748 | 68 | } |
justinkim | 0:e01f64037748 | 69 | |
justinkim | 0:e01f64037748 | 70 | void loop() |
justinkim | 0:e01f64037748 | 71 | { |
justinkim | 0:e01f64037748 | 72 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM |
justinkim | 0:e01f64037748 | 73 | |
justinkim | 0:e01f64037748 | 74 | while(1) |
justinkim | 0:e01f64037748 | 75 | { |
justinkim | 0:e01f64037748 | 76 | |
justinkim | 0:e01f64037748 | 77 | if(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)) //New Frame is coming |
justinkim | 0:e01f64037748 | 78 | { |
justinkim | 0:e01f64037748 | 79 | myCAM.set_mode(MCU2LCD_MODE); //Switch to MCU |
justinkim | 1:3a14a4c84db2 | 80 | myGLCD.resetXY(); |
justinkim | 0:e01f64037748 | 81 | myCAM.set_mode(CAM2LCD_MODE); //Switch to CAM |
justinkim | 0:e01f64037748 | 82 | while(!myCAM.get_bit(ARDUCHIP_TRIG,VSYNC_MASK)); //Wait for VSYNC is gone |
justinkim | 0:e01f64037748 | 83 | } |
justinkim | 0:e01f64037748 | 84 | } |
justinkim | 0:e01f64037748 | 85 | } |