RSSI stop sketch on a gboard (atmega) I have this function in my code and works fine (it returns a valid value, I put this value into a int variable outside function), but when end the function (or continue the code), my sketch stop/die...

///FUNCION PARA RSSI XBEE///
byte rss() {  ///PARA RSSI
union {byte B; char C;} atCmd[3];
AtCommandRequest atCmdReq;
AtCommandResponse atResp;
byte respLen, *resp, dBm;
strcpy(&amp;atCmd[0].C, "DB");
atCmdReq = AtCommandRequest(&amp;atCmd[0].B);
atResp = AtCommandResponse();
xbee.send(atCmdReq);
if (xbee.readPacket(5000)) {
   if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) {
       xbee.getResponse().getAtCommandResponse(atResp);
       if (atResp.isOk()) {
           respLen = atResp.getValueLength();
           if (respLen == 1) {
               resp = atResp.getValue();
               dBm = resp[0];
                  return dBm; 
           }
           else {
             //  Serial.println("Unexpected response");
           }
       }
       else {
         //  Serial.println("ERROR");
       }
   }
   else {
     //  Serial.println("Unknown response");
   }
}
else {
 //  Serial.println("No response");
}
}///fin rss()


¿Any tips?
Your function is only returning a value when everything works OK. If an error occurs, the problem is reported to serial but it doesn't return anything. It seems likely that this could cause stack corruption which could make the program stop.

A simple solution would be to put return 0; (or some other number) just before the end of the function.