# Understanding DCC packets and pressing function buttons



## Gigasaurus (Aug 22, 2013)

I'm trying to learn about DCC and DCC packets.

I understand a DCC packet has 4 key components:

preamble
address
instruction
error correction

An example on dccwiki is this:

1111111111 0 0AAAAAAA 0 01DUSSSS 0 EEEEEEEE 1

In this example, the "0" in "0AAAAAAA" is supposed to represent the headlight

the "01" in "01DUSSSS" is to represent an accessory control

If I had a few working examples of what certain packets would look like, it would better help me understand this.

Assuming my active loco was programmed set to #3, what might a data packet look like if I:

Pressed the F1 button on my controller (assuming 1 controls my headlight)

Pressed the F2 button on my controller (assuming 2 controls a SoundTraxx whistle)

Pressed the speed up button on my controller

Pressed the stop button on my controller


I appreciate any help in trying to understand this.


----------



## RT_Coker (Dec 6, 2012)

What’s up? Thought you were doing the Bluetooth for Bachmann?
You may what to get something like this: “NCE #524-231 Packet Analyzer for DCC Systems”.

I am hoping to finalize some open-source DBTC boards soon.
Bob


----------



## Gigasaurus (Aug 22, 2013)

Thanks for the tip. Hope your project is going well.


----------



## jimutt (Feb 21, 2015)

Hi,
Well I could probably help you out. I'm currently developing my own command station and I've got all the basics done. 

Your headlight example "0AAAAAAA" does mainly comply to certain outdated encoders as far as I'm concerned. I'm not too sure about that to be honest but I've had no luck using that bit at. With my encoder I'm using the FL bit in Function group 1. Which means that if I want to turn on the headlights on my loco I send the following command:

10010000

And to turn it off I simply send 10000000. 

So to give you a complete answer to your question for what package will be sent if you press the button to turn on the headlights for a loco with the address three you will send:

00000011 0 10010000 0 10010011

First you got your address byte containing the assigned address for your loco. Then you've got a separating "0" bit. After that the instrucvtion byte is sent according to the description I gave earlier. Then you have the checksum which is created by XORing the address and the instruction bytes. 

The same applies if you would press your "function 2" button. Just that the instruction byte will differ. 

It gets a little bit more messy when you're sending speed commands. But it's all done as the NMRA document says (http://www.nmra.org/sites/default/files/s-92-2004-07.pdf). For speed/direction commands the first 3 bits of the instruction byte can be either 010 or 011. The LSB of those three bits controls the direction of your loco.

Then the remaining 5 bits will control the speed. Here everything is working as expected except for one thing. For most modern encoders the least significant bit will actually be bit 4. _("Bit four of byte 2 (C) by default shall contain one additional speed
bit, which is the least significant speed bit")_

That's why you get the progression you see in the speed command table in the document for S-9.2. 

I guess you will still have a lot of questions but at least this might help you a little bit.


----------

