After blinking the LEDs. I started with the chapter register and on the first page itself I got some issues. I read about most of them and find out that the address is const and to use that fixed value we used raw pointer GPIOE_BSRR as *mut u32
which is making a copy of the address(referencing) variable and allowing us to change.
#353
-
After blinking the LEDs. I started with the chapter register and on the first page itself I got some issues. I read about most of them and find out that the address is const and to use that fixed value we used raw pointer I hope till here i am getting it right now the next issue is what we are doing at right-hand side using the shift operator. We are using 9 11 to set and 16, 25 to reset but why 1 in every shift? `#![no_main] #[allow(unused_imports)] #[entry] {
} Originally posted by @NitinSaxenait in #193 (comment) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It's a convenient way to express the full binary number we want to write to the register. The way the BSRR register works is you write a '1' to any of the 'set' fields (each 1 bit wide, bits 0-15) to turn on that GPIO, and write a '1' to any of the 'reset' fields (bits 16-31) to turn it off. So, to turn on pin 2, you write a 1 to bit 2, which means writing Sometimes a field is longer, for example it might be 4 bits starting at bit 5, and we want to write Hope that helps answer your question! |
Beta Was this translation helpful? Give feedback.
It's a convenient way to express the full binary number we want to write to the register. The way the BSRR register works is you write a '1' to any of the 'set' fields (each 1 bit wide, bits 0-15) to turn on that GPIO, and write a '1' to any of the 'reset' fields (bits 16-31) to turn it off.
So, to turn on pin 2, you write a 1 to bit 2, which means writing
0b0000_0000_0000_0000_0000_0000_0000_0100
to the register. Instead of typing out the long number, we can write1 << 2
, which is the same number but easier to understand. We're shifting a 1 to the left by 2 places. Because all the fields can only take a '1', we never need any other number. To turn it off we'd …