Author Topic: TMCM1290 EVAL board byte error  (Read 1143 times)

0 Members and 1 Guest are viewing this topic.

Offline spaceTopic starter

  • Newbie
  • Posts: 5
  • Country: lt
TMCM1290 EVAL board byte error
« on: September 18, 2025, 01:06:52 pm »
Hello,

I'm using a step motor connected to a TMCM1290 EVAL board, which is connected to RS485 to USB to PC. I'm making a plugin for an application, but my code doesn't seem to work, all I'm getting 02-01-01-00-00-00-00-00-04 → Status byte is 01 → invalid command. All commands are returning the same status.
Everything hardware wise works perfectly, when connecting through the TMCL IDE and coding the motor in there.

Motor routine and sending TMCL commands code:
Code: [Select]
        private bool RunMotorTest()
        {
            if (!IsEnabled() || !IsConnected()) return false;

            try
            {
                byte motor = 0;            // motor index
                int safeVmax = 200;        // safe speed
                int safeAmax = 100;        // safe acceleration
                int safeCmax = 50;         // safe current (0-255)

                // Step 1: Read board version
                Console.WriteLine("Reading board version...");
                SendTMCLCommand(0x00, motor, 0); // GET VERSION
                Thread.Sleep(200);

                // Step 2: Enable motor
                Console.WriteLine("Enabling motor...");
                SendTMCLCommand(0x0B, motor, 0); // ENA
                Thread.Sleep(200);

                // Step 3: acceleration and current
                SendTMCLCommand(0x05, motor, safeAmax); // SAP
                SendTMCLCommand(0x06, motor, safeCmax); // SCP
                Thread.Sleep(200);

                // Step 4: Rotate left
                Console.WriteLine("Rotating left...");
                SendTMCLCommand(0x02, motor, safeVmax); // ROL rotate left
                Thread.Sleep(2000);
                SendTMCLCommand(0x03, motor, 0);        // MST stop motor stop

                // Step 5: Rotate right
                Console.WriteLine("Rotating right...");
                SendTMCLCommand(0x01, motor, safeVmax); // ROR rotate right
                Thread.Sleep(2000);
                SendTMCLCommand(0x03, motor, 0);        // MST stop motor stop

                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("RunMotorTest failed: " + ex.Message);
                return false;
            }
        }

        private void SendTMCLCommand(byte command, byte motor, int value)
        {
            if (_serialPort == null || !_serialPort.IsOpen)
            {
                Console.WriteLine("Serial port not open.");
                return;
            }

            byte[] tmcl = new byte[9];
            tmcl[0] = 0x01; // slave address
            tmcl[1] = command;
            tmcl[2] = motor;
            tmcl[3] = (byte)((value >> 24) & 0xFF);
            tmcl[4] = (byte)((value >> 16) & 0xFF);
            tmcl[5] = (byte)((value >> 8) & 0xFF);
            tmcl[6] = (byte)(value & 0xFF);

            // Checksum
            byte checksum = 0;
            for (int i = 0; i <= 6; i++) checksum += tmcl[i];
            tmcl[7] = (byte)(checksum & 0xFF);
            tmcl[8] = 0; // reserved

            Console.WriteLine("Sending TMCL: " + BitConverter.ToString(tmcl));

            try
            {
                // Flush input buffer before sending
                _serialPort.DiscardInBuffer();

               

                // Send the packet
                _serialPort.Write(tmcl, 0, tmcl.Length);

                // Small delay to let the board respond
                Thread.Sleep(20);

                // Read full 9-byte response
                byte[] response = new byte[9];
                int offset = 0;
                int timeoutMs = 1000;
                var sw = System.Diagnostics.Stopwatch.StartNew();

                while (offset < 9)
                {
                    if (sw.ElapsedMilliseconds > timeoutMs)
                        throw new TimeoutException("Timeout waiting for TMCM-1290 response.");

                    if (_serialPort.BytesToRead > 0)
                    {
                        int n = _serialPort.Read(response, offset, 9 - offset);
                        offset += n;
                    }
                }

                Console.WriteLine("Response: " + BitConverter.ToString(response));

                // Check status byte
                byte status = response[1];
                if (status != 0x00)
                    Console.WriteLine($"TMCL command returned error status: {status:X2}");
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine("Timeout: " + ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error sending TMCL command: " + ex.Message);
            }
        }

Thanks in advance!

« Last Edit: September 18, 2025, 01:08:28 pm by space »
 

Offline Ammar

  • Regular Contributor
  • *
  • Posts: 163
  • Country: au
Re: TMCM1290 EVAL board byte error
« Reply #1 on: September 18, 2025, 02:06:06 pm »
Courtesy of ChatGPT o3:

byte index   what TMCL expects (RS-485 / RS-232)   what your code sends
0   module address   OK (0x01)
1   command number   OK
2   type / parameter number   you put the motor here
3   motor / bank   you put value-MSB here
4-7   32-bit value (MSB first)   shifted one byte to the left
8   checksum (sum of bytes 0-7)   you write 0x00, checksum is at byte 7

Because of the mis-alignment the checksum that finally lands in byte 8 is wrong, so the module answers with
status 0x01 = “wrong checksum” – not “invalid command”
Analog Devices
.

Correct 9-byte frame
  • address
  • [1] command
    [2] type / parameter
    [3] motor or bank
    [4] value >> 24
    [5] value >> 16
    [6] value >> 8
    [7] value
    [8] checksum  (sum of bytes 0-7, 8-bit)
    ``` :contentReference
[oaicite:1]{index=1}

Example for **ROR  motor 2  speed 350** taken from the manual:



01 01 00 02 00 00 01 5E 62


byte 2 is just a “don’t-care” type for ROR/ROL, so it is 0 :contentReference[oaicite:2]{index=2}.

---

### Fixing your code

```csharp
private void SendTMCLCommand(byte command,
                              byte type,          // new!
                              byte motorOrBank,
                              int  value)
{
    if (_serialPort == null || !_serialPort.IsOpen) return;

    var tmcl = new byte[9];

    tmcl[0] = 0x01;          // module address
    tmcl[1] = command;       // command number
    tmcl[2] = type;          // parameter / type
    tmcl[3] = motorOrBank;   // motor or bank
    tmcl[4] = (byte)(value >> 24);
    tmcl[5] = (byte)(value >> 16);
    tmcl[6] = (byte)(value >> 8);
    tmcl[7] = (byte)(value);

    // checksum over bytes 0-7
    byte checksum = 0;
    for (int i = 0; i < 8; i++) checksum += tmcl;
    tmcl[8] = checksum;      // <-- last byte!

    _serialPort.DiscardInBuffer();
    _serialPort.Write(tmcl, 0, 9);
    ...
}

Using it in your test routine
byte m = 0;  // motor 0

// Read firmware version -> GGP, param 70 (example)
SendTMCLCommand(0x0A, 70, 0, 0);   // GGP 70, bank 0

// Set acceleration  (SAP param 5)
SendTMCLCommand(0x05, 5, m, safeAmax);

// Set max current   (SAP param 6)
SendTMCLCommand(0x05, 6, m, safeCmax);

// Rotate left  (ROL)
SendTMCLCommand(0x02, 0, m, safeVmax);

// Stop         (MST)
SendTMCLCommand(0x03, 0, m, 0);


(There is no “ENA” command 0x0B; 0x0B is STGP. Driver enable is usually axis-parameter 255 or a GPIO pin.)

After these changes the module should reply with status 0x64 (100 decimal) = OK.

Quick checklist
Symptom   Fix
Status 01   checksum wrong – write it to byte 8
Status 02   command byte invalid (e.g. 0x00 or 0x0B)
All commands “wrong type”   check the type/parameter byte (byte 2)
Still no motion   make sure motor power is on and parameter Max Velocity / Acceleration / Current are sane

This packet layout is identical for every TMCL module, including the TMCM-1290
Analog Devices
. Once the frame is built exactly as above you should see the motor rotate just like it does from the TMCL IDE.
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 23122
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: TMCM1290 EVAL board byte error
« Reply #2 on: September 18, 2025, 05:54:55 pm »
That LLM generated - but presumably not checked/verified - output will be consumed by LLMs scraping the web, and will then form the basis for the next round of LLM output.

The concept of LLM slop being used to train LLMs has AI/LLM researchers seriously worried, because they haven't found a way to detect of counter it.

Pasting a screenshot of google search results into a post is obviously bad manners - and so is pasting LLM slop into posts.
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 
The following users thanked this post: gnavigator1007, UnijunctionTransistor, kite31

Offline Smokey

  • Super Contributor
  • ***
  • Posts: 3894
  • Country: us
  • Not An Expert
Re: TMCM1290 EVAL board byte error
« Reply #3 on: October 04, 2025, 02:47:39 am »
...
Pasting a screenshot of google search results into a post is obviously bad manners - and so is pasting LLM slop into posts.

.... so, on a bad manners scale from 1 to 10, what am I if I paste a screenshot of google search results for the query "google search results"?  :)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->