0
\$\begingroup\$

I'm using an STM32F103C8T6 (aka blue pill) with Eclipse/System Workbench and HAL.

The following code:

 volatile HAL_StatusTypeDef result =
  HAL_UART_Transmit(&huart1, bytesToSend + currentSendIndex, 
  bytesPerMessageToSend, 100);

 volatile uint32_t error = HAL_UART_GetError(&huart1);

works fine when sending 1 byte, and (later) receiving 1 byte and iterating this.

However, when sending 3 bytes, I noticed, I only receive the first byte, and the next calls for HAL_UART_Receive result in a timeout.

This seems logical, because probably there is only 1 byte buffer in the UART.

However, what I don't understand, why does transmitting multiple bytes in the code mentioned, returns HAL_OK, and also the call to HAL_UART_GetError returns 0.

I assume an overrun has occurred for the 2nd and consecutive bytes... is this true, and if yes, how can I check this?

\$\endgroup\$
12
  • 1
    \$\begingroup\$ Aren't you using TXempty for IRQ? What data rate? \$\endgroup\$ Sep 3, 2017 at 22:06
  • 1
    \$\begingroup\$ Using a timer is possible to fill 8 byte data buffer but IRQ is better. Before STM32 which have many std UARTS, I would use IRQ with DMA to send bursts of data, so CPU could run processes, and do housekeeping and delgate the DMA. Make sure you use parity, and check for all errors, NE ORE or FE and test signal integrity for glitches. \$\endgroup\$ Sep 4, 2017 at 12:20
  • 1
    \$\begingroup\$ For MIDI , I once just used the Joystick port to communicate over MIDI on WIN98 \$\endgroup\$ Sep 4, 2017 at 13:24
  • 1
    \$\begingroup\$ @Michel Keijzers if you want to learn microcontrollers forget HAL and use bare registers. \$\endgroup\$ Sep 4, 2017 at 15:46
  • 1
    \$\begingroup\$ I bet that learning those ridiciolous HAL structures will be much more complicated and will take longer (now you have problem with very simple peripheral) , than learning the hardware itself. I cant help you as I know how the hardware works, but I have no clues what HAL does). I use some HAL libraries (strongly modified by me) especially for USB & Ethernet. \$\endgroup\$ Sep 4, 2017 at 17:05

2 Answers 2

1
\$\begingroup\$

You can configure an interrupt to detect overrun errors. Actually a lot of interrupt are available to detect errors. From the reference manual:

enter image description here

Just for sure you could use the "Transmit data register empty" one as Tony has suggested.

As far as I know HAL IRQ handlers and IRQ calls for UART use all of these interrupts by default. The _IT versions of the UART calls enable all these interrupts.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks ... I already knew interrupts would be better, but since I'm quite a newbie I thought it would be easier to start with the non-interrupt solution... But I guess I already found it's limitation. I will check interrupts, and yes, the HAL supports interrupts for UART. \$\endgroup\$ Sep 4, 2017 at 7:53
1
\$\begingroup\$

Your solution may end up duplicating existing products.

http://www.ucapps.de/mbhp_core_lpc17.html

\$\endgroup\$
5
  • \$\begingroup\$ I know such things exist, but first, I want to learn more about microcontrollers, but also I want eventually (at least) 4 inputs, 4 outputs and 4 thrus. Probably I could stack 4 of those. \$\endgroup\$ Sep 4, 2017 at 14:22
  • \$\begingroup\$ Before you can design, you must know how everything works and fails, and learning curve depends on user. So start with something that works. \$\endgroup\$ Sep 4, 2017 at 14:28
  • \$\begingroup\$ Well I tried already a 'proof of concept' with 3 MIDI in/out/thrus on an Arduino and worked fine... but I need more memory, and possibly more processing power, so I am converting my proof of concept to STM32 ... \$\endgroup\$ Sep 4, 2017 at 14:31
  • \$\begingroup\$ then you must use DMA for thruput in order to have useful functions. \$\endgroup\$ Sep 4, 2017 at 14:35
  • \$\begingroup\$ Yes, but since I'm new I thought I start simple with polling, but that doesn't seem to work out well, so I will do IRQ/interrupts, and next step is using DMA. \$\endgroup\$ Sep 4, 2017 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.