C628 camera module and arduino mega2560

My senior design group and I are trying to interface the c628 enhanced jpeg module found at[urlhttp://www.electronics123.com/s.nl/it.A/id.2421/.f with an arduino mega 2560. The camera communicates with the arduino through the serial ports ( Rx and Tx). The camera sends and recieves code in hex.

We have hooked the camera to our computer using the RS 232 cable and UART connector and with the program provided on a cd, we have taken pictures. By hooking a logic analyzer to the RX and Tx pins we have found the string of hex code that is used to initialize the camera.

Moving to the arduino we have written this code to send the same string of hex.

int rx= 19;

int tx= 18;

int inByte =0;

int i=0;

void setup(){

Serial.begin(57600);

Serial1.begin(57600);

Serial1.write(0xAA);

Serial1.write(i); //sends as 0x00

Serial1.write(0xB0);

Serial1.write(0x04);

Serial1.write(0xAA);

}

// if (Serial.available()){

// delay(2500);

// int inByte = Serial.read();

// Serial1.print(inByte, HEX);

// if (Serial1.available() > 0) {

// delay(2500);

// int inByte = Serial1.read();

// Serial.println(inByte, HEX);

//}

//}

void loop(){

//delay(2500);

//Serial1.write(0xAA);

//Serial1.write(i); //sends as 0x00

//Serial1.write(0xB0);

//Serial1.write(0x04);

//Serial1.write(0xAA);

//delay(2500);

}

This code sends the same string of hex to the camera. Looking at the logic analyzer the camera instantly sends back 0xFF which in the user manual says it means terminating transmission.

We are not sure what direction to go from here so any advice would be a great help.

This code worked for me.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3);

void setup(){

pinMode(2,INPUT);

pinMode(3,OUTPUT);

mySerial.begin(57600);

mySerial.setTimeout(50);

delay(300);

mySerial.flush();

delay(300);

int numinput = mySerial.available();

delay(25);

while(numinput > 0){

mySerial.read();

delay(25);

numinput = mySerial.available();

delay(25);

}

}

void loop(){

int resp = mySerial.available();

delay(25);

byte sync = {0xAA,(byte)0x00,0xB0,0x04,0xAA};

while (!resp){

mySerial.write(sync,sizeof(sync));

delay(25);

resp = mySerial.available();

delay(25);

}

while(resp > 0){

mySerial.read();

delay(25);

resp = mySerial.available();

delay(25);

}

byte com2 = {0xAA,0x01,0x1E,0x73,0xAA};

while (!resp){

mySerial.write(com2,sizeof(com2));

delay(25);

resp = mySerial.available();

delay(25);

}

while(resp > 0){

mySerial.read();

delay(25);

resp = mySerial.available();

delay(25);

}

byte com3 = {0xAA,0x04,0x58,0xAA};

while (!resp){

mySerial.write(com3,sizeof(com3));

delay(25);

resp = mySerial.available();

delay(25);

}

while(resp > 0){

mySerial.read();

delay(25);

resp = mySerial.available();

delay(25);

}

byte com4 = {0xAA,0x01,0x38,0x8D,0xAA};

while (!resp){

mySerial.write(com4,sizeof(com4));

delay(25);

resp = mySerial.available();

delay(25);

}

while(resp > 0){

mySerial.read();

delay(25);

resp = mySerial.available();

delay(25);

}

byte com5 = {0xAA,0x01,0x55,0xAA};

while (!resp){

mySerial.write(com5,sizeof(com5));

delay(25);

resp = mySerial.available();

delay(25);

}

while(resp > 0){

mySerial.read();

delay(25);

resp = mySerial.available();

delay(25);

}

while(1){}

}