PDA

View Full Version : How to Correctly define Shiftout bits



BrianS
- 18th May 2011, 14:48
This works for me
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IODIRA,$00\24]

but from what I'm seeing in the manual it is not correct. Also from looking on this forum it is not correct from what I can tell.

This does not work for me
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE\8,IODIRA\8,$00\8]

This does not work correctly either
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IODIRA,$00]

I need to shift out 24 bits. What is the correct way to pass the number of bits sent?
Again Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IODIRA,$00\24] works but not sure why. The other ways do not.

Help is greatly appreciated.
Thanks,
Bryan

Bruce
- 18th May 2011, 16:03
This shifts out 2 bytes followed by 24-bits all zeros;
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IODIRA,$00\24]

This shifts out 3 bytes;
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE\8,IODIRA\8,$00\8]

This shifts out just 3 bytes;
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IODIRA,$00]

If you need 2 bytes WR_OPCODE_BYTE & IODIRA followed by 24-bits, then simply use the first version.

As in the manual, if you don't specify the number of bits, then 8-bits are shifted out. If WR_OPCODE_BYTE & IODIRA are byte variables with only 8-bits, then you don't need to tell it to shift out 8-bits per variable. It's automatic.

If either one was larger than 8-bits, then you would need to specificy this with the /#bits here option.

And - if you need 24 x 0 bits shifted out after the 1st two variables, then neither of your other routines are going to do that, so it doesn't work.

In your 1st version you're shifting out a total of 5 bytes. In your 2nd two just 3 bytes.

BrianS
- 19th May 2011, 11:38
I'm shifting out 24 bits. The device I writing to is a I/O portexpander MCP23S17 from microchip. I've tried the other methods and the portexpander does not respond to them. The only way to get it to recognize any commands, was to send them out like this.

WR_OPCODE_BYTE con $40
INTCONA con $04

Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IOCONA,$A0\24]

I don't know what the problem is with this. I know now it is incorrect but it works. The other ways do not.

There are two programs I wrote using the portexpander in PicBasic Pro. The first one only works as stated above. The other one works correctly if I use
Shiftout SDO,SCK,Msbfirst,[WR_OPCODE_BYTE,IOCONA,$A0]. Both use pretty much exactly the same code as it was copied and pasted from the first program into the second one. I can't put all the code on here as it was over 3000 lines of code.

Thanks,
Bryan

Bruce
- 19th May 2011, 13:09
Have you tried the example here? http://www.picbasic.co.uk/forum/showthread.php?t=13189&highlight=MCP23S17