Receive data using UART in STM32 || Poll || Interrupt || DMA

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ย. 2024

ความคิดเห็น • 126

  • @tonyyang1024
    @tonyyang1024 2 ปีที่แล้ว +10

    Hello Controllers Tech, I don't know if you can see this, but there is one more detail that can be mentioned:
    CubeIDE sometimes generates the MX_DMA_Init() after the corresponding UART init function.
    This leads to errors that won't even show up in the handle.
    The solution to this is reordering the init functions from the code generator app, in Project Manager/Advanced Settings.

  • @onurdemir42
    @onurdemir42 5 ปีที่แล้ว +2

    Why didn't you configure 'dma circular' on cubemx?

  • @DereC519
    @DereC519 ปีที่แล้ว

    My UART is not receiving, and does not seem to change the data types at all. Any help? My IDE (stm32) does not allow for the viewing of live variables which kinda sucks

  • @DereC519
    @DereC519 ปีที่แล้ว +1

    Never mind. After hours I realized you have to attach the ttl adapter TX and RX to the RX and TX pins, not the other way around

  • @Yassin_Ro
    @Yassin_Ro 3 ปีที่แล้ว +1

    Great Video😊
    Can you tell me please how can I delete the received data from Rx_buffer and to receive new data from Rx_buffer[0] ?

    • @nerdom1610
      @nerdom1610 3 ปีที่แล้ว

      Not sure if it will help you now but you can do
      memcpy(Rx_buffer, 0, (length you set for Rx_buffer));
      that will set it to all null (0 = null )

  • @branislavbaran8108
    @branislavbaran8108 5 ปีที่แล้ว +1

    Awesome video!!! Please make similar for I2C communication. Thank you!

  • @yaghiyahbrenner8902
    @yaghiyahbrenner8902 6 ปีที่แล้ว

    wow man, Just wanted to say thank you for this video. really appreciate this.!

  • @poijmc606
    @poijmc606 4 ปีที่แล้ว

    Thank you very much! I was using POLL recieve and had exact issues as shown, IT or DMA will solve my problem

  • @pdeepakjayan5515
    @pdeepakjayan5515 ปีที่แล้ว

    Sir, I am trying to receive gps data each second using interrupt function.What I understood is that,I had enabled the global interrupt in stm32 configuration for uart3, and whenever the interrupt triggers,the programs goes to the callback function which is hal_uart_rxcpltcallback.The program reaches the function..I do some processing again and then enable the interrupt again..The next sexond when the data arrives at 100ms after a pps signal(reference signal marked for 1 second),again interrupt is triggered , program goes to callback function, does the particular function, comes out of callback function.This happens in every 100th -130th millisecond of each second.I understood that whenever the codes enters the callback, ,the interrupt is diabled and we need to enable the interrupt again to receive the next data..Altogether 300bytes of data arrives from 100 to 130milliseconds..After 130 milisecond,if suppose some random data arrives, the interrupt may still trigger, since each time i enable the interrupt while coming out of callback function..how to stop receing the interrupt after 300millisecond? Can i use abort function?? Also can you please explain What is the differnce between isr function and callback function??Looking forward for your reply.

  • @eleckim
    @eleckim 6 ปีที่แล้ว +2

    잘 보았습니다. 감사합니다.
    I appreciate your tutorial video. Thank you! ^^

  • @attilahun7994
    @attilahun7994 3 ปีที่แล้ว +1

    Fantastic explanation thanks a lot

  • @cassianocampes
    @cassianocampes 4 ปีที่แล้ว

    Great video. This shows everything I needed.

  • @Stimmenhotel
    @Stimmenhotel 4 ปีที่แล้ว +1

    Thank you for making this video! It is very basic and easy to understand. But I am curious if there is more than the "Half Data" function differnece between IT and DMA. But your video already answered a part of my questions about this topic. Maybe I still have to look into the HAL documentation ... :)
    On suggestions about your videos: I am no "youtube maker expert" but I have seen videos who used the subtitles for adding text or just made a overlay text hardcoded into the video instead of using the editor. Even if using the editor slowing the "information stream" a lot, it still breaks the flow (sorry if i am not clear with this, i am not a native english speaker).
    Oh and if there is a way to increase the transparency of the yellow circle around the coursor, it would make the text beyond more visible, which would be great. (maybe it has something to do with video compression here?)
    Well thanks anyway and keep up the great work :)

  • @ShaikJaavid
    @ShaikJaavid ปีที่แล้ว

    small request from me . please post videos on Quectel mc60 modules . because there are not much videos on them . if you have time please give a try.

  • @niravjasani711
    @niravjasani711 5 ปีที่แล้ว +1

    I have to receive gps string , but the size of it is not fixed . How do I make it possible ?

    • @ControllersTech
      @ControllersTech  5 ปีที่แล้ว

      Check out the uart circular buffer video

  • @macasas8133
    @macasas8133 4 ปีที่แล้ว +1

    Awesome! really helpfull. Love the music

  • @thangduong8799
    @thangduong8799 3 ปีที่แล้ว +1

    Can you tell me please how can I delete the received data from Rx_buffer and to receive new data from Rx_buffer[0] ?

  • @naftidhia
    @naftidhia 3 ปีที่แล้ว

    Hallo can it works with xbee pro s1 module?
    thanke you

  • @user-ng2dl4eg9y
    @user-ng2dl4eg9y 2 ปีที่แล้ว

    hi! i followed all your instruction but i can't recive data with interrupt. i'm using stm nucelo f411re. is it maybe a matter of soldering/desoldering something? thanks

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      Don't use the pins marked as rx and tx, towards the bottom right corner, on nucleo. Use some other uart like uart 1.

    • @user-ng2dl4eg9y
      @user-ng2dl4eg9y 2 ปีที่แล้ว

      @@ControllersTech thanks for the hint! i risolvere the issue👍

  • @陳鴻進-k1r
    @陳鴻進-k1r 5 ปีที่แล้ว

    I got the demo program.Thank you very much.

  • @omerfarukuslu4212
    @omerfarukuslu4212 2 ปีที่แล้ว

    I did it same . But I receive 1 byte data again.I dont know what can ı do

  • @RaggooCollective
    @RaggooCollective ปีที่แล้ว

    If the stm32 is the primary cpu, and it controls the booting of a dm368 (in nand boot mode), is it possible to use the uart port on the stm32 to reflash the dm368 nand, or change the bootsel of the dm368 to uart from nand?

  • @MohammedAltowayti
    @MohammedAltowayti 8 หลายเดือนก่อน

    I'm using STM32 NUCLEO-F411RE chip... Can you help me write a code to make it capture an image using OV2640 and store it in pc folder?

  • @wegi9621
    @wegi9621 10 หลายเดือนก่อน

    0:50 Why choose Crystal ceramic resonator as clock source when it doesn't exist on this board? Shouldn't you choose "Bypass clk source"?

  • @krishnakulkarni6574
    @krishnakulkarni6574 4 ปีที่แล้ว +1

    It was a great video, it helped me so much. I have a question, we are giving size of buffer to fill in the buffer for interrupt receive, but if the length of data which we are receiving is not known then how to receive it? i mean like if we write in API to receive 8 bytes of data and we got only 4 bytes then next time when we receive 4 bytes again then in the previous buffer the data will be written at position 4-7. how to solve this issue? thanks in advance

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว +5

      If u want to receive the data which is of unknown length, watch the uart ring buffer video. It does that job.
      ST don't have anything implemented by default to tackle this problem

  • @alewarten
    @alewarten 2 ปีที่แล้ว

    Thank you! Why do you use usart2, but not usart1?

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      connecting with computer using usart2 is easier in nucleo boards

    • @rg99999
      @rg99999 2 ปีที่แล้ว

      @@ControllersTech could you explain why? I’m learning mcu programming.

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      It simply connects via the usb cable without the need for external hardware. That is how it's designed.

  • @davidadjoyi7015
    @davidadjoyi7015 2 ปีที่แล้ว

    Hi !
    I am starting with stm32 and I would like to read and write data by UART in interrupt mode with flow control RTS / CTS ... I can transmit but not receive. Please beg to help me!
    Thank you!

    • @fuzzs8970
      @fuzzs8970 2 ปีที่แล้ว +1

      Hi
      Have you been able to solve the problem?

    • @davidadjoyi7015
      @davidadjoyi7015 2 ปีที่แล้ว

      @@fuzzs8970 Yes thanks !
      I am trying to get an stm32l071xx and an stm8 to communicate in LPUART mode. The stm32 must receive the data transmitted by the stm8. I need help sorry!

    • @fuzzs8970
      @fuzzs8970 2 ปีที่แล้ว

      @@davidadjoyi7015 hi
      Unfortunately i don't know much either but very interested in learning about it

  • @陳鴻進-k1r
    @陳鴻進-k1r 5 ปีที่แล้ว

    This video is very nice for me. May I have this demo program ?

    • @ControllersTech
      @ControllersTech  5 ปีที่แล้ว

      Goto the link in the description. You can download it from there....

    • @陳鴻進-k1r
      @陳鴻進-k1r 5 ปีที่แล้ว

      Sorry, The code of link are broken now. By the way, My E-mail is hjchen@mail.hdut.edu.tw , Would you please send the demo code for me.

    • @ControllersTech
      @ControllersTech  5 ปีที่แล้ว

      Yeah. Sorry about that. I just saw the file is actually missing from the drive. I'll re-upload it asap. Wait for few hrs..

  • @chakrounimen7432
    @chakrounimen7432 ปีที่แล้ว

    Hello ControllersTech,
    Thanks a lot for this video, i've got a question:
    _ |s there a way to make uart_it in none circulare mode i want my data to starts writings from the beginning like the Poll mode?
    I will be so grateful!

    • @ControllersTech
      @ControllersTech  ปีที่แล้ว +1

      Uart interrupt receive is in a non circular mode i guess.. just cross check it once.

  • @sharana.p6161
    @sharana.p6161 3 ปีที่แล้ว

    Thank you so much for the great video. Please tell me how to do this using the register level.

  • @kayipchan832
    @kayipchan832 5 ปีที่แล้ว

    A very useful video thank you!

  • @artedesing
    @artedesing 6 ปีที่แล้ว

    I did not succeed the led gets to flash more in debug mode does not receive data !!! helps my board and the stm32f767zi

  • @minecetinkaya5763
    @minecetinkaya5763 ปีที่แล้ว

    While using poll method, it does not receive more than 1 byte even though I change timeout to 1000. How can I fix this

    • @ControllersTech
      @ControllersTech  ปีที่แล้ว

      You have to set the function to receive more bytes.
      Hal uart recieve takes the parameter of how many bytes you want to receive.

    • @minecetinkaya5763
      @minecetinkaya5763 ปีที่แล้ว

      @@ControllersTech I set the size parameter of function as 4. Here is my code
      uint8_t rx_buffer[10];
      HAL_UART_Receive(&huart1, rx_buffer, 4,1000);

  • @sudarshanjagannathan6599
    @sudarshanjagannathan6599 4 ปีที่แล้ว

    I did exactly what you specified for the POLL method, the timeout is even affecting my LED toggle likr you said, but I'm not receiving any data in the array. Can you think of any reason? Only thing I probably did different is the clock, but the peripheral clock shouldn't matter for UART since it's asynchronous, right?

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      You are right... It's not the clock. You have to receive more than 1 byte of the data. If the rx_buf[2], than input the length as 2. The uart will wait in the blocking mode, until 2 bytes have been received.

    • @sudarshanjagannathan6599
      @sudarshanjagannathan6599 4 ปีที่แล้ว +1

      @@ControllersTech , I was able to solve the issue. The issue turned out to be with the clock somehow, I just created a new file without changing the clock configuration at all as opposed to the first time when I made the change to the clock like you did in this video. Can you explain why you have changed the clock configuration in this video?

  • @sunnyhapse4743
    @sunnyhapse4743 2 ปีที่แล้ว

    what about 2 UART is use in the device ???

  • @Minas__Morgul
    @Minas__Morgul 3 ปีที่แล้ว

    Thank u for the video.
    What about if I want to use HAL_UART_Receive_IT function and I send 5 or 6 bytes (more than 4)? Zero byte RX[0] will be overwrite with fifth byte. And if I send another 4 byte command program will stock. How can I solve it? Plz Help

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      There is nothing to solve in that. That's how it is supposed to be.

  • @RixtronixLAB
    @RixtronixLAB 4 ปีที่แล้ว

    @9:14 at RxCallback, can I put strcmp ? or where can I put strcmp in interrupt mode ? thanks

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      You can.. but you should avoid writing too much code in the ISR.

    • @RixtronixLAB
      @RixtronixLAB 4 ปีที่แล้ว

      @@ControllersTech so I need to create another function and call that function from that ISR ?
      Looks like it's not responding to HAL_UART_Receive_IT, what do I miss here ?
      void Relay_Control()
      {
      i = strcmp (Rx_data,buf2);
      if (i==0)
      {
      printf("char match RELAY OFF
      ");
      }
      }
      void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
      {
      Relay_Control();
      HAL_UART_Receive_IT(&huart3, Rx_data, 4);
      }
      Thanks

    • @RixtronixLAB
      @RixtronixLAB 4 ปีที่แล้ว

      @@ControllersTech Do I need to enable global interrupt for UART3 in STM32CubeMX ? thanks

    • @RixtronixLAB
      @RixtronixLAB 4 ปีที่แล้ว

      What do you think?

    • @ControllersTech
      @ControllersTech  4 ปีที่แล้ว

      Join the group and ask there.. yt is noot really a good platform for the chat

  • @rohithsai7759
    @rohithsai7759 3 ปีที่แล้ว

    For my usart 1 the corresponding gpio pins I need to configure as usart TX and usart rx or gpio in and gpio out if it's gpio which pin I should configure as in and out?
    I followed the same steps as ur video still not getting any interrupt kindly help

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      Just select the uart, and it will select the pins automatically.
      Also make sure you enable the uart interrupt in the nvic tab.

    • @rohithsai7759
      @rohithsai7759 3 ปีที่แล้ว

      @@ControllersTech Thanks for your reply
      Tried n number of times and followed ur same steps not getting an interrupt pls help with what would gone wrong.
      Thanks.

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว

      Contact on discord or telegram..

    • @rohithsai7759
      @rohithsai7759 3 ปีที่แล้ว

      @@ControllersTech can I get the link of your telegram channel??

  • @dnyaneshvarsalve2984
    @dnyaneshvarsalve2984 2 ปีที่แล้ว

    I using stm32L475 in dev board B-L475E-IOT01A, I did everything as mentioned in video, but I am not able to receive any data from serial terminal.
    can you plz help

    • @dnyaneshvarsalve2984
      @dnyaneshvarsalve2984 2 ปีที่แล้ว

      Its working now. I had to remap my UART pins as per the USER MANUAL.
      Thank for the video

    • @user-ng2dl4eg9y
      @user-ng2dl4eg9y 2 ปีที่แล้ว

      @@dnyaneshvarsalve2984 how?

    • @dnyaneshvarsalve2984
      @dnyaneshvarsalve2984 2 ปีที่แล้ว +1

      @@user-ng2dl4eg9y I think you got confused due the use of word "remap". Sorry for that.
      In my code while assigning pins to UART peripheral I had used wrong pin numbers, that was the problem.

    • @user-ng2dl4eg9y
      @user-ng2dl4eg9y 2 ปีที่แล้ว

      @@dnyaneshvarsalve2984 oh ok. Thanks! Well anyway i risolvere the issue👍

  • @Gibrannachus
    @Gibrannachus ปีที่แล้ว

    Does anyone know how an arduino, for example, always receives all the characters correctly, without knowing how many we are going to write in advance?

    • @ControllersTech
      @ControllersTech  ปีที่แล้ว

      You can read the arduino library and know yourself. Its not that complicated.
      Anyway there is similar implementation in STM32 also, you just need to search for it.
      th-cam.com/video/wj427hpP81s/w-d-xo.html

  • @sayma25n.46
    @sayma25n.46 4 ปีที่แล้ว

    Thank you very much !!

  • @lonny_breaux
    @lonny_breaux ปีที่แล้ว

    Please note for DMA: If using newer version of CubeIDE - code configuration is wrong by default.
    In main ->
    change :
    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_USART2_UART_Init();
    MX_DMA_Init();
    /* USER CODE BEGIN 2 */
    To:
    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_DMA_Init();
    MX_USART2_UART_Init();
    /* USER CODE BEGIN 2 */
    I FOUND THIS INFO IN COMMENT UNDER THIS VIDEO - th-cam.com/video/urHGtvLYctk/w-d-xo.html&ab_channel=Weblearning

  • @siddharthmali5841
    @siddharthmali5841 2 ปีที่แล้ว

    Excellent.

  • @vb9950
    @vb9950 2 ปีที่แล้ว

    "Notice that data gets written in the buffer in circular mode. Unlike the poll method where it starts from the beginning." at 10:16. This is wrong. I tested it and this is behaving like cicular mode.

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      Which one is behaving in circular mode ? Poll or interrupt

    • @vb9950
      @vb9950 2 ปีที่แล้ว

      @@ControllersTech Both are behaving in circular mode.
      The one in the quoations of my above comment is the one you mentioned in the text file opened in notepad.

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      Hmm ok. This video is 3 4 years old. Maybe ST has changed the things after that. Even I don't used the poll method alot, so I don't know much about the changes

    • @vb9950
      @vb9950 2 ปีที่แล้ว

      @@ControllersTech Since I'm using HAL this might be true.

  • @electronicsguy8609
    @electronicsguy8609 3 ปีที่แล้ว

    awesome!, thank you

  • @paulchui3739
    @paulchui3739 4 ปีที่แล้ว

    Thank you very much

  • @RixtronixLAB
    @RixtronixLAB 4 ปีที่แล้ว

    thanks for the info :)

  • @Nandhakumar-rf9jx
    @Nandhakumar-rf9jx 2 ปีที่แล้ว

    Hai , Thanks for the wonderful video. Actually I used UART rx with DMA method...I sent 30 buffer size of data (example: 0123456789abcdefghijklmnopqrst)..after long time transmission, the data were shifted 4 bytes and received in rxcallback loop as (qrst0123456789abcdefghijklmnop)...therefore, after sometime rx data shifting as circular...but I don't want like this...can you please give me a better solution.

    • @ControllersTech
      @ControllersTech  2 ปีที่แล้ว

      Don't enable the circular mode in DMA.

  • @nhutnguyenminh4064
    @nhutnguyenminh4064 7 หลายเดือนก่อน

    i send but it not receiver although the code is same :>

  • @KirtanSakriya
    @KirtanSakriya 9 หลายเดือนก่อน

    what version of ide are u using?

    • @ControllersTech
      @ControllersTech  9 หลายเดือนก่อน

      Please check the latest videos on the channel. They cover uart in depth.

  • @bwajih
    @bwajih 2 ปีที่แล้ว

    great, thank you

  • @sysmaxim7
    @sysmaxim7 ปีที่แล้ว

    최신버전으로 업데이트 해주세요.

  • @syauqisabili3776
    @syauqisabili3776 5 ปีที่แล้ว

    How to reset buffer rx?

    • @ControllersTech
      @ControllersTech  5 ปีที่แล้ว

      You can assign ('\0') inside a for loop

    • @syauqisabili3776
      @syauqisabili3776 5 ปีที่แล้ว

      @@ControllersTech thank you sir

    • @thangduong8799
      @thangduong8799 3 ปีที่แล้ว

      can you write code about it if you got it?
      i have the same problem with you?
      thank you

    • @thangduong8799
      @thangduong8799 3 ปีที่แล้ว

      Can you tell me please how can I delete the received data from Rx_buffer and to receive new data from Rx_buffer[0] ?

    • @ControllersTech
      @ControllersTech  3 ปีที่แล้ว +1

      Memset (rx_buffer, '\0', size);

  • @thekorink
    @thekorink 4 ปีที่แล้ว

    mantap Pak.

  • @mohamedaminemejri8920
    @mohamedaminemejri8920 5 ปีที่แล้ว

    aychou frer