Close

Garbage out without garbage in (ATTiny serial problems)

A project log for Betri

A GSM connected car battery voltage monitor.

selali-adoborSelali Adobor 10/24/2016 at 00:490 Comments

After moving on from the flash issue I tried implementing a simple heartbeat check for the GSM module.

When you send the text "AT" you should get the response, "OK" back*

*The GSM module echos back everything you send, so the full string is really "AT <newline> OK"

What I was getting from the debug port was this:

Attempting to read from SIM800
Read line from SIM800: ???K

I'll start by saying the decision to keep the debug port already proved invaluable. When I tried having the ATTiny send the "AT" response while the GSM module was hooked up to my USB-to-Serial breakout, I was getting "AT <newline> OK" as expected.

That meant the ATTiny was getting exactly the correct response, but something was wrong with the ATTiny's serial receiving routine.

All I had to go on was the fact I was getting the correct number of characters, and the ATTiny was sending "AT" as it should.

The fix turned out to be pretty straight forward though, simply adding the line:

delay(500);
before and after my sleep function gave me what I expected:
Attempting to read from SIM800
Read line from SIM800: AT <newline> OK

...kind of.


There was supposed to be a debug statement that contained what I was sending to the sim module, and sometimes I was still getting garbage.

But it was progress.


TinyDebugSerial and SoftwareSerial are very sensitive to timing because they implement UART without the supporting hardware. Shortening my debug statements (thus having fewer statements overlapping between the two) produced reliable output without sleep statements:

writeSim: AT
readSim: AT <newline> OK

Discussions