cancel
Showing results for 
Search instead for 
Did you mean: 

Mixing HAL and Direct Register Manipulation

minion_SLAYER
Associate II

Hello. I am writing a code to read ADC data from an AC voltage sensor. I used HAL to initialize ADC 1 and USART2 for checking the values in Putty. However, I would like to use direct register manipulation to send data to USART6 so that it can transmit the data to a wifi module which sends the data to a website for monitoring. However, I am not getting correct values in USART6 (confirmed by using serial monitor in IDE which I am using to check data received by the wifi module which is ESP32 to be specific). The output is gibberish as opposed to the data obtained from USART2. Is it possible that there's clashing between the initialization of USART2 in HAL and USART6 in bare metal?

If I try using bare metal for USART2 and USART6, would there be any difference? I have read from another question here that you cannot mix HAL and bare metal code when accessing the same peripheral, but I wonder if that applies for the GPIO peripherals I'd be using as well (ADC GPIOs in HAL and USART GPIOs in bare metal)

11 REPLIES 11

At the end of the day, the working of resulting application still is your responsibility, whether you don't understand your own clock config or you don't understand the one achieved by clicking in CubeMX.

JW

 

minion_SLAYER
Associate II

I understand. Thank you! I'm relatively new to HAL and since I did not change anything with the CubeMX clock settings, I assumed that the system clock would be 16MHz by default. Now, I know better than to ignore the clock settings that are automatically set.

 

The initial question was still that at first I was doubtful if I can make HAL and bare metal programming work together because I have only worked with the latter so far and have little to no experience with the abstraction layer. I know I would have been able to figure out the clock part later on on my own, but the help regarding which parts would cause conflicts (i.e. code snippets I can comment out) helped me a lot.

 

Thanks everyone.