How to Interface RS485 Module with STM32

Поделиться
HTML-код
  • Опубликовано: 23 сен 2022
  • Purchase the Products shown in this video from :: controllerstech.store
    ________________________________________________________________________________________
    Check out the Modbus Playlist :::: • MODBUS STM32
    STM32 Playlist :::: • STM32 Tutorials
    UART IDLE Line Reception :::: • STM32 UART DMA and IDL...
    To download the code, goto :::: controllerstech.com/rs485-mod...
    ________________________________________________________________________________________
    ****** SUPPORT US BY DONATING*****
    paypal.me/controllertech
    ******Join the Membership******
    / @controllerstech
    Join the Discord Server / discord
    Join the Telegram Group t.me/controllerstechdiscuss
    Follow me on Instagram / controllerstech
    For more info, visit www.controllerstech.com
  • НаукаНаука

Комментарии • 44

  • @chrisidema
    @chrisidema Год назад +6

    I have a few tips about RS485 with STM32:
    1) use a bias network in addition to the termination resistor. You can look up "RS485 bias".
    Even if the RS485 line drivers have a "safe mode" they can still experience glitches on the receiver with the first byte. Especially if you don't share a GND.
    So you may miss or corrupt the first byte!
    2) STM32 UART RX doesn't have a hardware buffer. Receiving using interrupt is often too slow and you can miss data. Only DMA receiving works properly IMHO.
    3) You can use circular DMA for UART if you don't want to lose any data, but for RS485 this is not really needed. In fact it is best to clear any UART buffer after sending in case data ends up in your RX buffer.
    4) Note that when a glitch occurs an RX error will automatically halt DMA reception and you have to manually re-enable it. So enable the appropriate error interrupts (UART and/or DMA) and handle the errors appropriately or you may wait forever for data (though that only applies to an RS485 slave).
    5) Add short delays between switching Drive Enable and data transmission (before and after transmission). This makes communication more reliable.
    6) Enable Idle line detection interrupt. This is very useful in case you don't know how many bytes you are expecting. You receive an interrupt after receiving the last byte of a message.
    7) If you want to use very high Baud rates check the datasheet of your line drivers. They come in different speeds/slope limits.
    8) With any UART communication always verify your baudrate. With low clock frequencies you may not be able to get the exact baudrates you want due to rounding errors. Internal oscillators also have limited accuracy. It may work until it doesn't...
    9) When you want to connect it to the PC use the FT232R USB serial converter. It has a TXen pin that switches while it is sending. You can connect this pin to the RS485 DE pin. The alternative is to use the DTR or RTS pin, but this can switch too slow as Windows is not real time. Cheap USB-RS485 converters often use DTR and are not always reliable. So check the schematic before buying one.

  • @KWang_12
    @KWang_12 Год назад +1

    My favorite MLG voice tech channel

  • @abagnale7058
    @abagnale7058 Год назад

    The lecture was awesome. Can you make an RS-485 BUS for two stm32 microcontroller circuits?

  • @yudhahamdiarzi5553
    @yudhahamdiarzi5553 Год назад

    Great explanation. I use different module with auto logic for receive and transmit,so it's only need 2 pins. If possible i need knowledge about CAN J1939 and OBD2 :D

  • @DwinTechnologyOfficial
    @DwinTechnologyOfficial Год назад

    We have ASIC display chip, is it possible for you to try it?

  • @aflimohamed6448
    @aflimohamed6448 Месяц назад

    great explaination

  • @SamSmartLabs
    @SamSmartLabs 6 месяцев назад

    I got random data and I’m not able to establish communication it seems , I’m using 2 stm32f103 and the rs485 transceiver is MAX485

  • @kinomaniak123
    @kinomaniak123 Год назад

    Hi, great tutorial. I have one question - what voltage are You using to power the modules? If the voltage is 5V - do You need any voltage converter for data lines Rx/Tx?

    • @ControllersTech
      @ControllersTech  Год назад +1

      The voltage is 5V. The MAX485 chip takes care of thr conversion so we don't need any voltage converters.

    • @kinomaniak123
      @kinomaniak123 Год назад

      @@ControllersTech Thank You for reply.

  • @ThinhLe-ut9pr
    @ThinhLe-ut9pr Год назад +2

    hello, thanks for a great explaination, but I have a question. Could we connect the RO and DI pin of the MAX485 chip to RX and TX pin of USART2 instead of USART1 (on STM32L152RE)? because I had a project at school, we implemented the MODBUS RTU protocol, at first we used USART2 for debugging purpose, but after that we had to change to USART1 to deal with RS485 to USB converter, and I didn't know the reason why we had to change.

    • @ControllersTech
      @ControllersTech  Год назад +1

      You are using a nucleo board i guess. You tested it using the uart2 because in nucleo boards uart2 pins are shorted to be used as the vcp (virtual com port), so you don't need to connect an external hardware for uart, just the usb cable is enough.
      Now you want to use the rs485. This is why you used uart1, as the uart2 pin are being used as vcp and are not avaialble seperately.
      You can use any uart other than uart2. But if you insist on using uart2, then you need to see the schematics of the board and modify the hardware a little so that the pins are avaialble for external connection.

    • @ThinhLe-ut9pr
      @ThinhLe-ut9pr Год назад

      @@ControllersTechThank you very much, that is very helpful!

  • @xavierr4508
    @xavierr4508 День назад

    Hi, STM32 UARTs include RTS/DE pin functionality, but you're driving the DE pin manually, why? Isn't this be controlled automatically by the UART? So, what's the purpose of such DE pin?

  • @avr_stm_pro2955
    @avr_stm_pro2955 Год назад

    Спасибо 👍

  • @YAKITEMiguel
    @YAKITEMiguel 17 дней назад

    Hello, i want to interface a SmartEmbedded screen with an toshiba inverter and read out the inverter frequency on the screen by using RS485 wire with Stm32cubeIde, I would like to know if it´s possible ?

  • @koteswararaopokuri2301
    @koteswararaopokuri2301 Год назад

    Please make a video on stm32f4 with c11101rf transceiver by spi communication

    • @BB-ti9bf
      @BB-ti9bf Год назад

      Use CMSIS without HAL for deep understanding how it works, then you no need ask anyone make something to do it for you, it is freedom of creativity ☝️

  • @minecetinkaya5763
    @minecetinkaya5763 Год назад +1

    how to use 2 uarts 2 modules with one stm. I tried to combine codes but It does not work properly

    • @vincenttsai5116
      @vincenttsai5116 Год назад

      I have the same question, use uart1 transits, uart 2 receive, but it can't work.

    • @minecetinkaya5763
      @minecetinkaya5763 Год назад

      ​ @vincenttsai5116 It sould be. I use 4 modules now. Which one does not work. Did you try only receive and only transmit in while. If there is no data, maybe these tips help;
      1) check your enable pins and their connections. Be sure that you are using enable pins correctly.
      2) you should connect N to N and P to P.
      2) I'm offering you to use callback functions​ in normal mode.
      3) if you have logic analyzor try to observe is stm send any data.

  • @Rynxie
    @Rynxie 7 месяцев назад

    i want to make the communicate 2 stm32f103c8t6 stand-alone with no computer connection if it is possible that I give power both stms from same source and to max485s from stms 5v pn?

    • @ControllersTech
      @ControllersTech  7 месяцев назад +1

      Yes it's fine.

    • @Rynxie
      @Rynxie 7 месяцев назад

      @@ControllersTech thank you! I am new to electronics :p

  • @woldecosgrove
    @woldecosgrove 20 дней назад

    Hello great video ! i try your code on 2 H7A3 Nucleo, the TX board is working, but Rx board is not! is there any additional setting at IDE configuration that you miss out in the video? i dun understand the RxData[16] appear all 0 at Live Expression !
    can you advise...

    • @woldecosgrove
      @woldecosgrove 20 дней назад

      Hello... can u reply ...

    • @ControllersTech
      @ControllersTech  20 дней назад

      Nothing extra is needed. Make sure both RS485 has common ground.
      If it doesn't work, first check if simple uart transmission is working fine.

    • @woldecosgrove
      @woldecosgrove 19 дней назад

      @@ControllersTech Hello... i use same power supply to the 2 RS485 board, the power supply for the 2 H7A3 comes from 2 USB port is the fine? Tx board is able to transmit F103 to live experssion, but Rx board does not show any (RxData all 0s) UART transmission is working...

    • @ControllersTech
      @ControllersTech  19 дней назад

      If the simple uart is not working, theb RS485 won't work. You should look into that first.
      Also the tx buffer in live expression does not signify that transmission is working. The buffer simply changes because you are updating it in the code. You should use a logic analyzer or an oscilloscope to confirm if transmission is working.
      If you are using a nucleo board, do not use uart2, as it is connected to the st link.
      You should connect each board to the computer individually and check if uart tx and rx is working.

    • @woldecosgrove
      @woldecosgrove 19 дней назад

      @@ControllersTech Hello... i m using UART1 for both boards, power from USB port 1 and port 2, both the RS485 powered from external power bank. How should the common ground be wired? When i scope the Tx node A and B show correct waveform BUT 0.5v amplitude whats happed?

  • @phanendrabeella
    @phanendrabeella Год назад

    i need code for reccieve interface of rs 485 in interrupt method

    • @ControllersTech
      @ControllersTech  Год назад

      This video basically describes the RS485 to uart converter.
      If you are using this, then you can simply use the uart interrupt to receive the data.

  • @seimela
    @seimela Год назад

    What is the link to this software Q ide ,please share the link

    • @ControllersTech
      @ControllersTech  Год назад

      It's cube IDE..

    • @seimela
      @seimela Год назад

      @@ControllersTech Thanks got it ,this video got me to subscribe to your channel

  • @ahmedrefaie8671
    @ahmedrefaie8671 Год назад

    Please make a video to explain how to connect my computer stm32 via RS485

  • @ahmedrefaie8671
    @ahmedrefaie8671 Год назад

    Please is it possible to protect the code from theft?

    • @ControllersTech
      @ControllersTech  Год назад +1

      If you are talking about STM32, then yes it does.
      It have the methods to protect agains read and write operations.
      It depneds on the mcu you are using. It can be configured using the option bytes in the cube programmer.

  • @user-ox1gn4is1j
    @user-ox1gn4is1j 3 месяца назад

    Speed 😂

  • @user-ox1gn4is1j
    @user-ox1gn4is1j 3 месяца назад

    You cant teach to much speed 😂

  • @kaihorstmann2783
    @kaihorstmann2783 Год назад

    I think your explanation of voltage levels is plain wrong. This is a differential pair. Logic '1' is when A is low and B is high, and for '0' A is high, and B is low.
    Low and High are the same voltage levels for both lines. There is always a positive or negative difference between the two lines. A voltage difference of 0V as you showed is actually an undefined logical state and must be avoided.
    The absolute voltage level of the lines compared to ground is irrelevant as long as the limits are not exceeded. The signal is defined by the voltage difference between the two lines.