Problem Syncing with C328 JPEG Camera Module

Hi all,

recently I have purchased C328 JPEG camera module from Comedia Ltd. Before purchasing the camera, I have searched the web to see if anyone else have done interfacing with Arduino Duemilanove and C328 camera. I have found several links with available libraries. Now, the first thing that one must do after powering camera with 3.3 V is to issue a SYNC command. I have the following code, which attempts to sync with camera, but to no avail :frowning:

// Includes library for making any digital I/O pins to communicate like serial ports
#include <NewSoftSerial.h>
#define CMD_SIZE 6

NewSoftSerial camera(12,7); // Defines Rx/Tx pins on Arduino

// command bytes
static const byte CMD_PREFIX = 0xAA;
static const byte CMD_SYNC = 0x0D;
static const byte CMD_ACK = 0x0E;

byte _command[CMD_SIZE];
byte _receive_cmd[CMD_SIZE];

// Defines functuion sync and returns boolean value (either true or false)
boolean sync() {
  bool success = false;
  int attempts = 0;
  // manual indicates we might need 60 attempts at syncing
  while(attempts < 60) {
    createCommand(CMD_SYNC, 0x00, 0x00, 0x00, 0x00);
    sendCommand();
    receiveReply();
   
    if(_receive_cmd[1] == CMD_ACK && _receive_cmd[2] == CMD_SYNC) {
      receiveReply();
      if(_receive_cmd[1] == CMD_SYNC) {
        camera.flush();
        createCommand(CMD_ACK, CMD_SYNC, 0x00, 0x00, 0x00);
        sendCommand();
        return true;
      } 
      else {
        return false; 
      }
    }
    attempts++;
  }
  return success;
}

boolean receiveReply() {
  delay(100);
  if( camera.available() > 0 )
  {
    for(int i = 0;i < 6; i++) {
      _receive_cmd[i] = camera.read(); 
    }
    return true;
  } 
  else {
    return false; 
  }
}


// Creates command for sending data to the camera
void createCommand(byte cmd, byte param1, byte param2, byte param3, byte param4 ) {
  _command[0] = CMD_PREFIX;
  _command[1] = cmd;
  _command[2] = param1;
  _command[3] = param2;
  _command[4] = param3;
  _command[5] = param4;
}

void sendCommand() {
  for(int i = 0; i < 6; i++) {
    camera.print(_command[i],BYTE);
   Serial.println(_command[i]); 
  }
}

void setup()
{  
  delay(3000);
  Serial.begin(9600);
  camera.begin(9600);
  Serial.println(camera.available());
  Serial.println("Starting ...");
  delay(10000);
  if(!sync()) {
    Serial.println(" failed");
  }
  
  
}

void loop()
{
}

I am aware that the camera functions using 3.3V logic, hence I am using a voltage divider to step down Arduino’s 5V during transmission (Tx pin 7) to acceptable 3.3V level of the camera. The Tx wire from camera is directly plugged in to Rx pin (12) in the microcontroller. I have verified that 60 mA at 3.3 V is reaching the camera’s Vcc and GND pins. I cannot figure out what I am doing wrong. I hope its not the camera.

Any help would be greatly appreciated.

Viktar

I presume this post is now lacking in purpose as the problem has been solved. :wink:

Mowcius

You are correct!