Page 2 of 2

Re: USART Multiprocessor communication.

Posted: Tue Sep 28, 2021 11:37 am
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.

Re: USART Multiprocessor communication.

Posted: Tue Sep 28, 2021 12:19 pm
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...

Re: USART Multiprocessor communication.

Posted: Tue Sep 28, 2021 1:27 pm
by ag123
+1 try out the library suggested by fpiSTM, it may help avoid re-inventing the wheels.

Re: USART Multiprocessor communication.

Posted: Tue Sep 28, 2021 8:49 pm
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.