Skip to main content

Reply to "Sending TMCC Commands to Legacy Base over Serial Connections"

Professor Chaos and John, 

Thank you very much for your replies. It seems like I understood it more than I thought, but still have some questions.

Professor Chaos posted:

What hardware are you using to talk to the base?

I am not using anything yet. I am still in the planning stage, but I want to use an arduino. I was thinking of a Arduino mega with serial shield connected to a Lionel SER2. The mega board would like a server and communicate with other boards on the layout via xbee radio, wifi, or ethernet. 

Professor Chaos posted:

 

Here is a code fragment of how to assemble the two TMCC command bytes:

 TMCCCommand1 = deviceType | (deviceID >> 1); // Byte 2 is combination of type field and first 7 bit of TMCC address
TMCCCommand2 = (deviceID << 7) | (commandField << 5) | dataField; // Byte 3 is last bit of TMCC address, command field (2 bits), plus data field
where these are the deviceTypes:
 ENGType = B00000000
SWType = B01000000
TRType = B11001000

Thanks for the code example, but where does the "B" come from in your deviceType variable? I am sorry these bytes and bits are all new to me. 

JohnGaltLine posted:

Chris,

I've just gone through this myself for a project I'm working on, and have become very familiar with how TMCC commands work over serial.  Lots of folks also supplied a bunch of useful help on this thread.  

What I think your issue is, is not exactly understanding how the commands are sent.  The TMCC commands are always 3 bytes long, exactly 24 bits.  the first byte/8bits is meaningless other than to confirm that you do have a TMCC command, and not just garbage data.  (always 0xFE)    The second and third bytes are best used added together into a 16 bit number.  These 16 bits form your actual command word, which contains 4 types of information  A device type (engine, switch, route, etc) , the device's assigned address, (engine 52, switch 16, route 4), a command type, (is this a normal command, a speed command, a programing command, etc) , and lastly a data field( what is the actual command you want done.)

The command type and the data field are always the last 7 bits of the 16 bit command word, but the device type and address are not always the same.  Engines, Switches and Accessories have a 2 bit device type identifier and a 7 bit address.  Trains/Tracks and Routes use a 5 bit device type and 4 bit address.  

 

John thanks for the link to thread. I can see what you are saying. You would send the 0xFE and the second and third bytes together, so the bytes sent to the base to throw switch 27 out would be 0xFE, 4D9F. Is this correct? 

What does the code look like to send the commands to the base via serial. Is it just a serial write, but how do you send the bytes together?

What I am trying to do is have the arduino monitor several buttons for switches. When the button is pressed the arduino will send the TMCC command to the master arduino as mentioned above, which will then send the command to the base. Can the master arduino also listen to the command base, so that buttons can be updated if the switch is thrown via the cab-2 remote, so the arduino would have to listen and write to its master along with monitor buttons attached. The master would recieve and send commands from the base. This could be done correct or can only send commands to the Legacy base.

Thank you both very much for responding to my post. I feel like I am getting somewhere with this. 

As always thanks in advance for the help.

Chris 

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×