CellularRadio Driver issues

I am trying to work with the CellularRadio driver and a module with the SIM900 and there are a few oddities.

In the constructor there is an AT command sent to the serial port and then check a for serial bytes. This I assume is to check if the modem is ON or not.


if (this.serial.BytesToRead != 0) {
	this.power.Write(false);
	Thread.Sleep(1000);
	this.power.Write(true);
	Thread.Sleep(2200);

	this.serial.DiscardInBuffer();
	this.serial.DiscardOutBuffer();
}

The check in my mind is wrong. It should be if(this.serial.BytesToRead == 0) { as this would be the case if the modem was off. In my case, the modem is ON and I get 6 bytes in the buffer so the call then loops through and switches off the modem. :frowning: Also, when you next call the PowerOn function, it also pulses the reset line. I’ve modified the code so that the powerOn flag is set if characters are received in the constructor. I ignore the powerOn flag check in the PowerOn function because of this and just carry on.

In the DoWork thread, the check on CREG and CGREG does not work. The modem passes back 2 values with a comma separator. The existing code then fails and simply goes past the switch list.

I changed the code from this:


switch (response) {
	case "0": this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.NotSearching); break;
	case "1": this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Registered); break;
	case "2": this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Searching); break;
	case "3": this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.RegistrationDenied); break;
	case "4": this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Unknown); break;
	case 5: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Roaming); break;
}
break;

to this, which supports both a dual and single value return.


int reg = 4;
if (response.IndexOf(",") != -1)
     reg = int.Parse(response.Split(',')[1]);
else
     reg = int.Parse(response);

switch (reg) {
	case 0: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.NotSearching); break;
	case 1: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Registered); break;
	case 2: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Searching); break;
	case 3: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.RegistrationDenied); break;
	case 4: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Unknown); break;
	case 5: this.OnGsmNetworkRegistrationChanged(this, NetworkRegistrationState.Roaming); break;
}
break;

I did the same with the CGREG check too.

@ Dave McLaughlin - Thanks, the power on still needs a lot of work. We’ll take a look at the CREG and CGREG commands as well.

This explains some of my experiences, which I didnot have time to check closer. Thanks Dave! :slight_smile:

One other. The + for the phone number is added to the SMS. It would be ideal if the library checked for this and only add it if was not found. My code was sending the number with this and it took a bit to spot this as it kept returning error. :slight_smile:

@ John. If you are working on the cellularradio module driver, check the power control code as this is all wrong.

In your schematic you have an open collector transistor on the PWRKEY input to the SIM900. The manual for the SIM900 shows the state of this input as being held LOW for 1 second to power up the device.

In your code, you bring the GPIO output LOW for this time and then take it high. It should be the inverse of this to switch the transistor on. In your code below, you are holding the input LOW all the time after the 1 second with it high.


this.power.Write(false);
Thread.Sleep(1000);
this.power.Write(true);
Thread.Sleep(2200);

@ Dave McLaughlin - Interesting find. Just stupid question, true=LOW and false=HIGH ??

When referring to the GPIO outputs:

true = HIGH
false = LOW

BUT because of the transistor driver, the input to the SIM900 is inverted so a true on the GPIO means LOW on the input.

Ahh, thanks, that was the part I missed. Which is probably the reason for the mistake initially…?

@ Dave McLaughlin and njbuch - We’ve made some improvements to the driver based on the issues identified above. You can find the latest at https://bitbucket.org/ghi_elect/gadgeteer/src/2d1246055c52083dd739e14bc5524ae2963452c3/Modules/GHIElectronics/CellularRadio/CellularRadio_43/CellularRadio_43.cs?at=master&fileviewer=file-view-default if you want to try them out.

2 Likes

@ John - Can you be more specific as to what you have done, looked in the repo, and that was kind of unclear…

@ njbuch - Improved cellular radio power on detection, CREG and CGREG response parsing, and phone number + prefixing.