I have an o'scope on the fiber transmitter and say I want the fiber signal to look like this (in ones and zeros, the fiber signal is actually two different widths to represent 1 or 0):
000000000000000101010000 - that is 24 bits, the last eight to the right are OK because they are the 8 from the MCP23S17 that is just static setup data and I can handle those... and they are on the proper side of the string and in the proper order. so no problem with those. BUT....
The first 16 bits are: 0000000000000001 - Decimal "1"
Well, if I use my code to send those 16 bits - the fiber output ends up looking more like this: 100000000000000001010000 - The first 16 bits are opposite of what I need! They equal decimal "32768"
Far from the "1" I was expecting!
It's actually worse than that, because the MCP23S17 is not acting like a 16 bit device, but rather as two 8 bit devices... hence the splitting of "Voltage" into two bytes. But I think I just need to configure the MCP23S17 correctly for 16 bit mode, as soon as I wrap my brain around its datasheet.
But I still need to know how to send just the 16 bit WORD "Voltage" in my code LSB first, without having to do crazy math every time I work with the variable in my MAIN loop
I tried the operator "REV" and it doesn't seem to work as expected.
I think the MCP23S17 must have it's data fed to it MSB first, but my variable has to go LSB first!
I wonder if I could just get away with this?
:
Code:
nCSA = 0 'Enable MCP23S17-A
SHIFTOUT SDO, SCLK, 1, [MCP23A,OLATA] ' i.e. SHIFTOUT SDO, SCLK, MSB,[MCP23A,OLATA]
SHIFTOUT SDO, SCLK, 0, [VoltageFst] ' i.e. SHIFTOUT SDO, SCLK, LSB,[VoltageFst]
nCSA = 1 'Disable the MCP23S17
pause 1
nCSA = 0 'Enable MCP23S17-A
SHIFTOUT SDO, SCLK, 1, [MCP23A,OLATB] ' i.e. SHIFTOUT SDO, SCLK, MSB,[MCP23A,OLATB]
SHIFTOUT SDO, SCLK, 0, [VoltageSec] ' i.e. SHIFTOUT SDO, SCLK, LSB,[VoltageSec]
nCSA = 1 'Disable the MCP23S17
RETURN
Bookmarks