Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.22 KB | None | 0 0
  1. // ArduCAM Mini demo (C)2017 Lee
  2. // Web: http://www.ArduCAM.com
  3. // This program is a demo of how to use most of the functions
  4. // of the library with ArduCAM Mini camera, and can run on any Arduino platform.
  5. // This demo was made for ArduCAM_Mini_2MP_Plus.
  6. // It needs to be used in combination with PC software.
  7. // It can test OV2640 functions
  8. // This program requires the ArduCAM V4.0.0 (or later) library and ArduCAM_Mini_2MP_Plus
  9. // and use Arduino IDE 1.6.8 compiler or above
  10. #include <Wire.h>
  11. #include <ArduCAM.h>
  12. #include <SPI.h>
  13. #include "memorysaver.h"
  14. //This demo can only work on OV2640_MINI_2MP_PLUS platform.
  15. #if !(defined OV2640_MINI_2MP_PLUS)
  16. #error Please select the hardware platform and camera module in the ../libraries/ArduCAM/memorysaver.h file
  17. #endif
  18. #define BMPIMAGEOFFSET 66
  19. const char bmp_header[BMPIMAGEOFFSET] PROGMEM =
  20. {
  21. 0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00,
  22. 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
  23. 0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00,
  24. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00,
  25. 0x00, 0x00
  26. };
  27. // set pin 7 as the slave select for the digital pot:
  28. const int CS = 10;
  29. bool is_header = false;
  30. int mode = 0;
  31. uint8_t start_capture = 0;
  32. #if defined (OV2640_MINI_2MP_PLUS)
  33. ArduCAM myCAM( OV2640, CS );
  34. #else
  35. ArduCAM myCAM( OV5642, CS );
  36. #endif
  37. uint8_t read_fifo_burst(ArduCAM myCAM);
  38. void setup() {
  39. // put your setup code here, to run once:
  40. uint8_t vid, pid;
  41. uint8_t temp;
  42. #if defined(__SAM3X8E__)
  43. Wire1.begin();
  44. Serial.begin(115200);
  45. #else
  46. Wire.begin();
  47. Serial.begin(921600);
  48. #endif
  49. Serial.println(F("ACK CMD ArduCAM Start! END"));
  50. // set the CS as an output:
  51. pinMode(CS, OUTPUT);
  52. digitalWrite(CS, HIGH);
  53. // initialize SPI:
  54. SPI.begin();
  55. //Reset the CPLD
  56. myCAM.write_reg(0x07, 0x80);
  57. delay(100);
  58. myCAM.write_reg(0x07, 0x00);
  59. delay(100);
  60. while(1){
  61. //Check if the ArduCAM SPI bus is OK
  62. myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
  63. temp = myCAM.read_reg(ARDUCHIP_TEST1);
  64. if (temp != 0x55){
  65. Serial.println(F("ACK CMD SPI interface Error! END"));
  66. delay(1000);continue;
  67. }else{
  68. Serial.println(F("ACK CMD SPI interface OK. END"));break;
  69. }
  70. }
  71.  
  72. #if defined (OV2640_MINI_2MP_PLUS)
  73. while(1){
  74. //Check if the camera module type is OV2640
  75. myCAM.wrSensorReg8_8(0xff, 0x01);
  76. myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
  77. myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
  78. if ((vid != 0x26 ) && (( pid != 0x41 ) || ( pid != 0x42 ))){
  79. Serial.println(F("ACK CMD Can't find OV2640 module! END"));
  80. delay(1000);continue;
  81. }
  82. else{
  83. Serial.println(F("ACK CMD OV2640 detected. END"));break;
  84. }
  85. }
  86. #else
  87. while(1){
  88. //Check if the camera module type is OV5642
  89. myCAM.wrSensorReg16_8(0xff, 0x01);
  90. myCAM.rdSensorReg16_8(OV5642_CHIPID_HIGH, &vid);
  91. myCAM.rdSensorReg16_8(OV5642_CHIPID_LOW, &pid);
  92. if((vid != 0x56) || (pid != 0x42)){
  93. Serial.println(F("ACK CMD Can't find OV5642 module! END"));
  94. delay(1000);continue;
  95. }
  96. else{
  97. Serial.println(F("ACK CMD OV5642 detected. END"));break;
  98. }
  99. }
  100. #endif
  101. //Change to JPEG capture mode and initialize the OV5642 module
  102. myCAM.set_format(JPEG);
  103. myCAM.InitCAM();
  104. #if defined (OV2640_MINI_2MP_PLUS)
  105. myCAM.OV2640_set_JPEG_size(OV2640_320x240);
  106. #else
  107. myCAM.write_reg(ARDUCHIP_TIM, VSYNC_LEVEL_MASK); //VSYNC is active HIGH
  108. myCAM.OV5642_set_JPEG_size(OV5642_320x240);
  109. #endif
  110. delay(1000);
  111. myCAM.clear_fifo_flag();
  112. #if !(defined (OV2640_MINI_2MP_PLUS))
  113. myCAM.write_reg(ARDUCHIP_FRAMES,0x00);
  114. #endif
  115. }
  116. void loop() {
  117. // put your main code here, to run repeatedly:
  118. uint8_t temp = 0xff, temp_last = 0;
  119. bool is_header = false;
  120. if (Serial.available())
  121. {
  122. temp = Serial.read();
  123. switch (temp)
  124. {
  125. case 0:
  126. myCAM.OV2640_set_JPEG_size(OV2640_160x120);delay(1000);
  127. Serial.println(F("ACK CMD switch to OV2640_160x120 END"));
  128. temp = 0xff;
  129. break;
  130. case 1:
  131. myCAM.OV2640_set_JPEG_size(OV2640_176x144);delay(1000);
  132. Serial.println(F("ACK CMD switch to OV2640_176x144 END"));
  133. temp = 0xff;
  134. break;
  135. case 2:
  136. myCAM.OV2640_set_JPEG_size(OV2640_320x240);delay(1000);
  137. Serial.println(F("ACK CMD switch to OV2640_320x240 END"));
  138. temp = 0xff;
  139. break;
  140. case 3:
  141. myCAM.OV2640_set_JPEG_size(OV2640_352x288);delay(1000);
  142. Serial.println(F("ACK CMD switch to OV2640_352x288 END"));
  143. temp = 0xff;
  144. break;
  145. case 4:
  146. myCAM.OV2640_set_JPEG_size(OV2640_640x480);delay(1000);
  147. Serial.println(F("ACK CMD switch to OV2640_640x480 END"));
  148. temp = 0xff;
  149. break;
  150. case 5:
  151. myCAM.OV2640_set_JPEG_size(OV2640_800x600);delay(1000);
  152. Serial.println(F("ACK CMD switch to OV2640_800x600 END"));
  153. temp = 0xff;
  154. break;
  155. case 6:
  156. myCAM.OV2640_set_JPEG_size(OV2640_1024x768);delay(1000);
  157. Serial.println(F("ACK CMD switch to OV2640_1024x768 END"));
  158. temp = 0xff;
  159. break;
  160. case 7:
  161. myCAM.OV2640_set_JPEG_size(OV2640_1280x1024);delay(1000);
  162. Serial.println(F("ACK CMD switch to OV2640_1280x1024 END"));
  163. temp = 0xff;
  164. break;
  165. case 8:
  166. myCAM.OV2640_set_JPEG_size(OV2640_1600x1200);delay(1000);
  167. Serial.println(F("ACK CMD switch to OV2640_1600x1200 END"));
  168. temp = 0xff;
  169. break;
  170. case 0x10:
  171. mode = 1;
  172. temp = 0xff;
  173. start_capture = 1;
  174. Serial.println(F("ACK CMD CAM start single shoot. END"));
  175. break;
  176. case 0x11:
  177. temp = 0xff;
  178. myCAM.set_format(JPEG);
  179. myCAM.InitCAM();
  180. #if !(defined (OV2640_MINI_2MP_PLUS))
  181. myCAM.set_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
  182. #endif
  183. break;
  184. case 0x20:
  185. mode = 2;
  186. temp = 0xff;
  187. start_capture = 2;
  188. Serial.println(F("ACK CMD CAM start video streaming. END"));
  189. break;
  190. case 0x30:
  191. mode = 3;
  192. temp = 0xff;
  193. start_capture = 3;
  194. Serial.println(F("ACK CMD CAM start single shoot. END"));
  195. break;
  196. case 0x31:
  197. temp = 0xff;
  198. myCAM.set_format(BMP);
  199. myCAM.InitCAM();
  200. #if !(defined (OV2640_MINI_2MP_PLUS))
  201. myCAM.clear_bit(ARDUCHIP_TIM, VSYNC_LEVEL_MASK);
  202. #endif
  203. myCAM.wrSensorReg16_8(0x3818, 0x81);
  204. myCAM.wrSensorReg16_8(0x3621, 0xA7);
  205. break;
  206. case 0x40:
  207. myCAM.OV2640_set_Light_Mode(Auto);temp = 0xff;
  208. Serial.println(F("ACK CMD Set to Auto END"));break;
  209. case 0x41:
  210. myCAM.OV2640_set_Light_Mode(Sunny);temp = 0xff;
  211. Serial.println(F("ACK CMD Set to Sunny END"));break;
  212. case 0x42:
  213. myCAM.OV2640_set_Light_Mode(Cloudy);temp = 0xff;
  214. Serial.println(F("ACK CMD Set to Cloudy END"));break;
  215. case 0x43:
  216. myCAM.OV2640_set_Light_Mode(Office);temp = 0xff;
  217. Serial.println(F("ACK CMD Set to Office END"));break;
  218. case 0x44:
  219. myCAM.OV2640_set_Light_Mode(Home); temp = 0xff;
  220. Serial.println(F("ACK CMD Set to Home END"));break;
  221. case 0x50:
  222. myCAM.OV2640_set_Color_Saturation(Saturation2); temp = 0xff;
  223. Serial.println(F("ACK CMD Set to Saturation+2 END"));break;
  224. case 0x51:
  225. myCAM.OV2640_set_Color_Saturation(Saturation1); temp = 0xff;
  226. Serial.println(F("ACK CMD Set to Saturation+1 END"));break;
  227. case 0x52:
  228. myCAM.OV2640_set_Color_Saturation(Saturation0); temp = 0xff;
  229. Serial.println(F("ACK CMD Set to Saturation+0 END"));break;
  230. case 0x53:
  231. myCAM. OV2640_set_Color_Saturation(Saturation_1); temp = 0xff;
  232. Serial.println(F("ACK CMD Set to Saturation-1 END"));break;
  233. case 0x54:
  234. myCAM.OV2640_set_Color_Saturation(Saturation_2); temp = 0xff;
  235. Serial.println(F("ACK CMD Set to Saturation-2 END"));break;
  236. case 0x60:
  237. myCAM.OV2640_set_Brightness(Brightness2); temp = 0xff;
  238. Serial.println(F("ACK CMD Set to Brightness+2 END"));break;
  239. case 0x61:
  240. myCAM.OV2640_set_Brightness(Brightness1); temp = 0xff;
  241. Serial.println(F("ACK CMD Set to Brightness+1 END"));break;
  242. case 0x62:
  243. myCAM.OV2640_set_Brightness(Brightness0); temp = 0xff;
  244. Serial.println(F("ACK CMD Set to Brightness+0 END"));break;
  245. case 0x63:
  246. myCAM. OV2640_set_Brightness(Brightness_1); temp = 0xff;
  247. Serial.println(F("ACK CMD Set to Brightness-1 END"));break;
  248. case 0x64:
  249. myCAM.OV2640_set_Brightness(Brightness_2); temp = 0xff;
  250. Serial.println(F("ACK CMD Set to Brightness-2 END"));break;
  251. case 0x70:
  252. myCAM.OV2640_set_Contrast(Contrast2);temp = 0xff;
  253. Serial.println(F("ACK CMD Set to Contrast+2 END"));break;
  254. case 0x71:
  255. myCAM.OV2640_set_Contrast(Contrast1);temp = 0xff;
  256. Serial.println(F("ACK CMD Set to Contrast+1 END"));break;
  257. case 0x72:
  258. myCAM.OV2640_set_Contrast(Contrast0);temp = 0xff;
  259. Serial.println(F("ACK CMD Set to Contrast+0 END"));break;
  260. case 0x73:
  261. myCAM.OV2640_set_Contrast(Contrast_1);temp = 0xff;
  262. Serial.println(F("ACK CMD Set to Contrast-1 END"));break;
  263. case 0x74:
  264. myCAM.OV2640_set_Contrast(Contrast_2);temp = 0xff;
  265. Serial.println(F("ACK CMD Set to Contrast-2 END"));break;
  266. case 0x80:
  267. myCAM.OV2640_set_Special_effects(Antique);temp = 0xff;
  268. Serial.println(F("ACK CMD Set to Antique END"));break;
  269. case 0x81:
  270. myCAM.OV2640_set_Special_effects(Bluish);temp = 0xff;
  271. Serial.println(F("ACK CMD Set to Bluish END"));break;
  272. case 0x82:
  273. myCAM.OV2640_set_Special_effects(Greenish);temp = 0xff;
  274. Serial.println(F("ACK CMD Set to Greenish END"));break;
  275. case 0x83:
  276. myCAM.OV2640_set_Special_effects(Reddish);temp = 0xff;
  277. Serial.println(F("ACK CMD Set to Reddish END"));break;
  278. case 0x84:
  279. myCAM.OV2640_set_Special_effects(BW);temp = 0xff;
  280. Serial.println(F("ACK CMD Set to BW END"));break;
  281. case 0x85:
  282. myCAM.OV2640_set_Special_effects(Negative);temp = 0xff;
  283. Serial.println(F("ACK CMD Set to Negative END"));break;
  284. case 0x86:
  285. myCAM.OV2640_set_Special_effects(BWnegative);temp = 0xff;
  286. Serial.println(F("ACK CMD Set to BWnegative END"));break;
  287. case 0x87:
  288. myCAM.OV2640_set_Special_effects(Normal);temp = 0xff;
  289. Serial.println(F("ACK CMD Set to Normal END"));break;
  290. }
  291. }
  292. if (mode == 1)
  293. {
  294. if (start_capture == 1)
  295. {
  296. myCAM.flush_fifo();
  297. myCAM.clear_fifo_flag();
  298. //Start capture
  299. myCAM.start_capture();
  300. start_capture = 0;
  301. }
  302. if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))
  303. {
  304. Serial.println(F("ACK CMD CAM Capture Done. END"));delay(50);
  305. read_fifo_burst(myCAM);
  306. //Clear the capture done flag
  307. myCAM.clear_fifo_flag();
  308. }
  309. }
  310. else if (mode == 2)
  311. {
  312. while (1)
  313. {
  314. temp = Serial.read();
  315. if (temp == 0x21)
  316. {
  317. start_capture = 0;
  318. mode = 0;
  319. Serial.println(F("ACK CMD CAM stop video streaming. END"));
  320. break;
  321. }
  322. switch (temp)
  323. {
  324. case 0x40:
  325. myCAM.OV2640_set_Light_Mode(Auto);temp = 0xff;
  326. Serial.println(F("ACK CMD Set to Auto END"));break;
  327. case 0x41:
  328. myCAM.OV2640_set_Light_Mode(Sunny);temp = 0xff;
  329. Serial.println(F("ACK CMD Set to Sunny END"));break;
  330. case 0x42:
  331. myCAM.OV2640_set_Light_Mode(Cloudy);temp = 0xff;
  332. Serial.println(F("ACK CMD Set to Cloudy END"));break;
  333. case 0x43:
  334. myCAM.OV2640_set_Light_Mode(Office);temp = 0xff;
  335. Serial.println(F("ACK CMD Set to Office END"));break;
  336. case 0x44:
  337. myCAM.OV2640_set_Light_Mode(Home); temp = 0xff;
  338. Serial.println(F("ACK CMD Set to Home END"));break;
  339. case 0x50:
  340. myCAM.OV2640_set_Color_Saturation(Saturation2); temp = 0xff;
  341. Serial.println(F("ACK CMD Set to Saturation+2 END"));break;
  342. case 0x51:
  343. myCAM.OV2640_set_Color_Saturation(Saturation1); temp = 0xff;
  344. Serial.println(F("ACK CMD Set to Saturation+1 END"));break;
  345. case 0x52:
  346. myCAM.OV2640_set_Color_Saturation(Saturation0); temp = 0xff;
  347. Serial.println(F("ACK CMD Set to Saturation+0 END"));break;
  348. case 0x53:
  349. myCAM. OV2640_set_Color_Saturation(Saturation_1); temp = 0xff;
  350. Serial.println(F("ACK CMD Set to Saturation-1 END"));break;
  351. case 0x54:
  352. myCAM.OV2640_set_Color_Saturation(Saturation_2); temp = 0xff;
  353. Serial.println(F("ACK CMD Set to Saturation-2 END"));break;
  354. case 0x60:
  355. myCAM.OV2640_set_Brightness(Brightness2); temp = 0xff;
  356. Serial.println(F("ACK CMD Set to Brightness+2 END"));break;
  357. case 0x61:
  358. myCAM.OV2640_set_Brightness(Brightness1); temp = 0xff;
  359. Serial.println(F("ACK CMD Set to Brightness+1 END"));break;
  360. case 0x62:
  361. myCAM.OV2640_set_Brightness(Brightness0); temp = 0xff;
  362. Serial.println(F("ACK CMD Set to Brightness+0 END"));break;
  363. case 0x63:
  364. myCAM. OV2640_set_Brightness(Brightness_1); temp = 0xff;
  365. Serial.println(F("ACK CMD Set to Brightness-1 END"));break;
  366. case 0x64:
  367. myCAM.OV2640_set_Brightness(Brightness_2); temp = 0xff;
  368. Serial.println(F("ACK CMD Set to Brightness-2 END"));break;
  369. case 0x70:
  370. myCAM.OV2640_set_Contrast(Contrast2);temp = 0xff;
  371. Serial.println(F("ACK CMD Set to Contrast+2 END"));break;
  372. case 0x71:
  373. myCAM.OV2640_set_Contrast(Contrast1);temp = 0xff;
  374. Serial.println(F("ACK CMD Set to Contrast+1 END"));break;
  375. case 0x72:
  376. myCAM.OV2640_set_Contrast(Contrast0);temp = 0xff;
  377. Serial.println(F("ACK CMD Set to Contrast+0 END"));break;
  378. case 0x73:
  379. myCAM.OV2640_set_Contrast(Contrast_1);temp = 0xff;
  380. Serial.println(F("ACK CMD Set to Contrast-1 END"));break;
  381. case 0x74:
  382. myCAM.OV2640_set_Contrast(Contrast_2);temp = 0xff;
  383. Serial.println(F("ACK CMD Set to Contrast-2 END"));break;
  384. case 0x80:
  385. myCAM.OV2640_set_Special_effects(Antique);temp = 0xff;
  386. Serial.println(F("ACK CMD Set to Antique END"));break;
  387. case 0x81:
  388. myCAM.OV2640_set_Special_effects(Bluish);temp = 0xff;
  389. Serial.println(F("ACK CMD Set to Bluish END"));break;
  390. case 0x82:
  391. myCAM.OV2640_set_Special_effects(Greenish);temp = 0xff;
  392. Serial.println(F("ACK CMD Set to Greenish END"));break;
  393. case 0x83:
  394. myCAM.OV2640_set_Special_effects(Reddish);temp = 0xff;
  395. Serial.println(F("ACK CMD Set to Reddish END"));break;
  396. case 0x84:
  397. myCAM.OV2640_set_Special_effects(BW);temp = 0xff;
  398. Serial.println(F("ACK CMD Set to BW END"));break;
  399. case 0x85:
  400. myCAM.OV2640_set_Special_effects(Negative);temp = 0xff;
  401. Serial.println(F("ACK CMD Set to Negative END"));break;
  402. case 0x86:
  403. myCAM.OV2640_set_Special_effects(BWnegative);temp = 0xff;
  404. Serial.println(F("ACK CMD Set to BWnegative END"));break;
  405. case 0x87:
  406. myCAM.OV2640_set_Special_effects(Normal);temp = 0xff;
  407. Serial.println(F("ACK CMD Set to Normal END"));break;
  408. }
  409. if (start_capture == 2)
  410. {
  411. myCAM.flush_fifo();
  412. myCAM.clear_fifo_flag();
  413. //Start capture
  414. myCAM.start_capture();
  415. start_capture = 0;
  416. }
  417. if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))
  418. {
  419. uint32_t length = 0;
  420. length = myCAM.read_fifo_length();
  421. if ((length >= MAX_FIFO_SIZE) | (length == 0))
  422. {
  423. myCAM.clear_fifo_flag();
  424. start_capture = 2;
  425. continue;
  426. }
  427. myCAM.CS_LOW();
  428. myCAM.set_fifo_burst();//Set fifo burst mode
  429. temp = SPI.transfer(0x00);
  430. length --;
  431. while ( length-- )
  432. {
  433. temp_last = temp;
  434. temp = SPI.transfer(0x00);
  435. if (is_header == true)
  436. {
  437. Serial.write(temp);
  438. }
  439. else if ((temp == 0xD8) & (temp_last == 0xFF))
  440. {
  441. is_header = true;
  442. Serial.println(F("ACK IMG END"));
  443. Serial.write(temp_last);
  444. Serial.write(temp);
  445. }
  446. if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
  447. break;
  448. delayMicroseconds(15);
  449. }
  450. myCAM.CS_HIGH();
  451. myCAM.clear_fifo_flag();
  452. start_capture = 2;
  453. is_header = false;
  454. }
  455. }
  456. }
  457. else if (mode == 3)
  458. {
  459. if (start_capture == 3)
  460. {
  461. //Flush the FIFO
  462. myCAM.flush_fifo();
  463. myCAM.clear_fifo_flag();
  464. //Start capture
  465. myCAM.start_capture();
  466. start_capture = 0;
  467. }
  468. if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))
  469. {
  470. Serial.println(F("ACK CMD CAM Capture Done. END"));delay(50);
  471. uint8_t temp, temp_last;
  472. uint32_t length = 0;
  473. length = myCAM.read_fifo_length();
  474. if (length >= MAX_FIFO_SIZE )
  475. {
  476. Serial.println(F("ACK CMD Over size. END"));
  477. myCAM.clear_fifo_flag();
  478. return;
  479. }
  480. if (length == 0 ) //0 kb
  481. {
  482. Serial.println(F("ACK CMD Size is 0. END"));
  483. myCAM.clear_fifo_flag();
  484. return;
  485. }
  486. myCAM.CS_LOW();
  487. myCAM.set_fifo_burst();//Set fifo burst mode
  488.  
  489. Serial.write(0xFF);
  490. Serial.write(0xAA);
  491. for (temp = 0; temp < BMPIMAGEOFFSET; temp++)
  492. {
  493. Serial.write(pgm_read_byte(&bmp_header[temp]));
  494. }
  495. char VH, VL;
  496. int i = 0, j = 0;
  497. for (i = 0; i < 240; i++)
  498. {
  499. for (j = 0; j < 320; j++)
  500. {
  501. VH = SPI.transfer(0x00);;
  502. VL = SPI.transfer(0x00);;
  503. Serial.write(VL);
  504. delayMicroseconds(12);
  505. Serial.write(VH);
  506. delayMicroseconds(12);
  507. }
  508. }
  509. Serial.write(0xBB);
  510. Serial.write(0xCC);
  511. myCAM.CS_HIGH();
  512. //Clear the capture done flag
  513. myCAM.clear_fifo_flag();
  514. }
  515. }
  516. }
  517. uint8_t read_fifo_burst(ArduCAM myCAM)
  518. {
  519. uint8_t temp = 0, temp_last = 0;
  520. uint32_t length = 0;
  521. length = myCAM.read_fifo_length();
  522. Serial.println(length, DEC);
  523. if (length >= MAX_FIFO_SIZE) //512 kb
  524. {
  525. Serial.println(F("ACK CMD Over size. END"));
  526. return 0;
  527. }
  528. if (length == 0 ) //0 kb
  529. {
  530. Serial.println(F("ACK CMD Size is 0. END"));
  531. return 0;
  532. }
  533. myCAM.CS_LOW();
  534. myCAM.set_fifo_burst();//Set fifo burst mode
  535. temp = SPI.transfer(0x00);
  536. length --;
  537. while ( length-- )
  538. {
  539. temp_last = temp;
  540. temp = SPI.transfer(0x00);
  541. if (is_header == true)
  542. {
  543. Serial.write(temp);
  544. }
  545. else if ((temp == 0xD8) & (temp_last == 0xFF))
  546. {
  547. is_header = true;
  548. Serial.println(F("ACK IMG END"));
  549. Serial.write(temp_last);
  550. Serial.write(temp);
  551. }
  552. if ( (temp == 0xD9) && (temp_last == 0xFF) ) //If find the end ,break while,
  553. break;
  554. delayMicroseconds(15);
  555. }
  556. myCAM.CS_HIGH();
  557. is_header = false;
  558. return 1;
  559. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement