Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 13


Byte 2 is a command code.
Additional bytes can contain data specific to the command. Some com-
mands have no command-specific bytes.
The final byte is a line-feed code (0Ah) that signifies the end of the message.
A CR code (0Dh) can precede or follow the LF but isn’t required.
On receiving a message from the primary node, a secondary node returns a
message with this format:
Byte 0 is a “:” character that signals the start of a response.
Byte 1 is the address of the node returning the response.
Additional bytes can contain data specific to the command. Some responses
have no command-specific bytes.
The final byte is a line-feed code that signifies the end of the message. A CR
code can precede the LF but isn’t required.







The code example in this chapter implements two commands: read_byte and
write_byte. On receiving a valid command, a node returns a response. A node
that receives an unsupported command or detects an error returns no response.

 

65 


The read_byte command requests a byte of data from a specified location in a
secondary node. The location is an application-defined byte that can indicate a
port or variable:

!
 

   
%""2""
.6(

   

0 : (ASCII 58) Start-of-communication indicator
1 address Identifies the recipient
2 1 (ASCII 48) read_byte command code
3 location Identifies the location to read
4 LF (ASCII 10) End-of-communication indicator
Free download pdf