What is the purpose of asterix (*) in Gcode?

  • Doing some low level monitoring, the following sequence is sent to the printer:



    N0 M106*36 
    N1 G28*18
    N2 M107*39


    This sequence just turns the fan on, homes the printer, then turns the fan off.



    Question: What is the purpose of the asterix/star/(*) and the two succeeding digits on each line?


    * asterisk - Asterix is a character in a cartoon series.

    @AndrewMorton So that would make the gcode the Romans then - with Asterix being their checksum, stopping corruption in his local area?

    Hmmm... maybe. The Romans did build a lot of things, like a 3-d printer does.

  • That is a checksum. It's added by the host software to the G-code, to allow some basic verification by the firmware that the G-code was transmitted unchanged. It doesn't change the meaning of the G-code, and what your sequence actually represents is just M106, G28, M107. The N0,N1,N2,... are line numbers, and the combination of line numbers and checksums is used to request a re-send of any lines that were corrupted during transmission.


    Do you happen to know the checksum algorithm used here?

    In Marlin, all the bytes for the individual characters are XOR-ed together, and the result should be the same as the checksum.

    Just XOR: `byte checksum = 0; byte count = 0; while(instruction[count] != '*') checksum = checksum^instruction[count++];`

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used