Thanks everyone. I realized the quote marks used on the Arduino example was due to it being a serial read.
I made changes and it now is at least functioning. I'm getting my timeout messages to the serial monitor.
//other variables declared also
typedef enum {
messageInit, messageWaitFor10, messageWaitForID, p5DsCollectTheData, p49sCollectGLO, pF5sCollectTheData, pF5s2CollectTheData, pF6sCollectTheData, p49sCollectGPS, pF7sSystemID, Fini, }
IDstate_t;
bool Serial2_WaitForByte(byte* v)
{
TimerA =millis();
while ( Serial2.available () <=0)
{
if (millis()-TimerA >= 500UL){
Serial.println("timeout no COMM");
return false;
}
}
*v = Serial2.read();
return true ;
}
void inMessage()
{
IDstate_t state;
byte n;
byte inbyte;
// state = messageInit; this was my main issue changed to
state = messageWaitFor10; // and added "case"
while ( state != Fini )
{
Serial.println("while line"); //debug... //this is the point the program gets stuck
switch ( state )
{
Serial.println("switch state line"); //debug
case messageWaitFor10:
TimerA =millis();
if ( Serial2_WaitForByte( &inbyte ) )
{
if ( inbyte == 0x10 )
{
state = messageWaitForID;
}
}
else if(millis()-TimerA >= 1000UL){
}
break;
case messageWaitForID:
TimerA =millis();
if ( Serial2_WaitForByte( &inbyte ) )
{
if ( inbyte == 0x10 ) // if 0x10 continue waiting for an ID byte to come
{
state = messageWaitForID;
}
if ( inbyte == 0x54 ) // comm response good
{
comm2 = true;
state = Fini;
}
if ( inbyte == 0xF5 ) //channel raw info
{
state = pF5sCollectTheData;
}
if ( inbyte == 0xF6 ) //coord of antenna
{
state = pF6sCollectTheData;
}
if ( inbyte == 0xF7 ) //empheritis
{
for (int n=0; n<32; n++){
gpsEmp[n] = false; //set all positions false
}
for (int n=0; n<24; n++){
gloEmp[n] = false; //set all positions false
}
state = pF7sSystemID;
}
if ( inbyte == 0x5D ) //tropo and iono corrections per SV#
{
state = p5DsCollectTheData;
}
}
else if (millis()-TimerA >= 500UL){
Serial.println("reciever communication time out error message ID");
state = messageWaitFor10;
}
break;
// more states related to each inMessage type complete this function
}
}
}
}
void setup(){
Wire.begin();
Serial.begin(9600); // error reporting output
Serial2.begin(115200); // comm with reciever
Serial3.begin(115200); // comm with LAN adapter or serial
delay(3000);
handshake();
startup();
TimerB = 0;
}// end of setup
void loop(){
if (Serial2.available()){
inMessage();
}
if (TimerB >= 1000){
sendMessage();
TimerB = 0;
}
}
Now I need to connect my device board however I'm having some confusion with setting the Serial2 to odd parity. I need 8 data, odd parity, 1 stop
I get that no parity these to bits are set to 0. Is the _BV() going to change them each to 1? I need both set to 1 for odd parity.
//after initializing Serial2
Serial2.begin(115200);
UCSR2C = _BV(UPM21) | _BV(UPM20);