USART Multiprocessor communication.

Post here first, or if you can't find a relevant section!
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: USART Multiprocessor communication.

Post by ag123 »

The address is defined in your firmware, the protocol, not in the uart. it is not a hardware concept.

'modbus' can be extremely easy

Code: Select all

void setup() {
	Serial1.begin(115200);
}

#define ADDRESS 0x01;

void loop() {
	if (Serial1.available()){
		uint8_t c = Serial1.read();
		if(c == ADDRESS) {
			// do something
		}	
	}	
}
of course this won't be a functional 'modbus', but it isn't too far from this.

oh i read a little about RS485
https://en.wikipedia.org/wiki/RS-485
that 'enable' pins apparently is about enabling the receiver output or driver output or making them hi-z. I'd guess that would matter more when the slaves need to transmit. As if other slaves are not in hi-z mode, they may instead sink/short the signal to ground. This could also affect the master as rs485 has a different topology.

I'd guess it'd take some effort to figure it out. For purely stm32, you could make that pin hi-z by simply putting it in INPUT mode. But that interfacing external hardware e.g. MAX232 or MAX485 drivers could mean that more signal lines is needed.
Last edited by ag123 on Tue Sep 28, 2021 1:03 pm, edited 2 times in total.
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: USART Multiprocessor communication.

Post by fpiSTM »

Did you evaluate to try existing library. For example this one:
https://github.com/andresarmento/modbus ... dbusSerial

Don't know it it could fit your needs nor if it works with STM32core but this probably could help...
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: USART Multiprocessor communication.

Post by ag123 »

+1 try out the library suggested by fpiSTM, it may help avoid re-inventing the wheels.
mustaq_ahm
Posts: 31
Joined: Tue Sep 14, 2021 11:08 am
Answers: 2

Re: USART Multiprocessor communication.

Post by mustaq_ahm »

Special thanks to @ag123 . And thanks to everyone who ever spend your time and energy to reply me. I felt really bad after knowing how to address the slave microcontrollers with rotary switch. It was damn simple just to work on with rotary switch. When I stoped thinking way more out of box, I figured it out by very simple method with INPUT_PULLUP to access my rotary switch to give address to my slaves.

And thanks to all of you for your suggestion, opinions and corrections.
Post Reply

Return to “General discussion”