Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Communicating question

Shituation

New Member
Hi, everybody
I've connected two microcontrollers (ATmega32A&ATmega8A) with USART.
M32 sends some variables two M8. Then M8 sends them to LCD. There are different data to be sent to the M8 such as frequency, voltage and etc.
How can M32 explain to M8 that what is each data witch has sent? Imagine M32 sends frequency, voltage and other variables to M8 consecutively and repeatedly.
Thanks.
 
Some ways of doing that:

Send data one nibble (4 bits) at a time, with the data in the low half of the byte and the sequence or location in the high half. That gives 16 "addresses" of where to put the data in 8 bytes; update the display when the last one of the set is received.

Send a fixed number of bytes for each complete data block, with a timeout interval between transmissions that resets the receiver to expect a new set of data in order.

Use 7 bit data, and use the high bit as an indicator of a new sequence start (that's how MIDI works between musical instruments).

You can also use that a "command" with eg. the high bit set, then data with it clear; the command tells the receiver what set of data will follow.

You can also use the "command" byte method to just tell the display what screen position to put the cursor, then send plain text that's written to the screen starting from there.
Pad each item to a fixed size with spaces, to ensure the previous text is overwritten.
That allows you to totally control the screen layout from the master device.

For larger screens I've used a full ANSI terminal command set before now; that's a method used for screen control on serial line (RS232) terminals, that gave very comprehensive control of a display with just (mostly) plain text.
Info here:
 
There are many ways to do it - packets are the usual way. So you don't sent bytes of data, you send a 'packet' of data, think of it as an envelope full of all the data.

Essentially you need to sent a 'start', then the data, then an 'end' - the 'end' can just be CR/LF. If the data is multiple items, and can be different sizes, then you need a separation character as well, a comma is pretty common.

So something like "D1234, 5678, 4567CR/LF".

Or you could do individual packets - like:

"V1234CR/LF" for voltage, or "A5678CR/LF" for current.

Or use much more expressive terms, I'm doing that between a PIC and an ESP32 controlling a GSM modem.

My table of 'starts' is this:

Code:
// list of incoming commands to search for
#define NumCommands 18

char master_list[NumCommands][10] =
{
    "READING=",
    "SIGNAL=",
    "NETWORK",
    "APNOK",
    "BATTERY=",
    "SHUTDOWN=",
    "NETFAIL",
    "APNFAIL",
    "ESP32=",
    "OK",
    "REPLY",
    "IMEI=",
    "ERROR=",
    "MESSAGE=",
    "BRIGHT",
    "CCID=",
    "SENDSMS",
    "BEEP"
};

The commands themselves can contain multiple values, separated by commas, and the receive routine parses them to a string array and an integer array (for any numbers), and sets variables for how many entries were found.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top