cancel
Showing results for 
Search instead for 
Did you mean: 

How to implement UART code for communication with Arduino in BLE mesh lighting application in STM32WB55RG ?

NDev.1
Associate III

Use case : when an on-off command is received on the node via BLE, the node should send some data to Arduino over USART1. Similarly, when some data is received on the node over USART1, it should publish the data to other boards or a phone.

If I port the UART interrupt code to the above application, the HAL_UART_Receive_IT() keeps giving HAL_BUSY error and no character is received from Arduino.

5 REPLIES 5

Well you can't keep issuing new HAL_UART_Receive_IT() requests when one is already pending.

You actually need to receive a character, from the UART's perspective, have the IRQ handler dispatch the callback, and then set a new request.

If the UART is not receiving anything, then you need to inspect the clocks, the pins, the Uart configuration and the external wiring.

I'd start by tracing the signal from the source into the UART's RX pin, use a scope, check the form of the signal and the bit rate. Check that the TX side of the UART outputs data in the equivalent manner.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
NDev.1
Associate III

Thank you @Community member​ for your prompt response. I apologize for the delay.

I think I am doing what you are saying. I am using the BLEMeshLightingPRFNode application in which I have ported the UART code in the following way :

In "app_mesh.c" file's Appli_Init(), I called HAL_UART_Receive_IT(&huart1_temp, &ch, 1); (I will refer it as a 'receive API' for the sake of simplicity.)

In the same file, I defined HAL_UART_RxCpltCallback() (callback function) and called the receive API again. But then compilation error occurred saying that the callback function is already defined in hw_uart.c. So I invoked the receive API in that file. But then no loop occurred or reception. I had to disable the friend feature for that. Now the callback is invoked continuously but it always returns an error HAL_BUSY.

-------------------Some clarifications----------------------

  1. What do you mean by " have the IRQ handler dispatch the callback" ? What do I have to do for that ?
  2. Actually, the stand-alone UART interrupt code is working and I am able to receive a particular character which is compared with the predefined character. If they match, then an LED turns on, which is working.
  3. How do I inspect the clocks ? In the CRO or do I have to check the ioc file ? This BLE mesh application does not have an ioc file.
  4. The pins I am using for uart are PB6 and PB7.
  5. Bit rate is 9600 both on arduino and in this application.
  6. TX side of the UART means from the other board (arduino), right ? It outputs a character properly.
  7. External wiring is also fine.
  8. UART configuration is same as that of the UART code except for one change. For initialization, In the "main.c" file, I have imported the MX_GPIO_Init() and MX_USART1_UART_Init() from the interrupt UART code. But I have not merged the systemClockConfig() function of the UART example to that of the BLE mesh application. Do you think that can be the problem ?

NDev.1
Associate III

Hi everyone ! I'd really appreciate if someone can guide me here..

It sounds like you are trying to do too many things all at once.

Take a step back, and start with the basics: just get a wired UART connection to a PC working.

Thank you @Andrew Neil​ for the suggestion. I will try that.