cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 c programming example

kumaresh
Associate II
Posted on June 25, 2015 at 07:58

dear all, i am bit confused in understanding the register handling of stm32 controller using c language. i am using keil compiler. i like to read, write register and set or clear single bit in the register. i want to write programs from scratch and dont want to use HAL library. i have to add just a header file like the one attached in the post and want to read and write register in bit and byte wise. 

please give examples for the same.

thanks in advance

#stm32 #c-programming
3 REPLIES 3
Posted on June 25, 2015 at 08:23

You could still review how the SPL and HAL are coded, it would provide you with plenty of examples.

The registers are described in the Reference Manual

The peripheral registers reside within the processors normal address space, and read/write in a similar manner to RAM

USART1

->

CR1

=

USART_CR1_UE

|

USART_CR1_TE

|

USART_CR1_RE

;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kumaresh
Associate II
Posted on June 25, 2015 at 09:37

thanks clive. if i want read adc data register to a variable how can i do it.

for ex

temp = ADC1->DR; is it right

and to clear a bit

USART1

->

CR1

=

!USART_CR1_UE; is right?

Posted on June 25, 2015 at 14:51

In C, bit-wise operations are done like this

USART1->CR1 &= ~USART_CR1_UE; // Clear Uart Enable

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