setting an pin to output understanding
DXC
Posts: 33
Hello all,
I did some programming in ASM with the Propeller now some time.
The question I have is when setting an pin to output I also have to set the rest of the pins.
eg,
cog 1 uses 3pins as outputs, pin 1 ,2 and 3. (spin basic language)
cog 2 uses 2pins as outputs, pin 28 and 29. (assembly )
dira has to be set to 110000 00000000 00000000 00000000 binair
but doing so will I not set pins 1,2 and 3 as inputs?
Or do I have to set dira to 110000 00000000 00000000 00000111?
gr,
Bart
I did some programming in ASM with the Propeller now some time.
The question I have is when setting an pin to output I also have to set the rest of the pins.
eg,
cog 1 uses 3pins as outputs, pin 1 ,2 and 3. (spin basic language)
cog 2 uses 2pins as outputs, pin 28 and 29. (assembly )
dira has to be set to 110000 00000000 00000000 00000000 binair
but doing so will I not set pins 1,2 and 3 as inputs?
Or do I have to set dira to 110000 00000000 00000000 00000111?
gr,
Bart
Comments
Usually the pin numbers range from 0 to 31 and not from 1 to 32. The reason can be found in the binary nature of microcontrollers. The least significant bit is also called bit 0. If you have a look at one byte, the least significant bit has a value of 2 to the power of 0 = 1, whereas the most significant bit has a value of 2 to the power of 7 = 128.
So, in your description either cog 1 or the binary mask you show on the end is wrong:
110000 00000000 00000000 00000111
| these are bits 28 and 29 | these are bits 0-2
Now to the DIRA thing ... each COG has it's own copy of DIRA. You should only set the pins to output which are used by the COG, all other pins should stay as input.
So, in the SPIN COG you say
DIRA := %111
and in the PASM COG you say
mov dira, pin_mask
...
pin_mask long %110000 00000000 00000000 00000000
thnx for the explanation.
Allways worked with it but never thought of how it would work in the propeller.
I also ment 0..2 yes, my fault.
gr,
Bart