RSSI stop sketch on a gboard (atmega)
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.