I want to express my sincere gratitude for your advice. I have now revised my program. However, it is still experiencing the original problem of not looping unless serial.print() is used in another function (the first line of readUM6()). Any ideas?
//AUTHOR: Jaz S;
#define BAUD 115200
#define REG_EULER_PHI_THETA 0X62
#define REG_EULER_PSI 0x63
#define ANGLE_SCALE_FACTOR 0.0109863 // Convert register data to Degrees
boolean IMU_flag = false;
struct IMU{
int data;
} phi, theta, psi;
void setup(){
Serial.begin(BAUD); //Sets baud rate for PC USB
Serial1.begin(BAUD); //Sets baud rate for Serial port 1
// Serial.println("Setup complete");
}
void loop(){
// Serial.println("Starting loop");
do{
read_UM6();
}while (IMU_flag == false);
Serial.print("psi... ");
Serial.println(psi.data*ANGLE_SCALE_FACTOR);
delay(250);
}//end VOID
void read_UM6(){
Serial.println("Reading IMU... ");//If this line is excluded from the overall program, the whole thing stops working.
psi.data = 0;
byte i = 0;
unsigned int data[15] = {0};
unsigned long data_sum = 0;
byte blank = 0, temp = 0;
byte chksum1 = 0, chksum0 = 0;
unsigned int chksum = 0;
//If there's data in the serial temp register and we haven't finished retrieving data...
while ((Serial1.available() > 0)) {
for (i=0; i < 15; i++){
data[i] = Serial1.read();
}
}
if ((data[0] == 's')){
if ((data[1] == 'n')){
if ((data[2] == 'p')) {
if (data[3] == (PT_HAS_DATA | PT_IS_BATCH | PT_BATCH_LEN)){
if (data[4] == REG_EULER_PHI_THETA){
for (byte j = 5; j <= 12; j++){
data_sum += data[j];
}
blank = data[11];//12
blank = data[12];//13
chksum1 = data[13];//14
chksum0 = data[14];//15
chksum = (chksum1 << 8) | chksum0;
if (chksum == ('s' + 'n' + 'p' + (PT_HAS_DATA | PT_IS_BATCH | PT_BATCH_LEN) + REG_EULER_PHI_THETA + data_sum)){ //If checksum is correct...
phi.data = (data[6] | (data[5] << 8));
theta.data = (data[8] | (data[7] << 8));
psi.data = (data[10] | (data[9] << 8));
IMU_flag = true;
return;
}//1
}//2
else{
IMU_flag = false;
return;
}
}//3
else{
IMU_flag = false;
return;
}
}//4
else{
IMU_flag = false;
return;
}
}//5
else{
IMU_flag = false;
return;
}
}//6
else{
IMU_flag = false;
return;
}
else {
IMU_flag = false;
return;
}