Which core do you intend to use? :
Not sure if this is correct answer, but this is the number on the chip - STM32F103CBT6
Which pinout do you plan? :
Not sure what I need. So far I've connected like this :
- CS to PIN7 (which I now see is SPI1 SS - could this be an issue if I've declared PIN7 as an OUTPUT?)
Why do you need SPI? :
Example code shows that SPI is used
You can use any I2C interface. :
Isn't this the Wire class?
Below is the code I've uploaded to the board. It has been modified to automatically capture and send the frame to the PC continuously. I am using a windows app to receive the data which works for the Arduino Nano.
Using the Maple Mini it shows me the error message "SPI Interface Error". Which I'm guessing is I'm using the wrong pins.
The Nano only has one SPI and one I2C, but I've seen other Arduino boards (like the Maple Mini) that have two SPI and two I2C interfaces, which I thought were accessed like Wire1 and Wire2 or SPI1 and SPI2. (I'm not positive though). Question is, how can I be sure that in the Maple Mini, that the code SPI.begin() and Wire.begin() directly relate to the pins for I2C1 and SPI1? I can't find any class declarations like Wire1 and Wire2.
Code: Select all
// The demo sketch will do the following tasks:
// 1. Set the camera to JPEG output mode.
// 2. Read data from Serial port and deal with it
// 3. If receive 0x00-0x08,the resolution will be changed.
// 4. If receive 0x10,camera will capture a JPEG photo and buffer the image to FIFO.Then write datas to Serial port.
// 5. If receive 0x20,camera will capture JPEG photo and write datas continuously.Stop when receive 0x21.
// 6. If receive 0x30,camera will capture a BMP photo and buffer the image to FIFO.Then write datas to Serial port.
// 7. If receive 0x11 ,set camera to JPEG output mode.
// 8. If receive 0x31 ,set camera to BMP output mode.
#include <Wire.h>
#include <OV2640.h>
#include <SPI.h>
#define OV2640_MINI_2MP
#define BMPIMAGEOFFSET 66
const char bmp_header[BMPIMAGEOFFSET] PROGMEM =
{
0x42, 0x4D, 0x36, 0x58, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10, 0x00, 0x03, 0x00,
0x00, 0x00, 0x00, 0x58, 0x02, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0xC4, 0x0E, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00,
0x00, 0x00
};
// set pin 7 as the slave select for the digital pot:
const int CS = 7;
bool is_header = false;
int mode = 0;
uint8_t start_capture = 0;
ArduCAM myCAM(OV2640, CS);
void setup() {
// put your setup code here, to run once:
uint8_t vid, pid;
uint8_t temp;
Wire.begin();
Serial.begin(115200);
// Serial.begin(921600);
Serial.println("ArduCAM Start!");
// set the CS as an output:
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
// initialize SPI:
SPI.begin();
//Reset the CPLD
myCAM.write_reg(0x07, 0x80);
delay(100);
myCAM.write_reg(0x07, 0x00);
delay(100);
while (1) {
//Check if the ArduCAM SPI bus is OK
myCAM.write_reg(ARDUCHIP_TEST1, 0x55);
temp = myCAM.read_reg(ARDUCHIP_TEST1);
if (temp != 0x55) {
Serial.println("SPI Interface Error!");
delay(1000); continue;
}
else {
Serial.println("SPI Interface OK."); break;
}
}
while (1) {
//Check if the camera module type is OV2640
myCAM.wrSensorReg8_8(0xff, 0x01);
myCAM.rdSensorReg8_8(OV2640_CHIPID_HIGH, &vid);
myCAM.rdSensorReg8_8(OV2640_CHIPID_LOW, &pid);
if ((vid != 0x26) && ((pid != 0x41) || (pid != 0x42))) {
Serial.println("Can't find OV2640 module!");
delay(1000);
continue;
}
else {
Serial.println("OV2640 Has Been Detected.");
break;
}
}
//Change to JPEG capture mode and initialize the OV5642 module
myCAM.set_format(JPEG);
myCAM.InitCAM();
myCAM.OV2640_set_JPEG_size(OV2640_320x240);
delay(1000);
myCAM.clear_fifo_flag();
}
void loop() {
while (1) {
digitalWrite(33, HIGH);
delay(1000);
digitalWrite(33, LOW);
mode = 2;
start_capture = 2;
uint8_t temp = 0xff, temp_last = 0;
while (1)
{
if (start_capture == 2)
{
myCAM.flush_fifo();
myCAM.clear_fifo_flag();
//Start capture
myCAM.start_capture();
start_capture = 0;
}
if (myCAM.get_bit(ARDUCHIP_TRIG, CAP_DONE_MASK))//if the capture has completed
{
uint32_t length = 0;
length = myCAM.read_fifo_length();// buffer length
if ((length >= MAX_FIFO_SIZE) | (length == 0))
{
myCAM.clear_fifo_flag();
start_capture = 2;
continue;
}
myCAM.CS_LOW();
myCAM.set_fifo_burst();//Set fifo burst mode
temp = SPI.transfer(0x00);
length--;
while (length--)
{
temp_last = temp;
temp = SPI.transfer(0x00);
if (is_header == true)
{
Serial.write(temp);
}
else if ((temp == 0xD8) & (temp_last == 0xFF))
{
is_header = true;
Serial.write(temp_last);
Serial.write(temp);
}
if ((temp == 0xD9) && (temp_last == 0xFF)) //If find the end ,break while,
break;
delayMicroseconds(15);
}
myCAM.CS_HIGH();
myCAM.clear_fifo_flag();
start_capture = 2;
is_header = false;
}
}
}
}
I have also noted these definitions in ArduCam.h for various types of chips. (Here is the one for the Nano)
Code: Select all
#if defined (__AVR__)
#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
#define pulse_high(reg, bitmask) sbi(reg, bitmask); cbi(reg, bitmask);
#define pulse_low(reg, bitmask) cbi(reg, bitmask); sbi(reg, bitmask);
#define cport(port, data) port &= data
#define sport(port, data) port |= data
#define swap(type, i, j) {type t = i; i = j; j = t;}
#define fontbyte(x) pgm_read_byte(&cfont.font[x])
#define regtype volatile uint8_t
#define regsize uint8_t
#endif
This is what I have defined for the Maple Mini but they are more guess work than anything else. The below definitions were the only ones used by ArduCam so I didn't bother trying to convert the others.
Code: Select all
#ifdef __STM32F1__//these values may not be correct
#define cbi(reg, bitmask) *reg &= ~bitmask
#define sbi(reg, bitmask) *reg |= bitmask
#define regtype volatile uint32_t
#define regsize uint32_t
#endif