{"id":4137,"date":"2026-01-03T05:31:19","date_gmt":"2026-01-03T05:31:19","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=4137"},"modified":"2026-01-03T05:31:20","modified_gmt":"2026-01-03T05:31:20","slug":"stm32-uart-part-11-rs485-reception","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=4137","title":{"rendered":"STM32 UART Part 11: RS485 Reception"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-1024x683.png\" alt=\"\" class=\"wp-image-4138\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-1024x683.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-300x200.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-768x512.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-1150x767.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-750x500.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-400x267.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM-250x167.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/ChatGPT-Image-Dec-31-2025-at-10_38_23-AM.png 1536w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Part 2\u00a0focuses on receiving data over an RS-485 bus, where correct timing and bus state management are critical for reliable communication. <\/p>\n\n\n\n<p>For demonstration purposes only, the system behavior is to echo back the received data, allowing reception and bus control to be observed and verified easily.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>STM32CubeMX configuration.<\/li>\n\n\n\n<li>Firmware development.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. STM32CubeMX Configuration:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We shall continue from the previous guide here.<\/p>\n\n\n\n<p>Open the RS485 project in STM32CubeMX and select the UART that has been used, for this guide, USART1 has been used.<\/p>\n\n\n\n<p>Enable the interrupt for USART1 from NVIC settings tabs and click on generate project as follows:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"662\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-1024x662.jpg\" alt=\"\" class=\"wp-image-4140\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-1024x662.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-300x194.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-768x497.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-1536x993.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-2048x1324.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-1150x744.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-750x485.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-400x259.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_07-56-27-1-250x162.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This will update the project to make the UART operates in interrupt mode.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Thats all for the STM32CubeMX configuration.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Note: It is possible to use DMA to receive the data. You may apply the steps from <a href=\"https:\/\/blog.embeddedexpert.io\/?p=3769\" data-type=\"link\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=3769\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a> to convert the project from interrupt base to DMA based.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Firmware Development:<\/h2>\n\n\n\n<p>Open STM32CubeIDE and open main.c source file since the project is already imported to STM32CubeIDE from the previous guide.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">First, make sure that while 1 loop is empty as follows:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">while (1)\n  {\n    \/* USER CODE END WHILE *\/\n\n    \/* USER CODE BEGIN 3 *\/\n\n\n\n  }\n  \/* USER CODE END 3 *\/<\/pre><\/div>\n\n\n\n<p>Since everything is handled in the interrupt ISR.<\/p>\n\n\n\n<p>Next, in user code begin 2 in main function, start the UART to receive data in interrupt mode with IDLE line detection as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_UARTEx_ReceiveToIdle_IT(&amp;huart1, buffer, 20);<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In user code begin 0 in main.c file:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;C&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)\n\n{\tif(huart-&gt;Instance==USART1)\n\t{\n\t\tHAL_UART_Transmit(huart, buffer, Size, 100);\n\n\t\tHAL_UARTEx_ReceiveToIdle_IT(&amp;huart1, buffer, 20);\n\t}\n}<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>This function will be called either when full 20 characters are received or IDLE line is detected.<\/p>\n\n\n\n<p>Once the function is called, transmit the data that being received and rearm the UART to receive the data in interrupt mode again.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>That all for the firmware.<\/p>\n\n\n\n<p>Save, build and run the project as follows:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"34\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1024x34.jpg\" alt=\"\" class=\"wp-image-4132\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1024x34.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-300x10.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-768x26.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1536x51.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-1150x38.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-750x25.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-400x13.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13-250x8.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2025\/12\/2025-12-31_11-12-13.jpg 1986w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Results:<\/h2>\n\n\n\n<p>Using your choice of Serial terminal, send data to the RS485 using RS-485-USB adapter and you should see the data is echoed back.<\/p>\n\n\n\n<p>Here, I am sending the data each 1 second:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"707\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-1024x707.jpg\" alt=\"\" class=\"wp-image-4141\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-1024x707.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-300x207.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-768x530.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-1536x1060.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-1150x794.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-750x518.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-400x276.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54-250x173.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2026\/01\/2026-01-03_08-03-54.jpg 1866w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>This is all for the RS485. <\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Part 2\u00a0focuses on receiving data over an RS-485 bus, where correct timing and bus state management are critical for reliable communication. For demonstration purposes only, the system behavior is to echo back the received data, allowing reception and bus control to be observed and verified easily. In this guide, we shall cover the following: 1. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-4137","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4137"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4137"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4137\/revisions"}],"predecessor-version":[{"id":4142,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/4137\/revisions\/4142"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}