Encoder Front Page
SRS Home | Front Page | Monthly Issue | Index
Google
Search WWW Search seattlerobotics.org

 

Motorola’s S-Record

Doug Leppard (DLeppard@CCCI.Org )

What is it?

When I was first doing research for my robot, I kept coming across the S-Record. I had no clue what it was. Then as I was booting up my robot for the first time I realized that knowing this format became very important.

The S-Record format was designed to be used loading the data from the host computer to the receiving computer. It is designed to be visually readable and even though it looks like mumble jumble it is very readable once you know how.

 

How the S-Record is constructed

Below is an example of an S-Record:

S015000046696C653A20737065656431322E61736D0A23
S1138000CF0BFFCD0BDF068009CC00085B16CC003C
S1138010345CC0CC00005BC2CC000C5BC316806C2B
S1138020087370656564203132CC00015B03CC00B9
S1138030025B0C87D6018800C8015B01CC00007C80
S11380400800FC08008CFFFE2E0CCC0001F3080095
S11380507C080006804206803320FE30E60008D704
S11380602708A6001680795326F4050136860D16D6
S11380708079860A168079323D4FC480FC5AC73D08
S9030000FC

Each line is individually loadable and can be cut out and added to other S-Record files. Each line has five parts:

Type

Record Length

Address

Code/Data

Checksum

 

Type - Type of line. Two bytes. For the 68HC912B32 it only uses S0, S1 or S9. Others are ignored. S0 record holds the description of the file. The S0 line is ignored and not loaded. The S1 line holds the data that is being loaded into your chip. S9 tells the receiving computer that the send is done.

 

Record Length - Two bytes. It tells the number of bytes in the line after the record length.

 

Address - 4, 6 or 8 bytes (for my B32 it is always 4). This tells the loading program where to load this line into memory. This is the key bytes to look at if you have loading problems.

 

Code/Data - Actual data loading into the receiving computer.

 

Checksum - 2 bytes. This is error checking for this line. What they do is add up all bytes that are loaded into the receiving computer and then check it against the checksum. If they don’t agree then a loading problem must have occurred and an error is given. What it means to you is that you can not change any bytes in a line without adjusting the checksum.

Below is an example of one line from the S-Record. It is a S1 line. $13 bytes in length. It loads the data starting at $8000. Last two characters on the line $13 is the checksum. If you look at the file speed.lst file you will see the object code and see the data in the object code that corresponds to it.

 

S1 record line with corresponding listing.

S1138000CF0BFFCD0BDF068009CC00085B16CC003C

8000 cf 0b ff lds #stkbeg initialize the stack pointer
8003 cd 0b df ldy #stkbeg-$20 initialize the data stack pointer
8006 06 80 09 jmp lbl999
8009 cc 00 08 ldd #$0008
800c 5b 16 stab $0016

* speed12.bas(8): poke sc0bdh,52 '9600 baud

800e cc 00 34 ldd #$0034

 

Debugging and using the S-Record

When downloading the S-Record to your robot, the loader (at least on the 68HC912B32) gives an "*" whenever it wants another line. So what you get is a series of asterisks. If it stops and says it can not program it, you can count the number of asterisks and that corresponds to the line in the S-Record. Then look at the address being loaded and see if it trying to load that line out of the range of the memory or into a protected area.

Another thing you can do is cut out a line and or load that line individually. I was loading a program into my B32’s EEPROM. But it had a interrupt which means the secondary vector must be loaded which is in the flash. When I first tried to load the program it gave me an error. Tracing it to the line I saw that I was trying to load into the flash memory along with the EEPROM and that was not permitted. So I cut that line out and loaded the EEPROM error free. Then I took the line and loaded that into the flash memory.

 

Conclusion

Knowing the S-Record format can be very helpful in debugging you robot. It is not as hard to understand it as it first may seem.

 

Resources

68EVB912B32UM/D    Manual for Motorola evaluation board for the B32.  It has an section that explains the S-Record.