
Originally Posted by
KurtE
Thanks,
Will be taking look. Yep I did find it does not build but should have all of the pieces to adapt some of the other code to.
Sorry about that. When I posted the CSI and Camera stuff, I forgot that those elements referred to some global variables in the interrupt routine for the CSI.
This simple front end should build and allow you to verify that the code is functioning:
Code:
// t4.1 PIN input and image packet test
// New CameraBB with new pinouts for wired breadboard
// MJB 10/27/2020
#include <stdint.h>
#include <Wire.h>
#define FRAME_WIDTH 640l
#define FRAME_HEIGHT 480l
#define FB_WIDTH 640l
#define FB_HEIGHT 480l
#define FB_COUNT 2 // two frames in EXTMEM
#define FRAMEBYTES (FRAME_WIDTH * FRAME_HEIGHT *2)
#define FRAMEBUFFBYTES (FB_WIDTH *FB_HEIGHT *2)
uint8_t fb1[FRAMEBUFFBYTES] EXTMEM;
uint8_t fb2[FRAMEBUFFBYTES] EXTMEM;
uint32_t masterfreq = 24;
volatile uint32_t last_csistat, csiIrqCount;
volatile uint32_t fb1count, fb2count;
volatile uint32_t bswitcherrors;
uint32_t framecount;
const char compileTime [] = " Compiled on " __DATE__ " " __TIME__;
const int ledpin = 13;
const int imarkpin = 32;
const int pinCamReset = 14;
#define LEDON digitalWriteFast(ledpin, HIGH); // Also marks IRQ handler timing
#define LEDOFF digitalWriteFast(ledpin, LOW);
#define LEDTOGGLE digitalToggleFast(ledpin);
#define IMARKHI digitalWriteFast(imarkpin, HIGH); // Also marks IRQ handler timing
#define IMARKLO digitalWriteFast(imarkpin, LOW);
#define IMARKTOGGLE digitalToggleFast(imarkpin);
void setup() {
Serial.begin(9600);
delay(200);
Wire.begin();
delay(100);
pinMode(ledpin, OUTPUT);
pinMode(imarkpin, OUTPUT);
pinMode(pinCamReset, OUTPUT);
delay(10);
memset(&fb1, 0, FRAMEBUFFBYTES * 2);
digitalWriteFast(pinCamReset, LOW);
delay(10);
digitalWriteFast(pinCamReset, HIGH); // subsequent resets via SCB
Serial.printf("\n\nOV7670 Camera Test 3 %s\n", compileTime);
cameraBegin(640, 480, fb1, fb2);
}
void loop() {
static uint32_t lastfc;
static uint32_t fc = 0;
char ch;
if (Serial.available()) {
ch = Serial.read();
if (ch == 's') CMSI();
if (ch == 'c') CMCS();
if (ch == 'r') CMCR();
if (ch == 'f') CMGF();
}
// This extends frame count from 16 to 32 bits
fc = CSI_CSICR3 >> 16; // get the 16-bit frame count
framecount += (fc - lastfc);
lastfc = fc;
}
// Show information
void CMSI(void) {
Serial.printf("\n\nOV7670 Camera Test 3 %s\n", compileTime);
Serial.printf("buff1 at %p buff2 at %p\n", &fb1, &fb2);
Serial.printf("Camera frame count = %lu \n", framecount);
Serial.printf("Base Address Change errors: %lu\n", bswitcherrors);
Serial.printf("csistat: %08X, csiIrqCount: %lu\n", CSI_CSISR, csiIrqCount);
Serial.printf("fb1 count: %6lu fb2 count %6lu\n",fb1count,fb2count);
}
void CMCS(void) { // Show CSI registers
print_csi_registers();
}
// Show Camera Registers
void CMCR(void) {
uint8_t regs[200];
cameraReadAll(regs);
cameraShowAll(regs);
}
// Get a frame of data
void CMGF(void) {
uint32_t imagesize, fbc;
imagesize = (FRAME_WIDTH * FRAME_HEIGHT * 2);
fbc = fb2count;
while (fbc == fb2count); // wait until a new frame in fb2 is finished
// Don't try sending unless your program can handle 614400 bytes in a hurry!
//Serial.write(fb2,magesize);
Serial.printf("fb2 ready for processing %lu nytes.", imagesize);
}
Start a sketch with this code and add the contents of the zip file to the sketch folder.