Notifications
Clear all

Shift Register

19 Posts
3 Users
6 Reactions
194 Views
(@davee)
Member
Joined: 3 years ago
Posts: 1778
 

Hi @fordav1,

   Thanks for your kind reply.

  The code that makes up the function 'readByte()' that I included, is a 'rearrangement' of the code that makes up the function 'inShift()', that Bill (@dronebot-workshop) used in his sketch, and effectively has the same functionality.

However, inShift() is part of the Arduino library, whilst I explicitly included the coding for readByte(). The Arduino library must also define values for MSBFIRST and LSBFIRST, because they are not defined in 'standard' C or C++. I did not feel comfortable on relying on value definitions that might be changed in the future, albeit the chance of that happening is probably minuscule.

Hence, I converted the function parameter that determines whether the first bit fetched from the shift register was the Least Significant or Most Significant into a kind of question. The code definition for my 'readByte()' function starts:

uint8_t readByte (uint8_t dataPin, uint8_t clockPin, bool isLSBFirst)

The 3rd parameter "bool isLSBFirst", is intended to suggest the implied question, "Is the Least Significant Bit, the first bit fetched from the shift register?", with the argument required to be of the C++ type bool (boolean), which is defined as either true or false

------

All of which, is a long way of saying, try changing true to false in line 156 of my code, which presently looks like:

byte incoming = readByte(dataIn, clockIn, true);

to

byte incoming = readByte(dataIn, clockIn, false);

-------------

I hope that works.

Best wishes with your project, Dave


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7358
 

@fordav1 I might be missing something, but just swap the wires on the dip sw so that 1 becomes 128 etc.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1778
 

Hi Ron @zander

You are correct, that swapping the wires will do the same job, although that will take longer than replacing true with false in the sketch file.

My explanation is much longer than the one line answer I could have given, because I was also trying to help @fordavi to understand the software, etc., which might be helpful as he builds the test rig into his larger project.

Best wishes, Dave


   
Ron reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7358
 

@davee I didn't look at the sketch, all I heard was the results were backwards so I toook the direct pragmatic route.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
DaveE reacted
ReplyQuote
Page 2 / 2