Skip to main content
18 events
when toggle format what by license comment
Oct 3, 2015 at 0:32 vote accept Jonathan
Oct 2, 2015 at 20:27 comment added Jonathan Oh I completely understand! ok ok. That makes more sense. Hence this piece of code in the library. And if i just had an arduino uno, the inv would read false, since most arduinos don't use inverse logic. So basically, my start bit is 0, since i'm anding it with inv_mask. // Write the start bit if (inv) *reg |= reg_mask; else *reg &= inv_mask; Thank you so much for your help.
Oct 2, 2015 at 20:16 comment added Majenko Nonono! There is NO VALUE 0x2B. That is an ADDRESS in memory. The value that is being sent is ONE of the bits within the CONTENTS of that address. You don't need to know what the contents are, since you are only ever manipulating ONE bit within it, and you never care what it was, only what you set it to. Forget that whole register and look at the rest of the program to determine what the bit is being set to and when. Forget the mechanics of how the bit is being set.
Oct 2, 2015 at 20:00 comment added Jonathan well i was told to figure out what exactly is the startbit. So all of this is just to figure out what startbit is being sent. So am i understanding this properly? the value 0x2b is being transmitted as the startbit?
Oct 2, 2015 at 19:52 comment added Majenko By looking at *reg or PORTD. Why do you need to "figure out" what is at that address anyway? You are just setting or clearing one bit in it. The rest shouldn't concern you
Oct 2, 2015 at 19:51 comment added Jonathan Hmm, so how do I figure out what is at value 0x2b?
Oct 2, 2015 at 19:34 comment added Majenko No, reg is 0x2b, *reg is whatever is at 0x2b.
Oct 2, 2015 at 19:33 comment added Jonathan Hey, O i see what you're saying. Ok, i just read up on what each register does in arduino. But here's the iffy part. *reg is 0x2b. That evaluates to 0b00101011. So ORing that with 0b00000010 just gives me back 0b00101011.
Oct 2, 2015 at 19:26 comment added Majenko It expands to *reg = *reg | reg_mask. If *reg contains, say 0b00101001 and reg_mask contains 0b00000010 then *reg ends up as 0b00101011 and the pin goes high. That register is more than just memory - it is actually the physical hardware of the IO pin. You're not just setting values, you're directly affecting real hardware. By setting a bit in the PORT register you are physically changing the voltage level on the pin from 0V to 5V.
Oct 2, 2015 at 19:25 comment added Jonathan Also, just be setting it in the register, how does it actually transmit it? In other words, when does it actually power the pin HIGH and LOW?
Oct 2, 2015 at 19:23 comment added Jonathan sorry, I'm not quite understanding how it sets one bit in the register because that OR statement evaluates to 0b00101011.
Oct 2, 2015 at 19:20 comment added Majenko That would OR the contents of reg_mask with the contents of the address pointed to by reg. It basically sets one bit in the register. &= inv_mask clears the same bit.
Oct 2, 2015 at 19:18 comment added Jonathan OOO! the value at 0x2b is being deferenced, and we're trying to find out the address of that value. which IS 0x2b. Thank you so much. Also, why would or *reg |= reg_mask send a one? If i'm using pin 1, then reg_mask equals 0b00000010. so 0b00101011 | 0b00000010 is what is being calculated. but how does that translate to a one being sent? there isn't even a digitalWrite in that block of code.
Oct 2, 2015 at 19:17 vote accept Jonathan
Oct 2, 2015 at 22:01
Oct 2, 2015 at 18:23 comment added Majenko 0x2B is the value that is being returned when & is used, since that is the address that the value is stored at. Don't sweat it, it took me years to get my head around pointers.
Oct 2, 2015 at 18:22 history edited Majenko CC BY-SA 3.0
added 407 characters in body
Oct 2, 2015 at 18:21 comment added Jonathan Oh my, i feel so amateurish. I am so sorry. I can't believe I completely neglected the fact that the & is adress of in this case. Ok, thank you so much! So I know up the value in 0x2B is being deferenced. But are you saying 0x2B is the value that is being returned? or is it something else still?
Oct 2, 2015 at 18:16 history answered Majenko CC BY-SA 3.0