Author Topic: stm32 how to read register bits in keil  (Read 2008 times)

0 Members and 1 Guest are viewing this topic.

Offline tariqTopic starter

  • Contributor
  • Posts: 24
  • Country: ir
stm32 how to read register bits in keil
« on: May 09, 2021, 02:39:48 pm »
hi
for example in register NVIC->ICER i want to read bit number 7 in software .
i see it in my debug session but i want my software check it so i looking for a way to read the bit
this register is 32 bit so i defined a 32 bit variable with this command
uint32_t check_register;
and then
check_register=NVIC->ICER;
so i can shift the bit in check_register and check bit number 1
but this :
check_register=NVIC->ICER;
doesn't work.
how can i read register?what is the best way to read register bits?
thank you.
 

Offline DavidAlfa

  • Super Contributor
  • ***
  • Posts: 5890
  • Country: es
Re: stm32 how to read register bits in keil
« Reply #1 on: May 09, 2021, 04:30:12 pm »
How does it fail? Reads nothing? Drops some error?
You might want to apply a mask:
check_register = NVIC->ICER & (1<<7);

What mcu? In Cortex M0 it's just a single ICER register, but in others it's an array:
https://www.keil.com/pack/doc/CMSIS/Core/html/regMap_pg.html
Hantek DSO2x1x            Drive        FAQ          DON'T BUY HANTEK! (Aka HALF-MADE)
Stm32 Soldering FW      Forum      Github      Donate
 
The following users thanked this post: tariq

Offline tariqTopic starter

  • Contributor
  • Posts: 24
  • Country: ir
Re: stm32 how to read register bits in keil
« Reply #2 on: May 09, 2021, 04:46:00 pm »
it's stm32f101vbt6 which is Cortex M3.
this command
check_register = NVIC->ICER & (1<<7);
has error. i uploaded the error picture.
all i want is to check the Intended bit in if() command.what is the best way to do it?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11234
  • Country: us
    • Personal site
Re: stm32 how to read register bits in keil
« Reply #3 on: May 09, 2021, 05:10:37 pm »
ICER is an array, there are multiple ICER registers. If you want to check the 7th bit, then it will be located in the first register :

check_register = NVIC->ICER[0] & (1<<7);
Alex
 
The following users thanked this post: tariq

Offline gamalot

  • Super Contributor
  • ***
  • Posts: 1303
  • Country: au
  • Correct my English
    • Youtube
Re: stm32 how to read register bits in keil
« Reply #4 on: May 09, 2021, 05:14:31 pm »
it's stm32f101vbt6 which is Cortex M3.
this command
check_register = NVIC->ICER & (1<<7);
has error. i uploaded the error picture.
all i want is to check the Intended bit in if() command.what is the best way to do it?

The structure member ICER is an array of volatile uint32_t (array length is 1), so the correct syntax should be:

check_register = NVIC->ICER[0] & (1<<7);
 
The following users thanked this post: tariq


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf