Pacetech
06-21-04, 05:46 PM
Ok, I need to generate a packet to send out the 2nd serial port and the end of the packet has a checksum.
Now I know that 8 bit chars are stored as 16 bit numbers, but my checksum must be the 8 bit sum of the chars in the data packet. So I add up all my 8 bit chars and sometimes I get a larger number than FF. So, I've been doing a MOD to get it to be less than or equal to FF.
So I just do a FF MOD SCI1 TX
For example
: MOTSTARTMOTION ( ADDR -- )
AA SCI1 TX (packet header, do not add to checksum)
DUP SCI1 TX ( TO ADDR on stack )
05 SCI1 TX ( COMMAND BYTE - set gain )
05 + FF MOD SCI1 TX
; EEWORD
Since TX will only send out an 8 bit value, the question is, if I don't do the FF MOD, will only the lowest 8 bits of the 16 bit value get sent?
Now I know that 8 bit chars are stored as 16 bit numbers, but my checksum must be the 8 bit sum of the chars in the data packet. So I add up all my 8 bit chars and sometimes I get a larger number than FF. So, I've been doing a MOD to get it to be less than or equal to FF.
So I just do a FF MOD SCI1 TX
For example
: MOTSTARTMOTION ( ADDR -- )
AA SCI1 TX (packet header, do not add to checksum)
DUP SCI1 TX ( TO ADDR on stack )
05 SCI1 TX ( COMMAND BYTE - set gain )
05 + FF MOD SCI1 TX
; EEWORD
Since TX will only send out an 8 bit value, the question is, if I don't do the FF MOD, will only the lowest 8 bits of the 16 bit value get sent?