logo elektroda
logo elektroda
X
logo elektroda

[stm32] [rs485] ST485CDR Interface, Voltage Converters & AVTMOD-03 Module: Communication Issues

polimorf 7712 16
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 10278510
    polimorf
    Level 13  
    Hello.

    I have a plate of my own design, having an interface rs485 on us ST485CDR. Between START's usart1 and st485 there are 3 voltage converters 3.3V - 5.0V.
    In addition to testing the communication, I bought the AVTMOD-03 module (usb-rs485).

    The problem is that I can not pick up anything from usart1, the broadcast sometimes works (like debugging after a step or if the debugger is disconnected).

    To check start's start and voltage converters I desoldered st485 and in this place I connected the module with MAX232 (5V) - communication was working on both sides - that is, voltage converters work.

    In the program I also have a 3 ms delay between controlling the connected re and de st485 pins between sending and receiving.

    Does anyone know what could be the reason for this?
  • ADVERTISEMENT
  • #2 10278963
    Krotki
    Level 14  
    If you think that the error is in electronics, send the diagram if you can show the code in the program. If it is difficult to guess what is wrong :)
  • #3 10279307
    polimorf
    Level 13  
    the diagram is as follows - standard:
    [stm32] [rs485] ST485CDR Interface, Voltage Converters & AVTMOD-03 Module: Communication Issues
    these 4 elements 3 resistors and capacitor are unmounted - this is a circuit recommended by ST instead of a 120R resistor (less power-hungry).

    code from maina:
    [code:1:cad783aa3a]
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);

    GPIO_Conf.GPIO_Pin = GPIO_Pin_10;
    GPIO_Conf.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Conf.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_Conf);
    GPIO_SetBits(GPIOB, GPIO_Pin_10);

    USART_Config_Default();

    volatile uint32_t tmp;
    while(1) {
    GPIO_ResetBits(GPIOB, GPIO_Pin_10);
    for(tmp=0;tmp
  • #4 10279416
    Krotki
    Level 14  
    On the RS485 line you must have a forced state through resistors plus terminators (here R20 + capacitor) at the ends of the bus. This idea with a capacitor is pretty cool, but I do not know if it limits the transmission speed.

    Generally, I use 3 resistors: R18 and R19 -> 560 ohms and R20 -> 120 ohms.

    In addition, it is also worth combining the masses - the rs485 specification speaks of max. 7v potential difference receiver / transmitter.

    As for the program, I will not say it because I'm starting with stm32 :P
  • ADVERTISEMENT
  • #5 10280765
    polimorf
    Level 13  
    It is possible that I have a damaged converter usb-rs485 - I ordered 2.
    I have replaced us st485 with a new one and it is the same situation - no communication.
  • #6 10280820
    Krotki
    Level 14  
    Do you have any instructions for this converter? According to the rs485 A specification, this inverting output, B is a non-inverting output. Your converter has the reverse as most manufacturers of this type of equipment. Try after switching lines eg A with B :)

    Of course, assuming you have connected resistors :D
  • #7 10282474
    polimorf
    Level 13  
    I connected the resistors, I put the wires, added the common ground, I exchanged max485 from the avt module on ST485 and nothing. Did not work.

    I will wait until the new usb-rs485 module comes - it will then test whether it works.

    Thanks for the help.
  • ADVERTISEMENT
  • #9 10282859
    polimorf
    Level 13  
    Thanks - an interesting document, maybe I will take advantage.

    Now I can not even pick up anything from the device, sometimes the diode begins to blink from receiving - rarely (but the terminal is still empty).
    I'll wait for the adapter.
  • #10 10323629
    polimorf
    Level 13  
    I already have a new adapter.

    Teraj after connecting wires as before (the adapter is different than before) I receive data every time.
    Unfortunately, when sending it works only when I debug and step through USART_SendData (that's why I assume that the electronics are OK). With normal float or debugging without stopping, nothing comes on the terminal - it does not help even inserting a second break before sending.

    Any ideas?

    [Edit]
    Correction of only single sending of 1 byte data does not cause changes on the terminal.
    In burst mode :) when I send data in a loop, a lot of data comes in, but I do not know if all.

    [Edit]
    when I send data in a series of 10 bytes, I receive from 5 to 9 bytes. And when I send individual data, I have to send 2 bytes to get 1 and it often does not help.
    It was not possible to postpone the elements and try out the other combinations - the same error persisted.
    I checked 3 combinations:
    1. without a 120R resistor between wires A and B.
    2. with resistor and capacitor between A and B - as in the diagram.
    3. with a 120R resistor between A and B.
  • #11 10324130
    Krotki
    Level 14  
    Comment both delay lines:
    for (tmp = 0 tmp
  • ADVERTISEMENT
  • #12 10324182
    polimorf
    Level 13  
    Unfortunately, the same after the correction.
    As I send 2 same bytes, almost always one comes (at 1200).

    [Edit]
    Oddly, at 115200, it's the same - except that an additional bush appears as a sign.
  • #13 10324715
    Krotki
    Level 14  
    The time dependence is the blame ... you should build the best rotating buffer where in the interrupt you add the incoming character, and you download at the beginning. In addition, you must remember that you have half-duplex mode (common bus), or when you start transmitting many characters to the microcontroller you must inform him when he has to answer (eg sign of the end of the transmission, fixed command size, releasing the line for a specified period between characters) - the right Protocol.

    Now you have to pick the mark and immediately try to send it even though the line is busy with computer transmissions. In order for the microcontroller to reply, you must give him time between the characters or cache and send back with a delay.

    A somewhat chaotic statement, but I hope I was able to explain :)
  • #14 10324926
    polimorf
    Level 13  
    Krotki wrote:
    The time dependence is the blame ... you should build the best rotary buffer where in the interrupt you add the incoming character, and you download at the beginning.

    I send the same sign I received from the master several times.

    Krotki wrote:
    addition, you must remember that you have half-duplex mode (common bus), or when you start transmitting many characters to the microcontroller you must inform him when he has to answer (eg sign of the end of the transmission, fixed command size, releasing the line for a specified period between characters) appropriate protocol.

    Now, after each received character from the master, the slave sends 2 characters

    Quote:

    Now you have to pick the mark and immediately try to send it even though the line is busy with computer transmissions. In order for the microcontroller to reply, you must give him time between the characters or cache and send back with a delay.

    I gave him a break for 10 seconds - he is the same.

    I watched the waveforms on the oscilloscope and everything looks good - comparing with this document which link you gave me.
  • Helpful post
    #15 10325112
    Krotki
    Level 14  
    I have already lost it.

    So how do you press 2 characters from a PC termminal, you get 2 the same on the terminal?

    You do not have the automatic echo option selected?
  • #16 10325195
    polimorf
    Level 13  
    Quote:
    So how do you press 2 characters from a PC termminal, you get 2 the same on the terminal?

    I am just coming to the terminal with only one sign - although I am sending 2 - only this is how it works.
    If I send one sign from the prock, no one comes to the terminal.

    I do not have an automatic echo.

    [Edit]
    [stm32] [rs485] ST485CDR Interface, Voltage Converters & AVTMOD-03 Module: Communication Issues
    channel 0 and 1 is RS485
    channel 2 is tx uart

    Okay, all right - I just looked at it today.
    Thanks for the help.
  • #17 10327391
    HumunD
    Level 11  
    I suggest to read the ST documentation how to correctly perform RS485 support for stm32. In the proposed solution, ST uses the TC flag transmit complete. So after the correct byte sending, an interrupt is called, after the last byte you switch the RS485 into the reception mode, without calculating the late, etc. :D

Topic summary

The discussion revolves around communication issues with an RS485 interface using the ST485CDR chip. The user designed a custom board with voltage converters and an AVTMOD-03 USB-RS485 module. Initial tests showed intermittent communication, prompting the user to check the circuit and code. Suggestions included verifying the wiring, ensuring proper resistor values for termination, and checking the RS485 signal lines. The user replaced components but continued to experience issues, particularly with data transmission reliability. Recommendations included using an oscilloscope for debugging, implementing a proper communication protocol, and consulting ST documentation for RS485 support on STM32 microcontrollers.
Summary generated by the language model.
ADVERTISEMENT