S12X Serial Monitor communication quirks
Posted: Mon Jan 27, 2014 10:07 pm
Several people have noticed, that when using FreeEMS-Loader, you have to hit load twice to get it to actually load a file. This is most noticable when you first power up in SM mode, subsequent tries typically succeed.
I have managed to track down the reason for this, as the fact that the SM will send an indeterminant amount of null characters (0x0), before its response to the first command you send.
Typical command sequence according to the documentation
This is indeed true, for all except the first communication. That goes more like this
Where the SM waits for the PC to send its awake message before sending the 0's. Handling this by blindly reading after sending the first command, and then trying again seems to work every time.
I have managed to track down the reason for this, as the fact that the SM will send an indeterminant amount of null characters (0x0), before its response to the first command you send.
Typical command sequence according to the documentation
Code: Select all
PC -> 0xD //Check to see if SM is alive
SM -> 0xE0 0x08 0x3E
Code: Select all
PC -> 0xD
SM -> 0x0 0x0 0x0 (... some random number of 0's) 0xE0 0x08 0x3E
Code: Select all
PC -> 0xD
SM -> 0x0 0x0 0x0 (... some random number of 0's) 0xE0 0x08 0x3E
PC -> (Reads chars until 50-100ms timeout)
PC -> 0xD
SM -> 0xE0 0x08 0x3E