jeudi 26 mars 2015

Why does the Arduino restarts before entering initialization function?


I have been wracking my brain for a while now. Before making some changes to the way packet data is handled by my SAIAI_DEV object, I was able to run perfectly fine (except a bug in acknowledgment handling that necessitated the changes). However, now the device restarts after outputting the "About to Init" (I have another print statement as the first line of the init function). Additionally, without the 1 second delays a hang occurs at "Past Function 0." before the line finishes. I have tried reducing dynamic memory usage (put things in PROGMEM, reduced function and state count) to about 34%, which points to a non-memory issue, and have the same problem. I do not explicitly use interrupts either.


Setup Code:



void setupDevice(){
SoftwareSerial* xbeeSerial = new SoftwareSerial(RX_PIN,TX_PIN);
Serial.begin(BAUD);
xbeeSerial->begin(BAUD);
comm.init(xbeeSerial,&Serial,ENDNODE);
comm.report();
Serial.println(F("Past report."));

sensor.read22(SENSOR_PIN);
Serial.println(F("Past Sense."));

sprintf(states[0].name, "%.14s", "Temperature");
itoa((int)(sensor.temperature_f*10),states[0].value,63);
states[0].number = 0;
states[0].type = FLOAT;
states[0].divisor = 1;
Serial.println(F("Past State 0."));
delay(1000);

sprintf(states[1].name, "%.14s", "Humidity");
itoa((int)(sensor.humidity*10),states[1].value,63);
states[1].number = 1;
states[1].type = FLOAT;
states[1].divisor = 1;
Serial.println(F("Past State 1."));
delay(1000);

sprintf(functions[0].name, "%.79s", "Toggle LED");
functions[0].num_parameters = 0;
functions[0].function_pntr = &toggleLED;
Serial.println(F("Past Function 0."));
delay(1000);

sprintf(functions[1].name, "%.79s", "Change Temperature Unit");
functions[1].num_parameters = 1;
functions[1].function_pntr = &changeUnit;
functions[1].params = &func1_param;
Serial.println(F("Past Function 1."));
delay(1000);

sprintf(functions[1].params[0].name, "%.79s", "Unit of Temperature");
functions[1].params[0].type = CHAR;
sprintf(functions[1].params[0].value, "%.64s", "F");
Serial.println(F("Past F0 Param 0."));
delay(1000);

sprintf(info.name, "%.79s", "Smart Sensor");
info.num_states = 2;
info.num_functions = 2;
info.states = states;
info.functions = functions;
Serial.println(F("Info"));
delay(1000);

Serial.println(F("About to Init."));
delay(1000);
dev.init(&comm,&info);
}

// the setup routine runs once when you press reset:
void setup() {
Serial.println(F("\nEnter Setup."));
temp_unit = 'F';
pinMode(LED_PIN, OUTPUT);
setupDevice();
count = millis();
}


Init Function:



void SAIAI_DEV::init(XBEE* xb_dev, device_info* info){
comms->serial->println( F("Init Start.") );
delay(1000);
bool success = false;
comms = xb_dev;
device = info;
while( !success ){
success = true;
memset(comms->rx_pkt->cmdData,0,95);
memset(ack_buffer, 0, PROTOCOL_SIZE);
memset(data, 0, PROTOCOL_SIZE);
wait_for_coordinator();
success &= transmit_init();
if(success) success &= transmit_identity();
if(success) success &= transmit_states();
if(success) success &= transmit_functions();
if(success) { success &= finish_init();}
}
comms->serial->println(F("Init Done!"));
}


Any thoughts would be appreciated. If you need more source, I am happy to provide.




Aucun commentaire:

Enregistrer un commentaire