cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus over RS485 with STM32F303K8

RWedu.1
Associate II

I'm looking to make a loop of MCUs as slaves to a PC master so that I can send commands to them. The idea is to use the https://www.maximintegrated.com/en/products/interface/transceivers/MAX22025.html and https://www.ftdichip.com/Support/Documents/DataSheets/Cables/DS_USB_RS485_CABLES.pdf to be able to communicate over RS485. Note that the transceiver eliminates the need for DE and \RE. The question is however, how do I set up the MCUs for the Modbus protocol? I'm aware of the protocol implementations found online, but I'm unsure of the STM specific setup. In CubeMX I get this, with no RX pin and no options: 0693W000004KPkyQAG.pngThis is what the reference manual RM0316 says:

0693W000004KPrGQAW.png 

I'm a little confused as to how the UART should be set up for Modbus communication, so I appreciate any help!

Thanks

8 REPLIES 8
TDK
Guru

It's half duplex, so there is no RX pin. The TX pin pulls double duty.

I found quite a lot of hits when searching "modbus stm32". As is the nature of free software, I'm sure they are of varying quality and probably require you to do some of the work getting them to start.

If you feel a post has answered your question, please click "Accept as Solution".

That makes sense, thank you! Does this mean that the TX pin of the MCU should be connected to both the RXD and TXD pin of the transceiver? I see that it requires the TXD pin to be high to be able to receive data:

0693W000004KUCJQA4.png

It would be interesting what your solution was, I'm facing the same problem. Can you provide a schematic? Did you also used external pull-ups on the uart side?

Best regards

I ended up doing multiprocessors communication with addressing actually and implementing my own protocol over UART. I'm working on it now after leaving this project for a while. Do you still want more details or were you interested in the Modbus part?

Ahh ok, I read about it on your profile too. Right now I'm designing the PCB so I'm interested on how i need to connect the MAX with the STM32. I need to implement Modbus RTU so multiprocessor communication is no option for me i guess. Do you know if I need to connect the Rx and Tx pins of the MAX and connect it to the Tx pin from the STM32? Otherwise I will spend some jumpers so that I'm able to connect pins if needed..

Between the STM and MAX i have simply TX<->TX, RX<->RX(using both even if its half-duplex. The STM is configured to RX and TX), and 3V3<->VDDA. The RS485 bus side is supplied(VDDB) by the PC through to USB cable linked above. I use two 10kOhm pull ups for each node on the bus, one for A and one for B(no pull ups on the uart side). I put pull ups at the USB cable to the breadboard as well, considering it as a node. Between the USB and the MAX, I have A<->A, B<->B, GND<->GNDB and 5V<->VDDB. I don't have a schematic as I'm still prototyping on the breadboard.

Ok thank you :)

I will let you know what my schematic looks like in the end.. (when I know it)

Sorry, for B I use 10kOhm pull down of course :D