element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum Issue with Receiving Structured Data via UART Callback on STM32
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 9 replies
  • Answers 1 answer
  • Subscribers 286 subscribers
  • Views 1539 views
  • Users 0 members are here
  • usart
  • sensors
  • stm32f407ig
  • stm32
  • uart
  • electronics
  • stm32f4discovery
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

Issue with Receiving Structured Data via UART Callback on STM32

pooja_14
pooja_14 9 months ago

Hello,

I'm working with two different STM32 microcontrollers:

  • Sender: STM32F4CCUx
  • Receiver: STM32F4VET6

I am sending a packet (which is a structure of size 4) from the sender to the receiver using UART, with both microcontrollers utilizing the UART callback function for transmission and reception.

Here is the process I’m following:

  1. The sender sends a packet using HAL_UART_Transmit_IT.
  2. The receiver is configured with HAL_UART_Receive_IT.
  3. Both microcontrollers handle data in their respective callback functions.

However, on the receiving side, the data is either jumbled or incorrect.

Details:

  • The packet is a structured type with multiple fields.
  • I’ve ensured that the baud rate and UART configurations match on both microcontrollers.
  • The callback functions seem to be triggering correctly.
  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz 9 months ago +1 suggested
    There are a lot of useful examples (google ' STM32 UART interrupt receive example '). It would be best to start with one of those examples, so that you have known working code. Some of those examples…
Parents
  • balajivan1995
    0 balajivan1995 9 months ago

    If you could share the contents of callback functions, it'll be useful.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • balajivan1995
    0 balajivan1995 9 months ago

    If you could share the contents of callback functions, it'll be useful.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • pooja_14
    0 pooja_14 9 months ago in reply to balajivan1995

    void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

    {

    if (huart->Instance == USART3) // Check if the interrupt is from USART3

    {

    process_packet((uint8_t *)&rx_buffer, 10);

    HAL_StatusTypeDef status = HAL_UART_Receive_IT(&huart3,(uint8_t *) &rx_buffer,10);

    }

    } //i tried using DMA,IT,receive to idle.everything shows the same problem.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • obones
    0 obones 9 months ago in reply to pooja_14

    I'm not sure what "process_packet" is doing, but I find it suspicious that is is placed BEFORE the call to HAL_UART_Receive_IT as I'm under the impression that the latter is the call that gets the data from the serial buffer into userspace buffer for it be further processed.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balajivan1995
    0 balajivan1995 9 months ago in reply to pooja_14

    Not sure how the process_packet function is implemented, try passing (uint8_t *)rx_buffer alone. Not sure why you've mentioned 10 there, if it's the total bytes of data packet, it should be 6. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • balajivan1995
    0 balajivan1995 9 months ago in reply to pooja_14

    If you are using multiple UART at same time, try to increase clock frequency. If process packet function takes much longer time to process the data and newer data comes in between, create an 2D array of 6 bytes with n rows, increase Row and set the new row to receive new data.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube