2 Replies Latest reply on Mar 23, 2015 10:08 PM by LeonY

    shiftOut not available for Galileo

    Pb1

      Neither are shiftIn(). They are declared in AdvancedIO.h, however. When are these function going to be implemented?

        • 1. Re: shiftOut not available for Galileo
          JPMontero_Intel

          Hi Pb1

          I don’t know when or if this function is going to be implemented, but maybe you can create your own function to replace the Arduino one. Take a look at this link http://arduino.cc/en/Tutorial/ShiftOut#.U1BKD_ldVHU in there is a tutorial of how does the shift out function works and a couple of examples and just in case http://playground.arduino.cc/Code/Function this a tutorial about how to write functions. I hope this works for you.
          Regards
            JPMontero_Intel.

          • 2. Re: shiftOut not available for Galileo
            LeonY

            Here is my implementation of shiftOut() I thought i would add some more info...

            WHY: Im using this to drive a WS2803 LED driver

            How: It uses Galileos special OUTPUT_FAST modes for pins 3 and 2

             

            Prerequesites:

            in SETUP you must declare pins 2 and 3 for OUTPUT_FAST:

             

            pinMode(2, OUTPUT_FAST);

            pinMode(3, OUTPUT_FAST);

             

            Note this shiftOut() uses the super fast fastGpioDigitalWriteDestructive() function, its flaky and unreliable

             

            void shiftOut(byte data, byte inDataPin, byte inClockPin, bool mSigBit)

            {

              byte mask=1, bitResult=0;

              short int cnt=0;

             

              if(mSigBit)

              {

                 //Set the mask to '10000000'

                 mask = mask << 7;

                 for(cnt=0; cnt<8; cnt++)

                 {

                   //AND the mask and the data value

                   bitResult = data & mask;

                   //Shift the result by the CNT to get 1 or 0

                   bitResult = bitResult >> (7-cnt);

                   //output result to data pin

                   //fastGpioDigitalWrite(GPIO_FAST_IO3, bitResult);

                   //digitalWrite(inDataPin, bitResult);

                   if(bitResult)

                   {

                     fastGpioDigitalWriteDestructive(129);

                   }

                   else

                   {

                     fastGpioDigitalWriteDestructive(0);

                   }

                   //set clock high

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, HIGH);

                   //digitalWrite(inClockPin, HIGH);

                   fastGpioDigitalWriteDestructive(returnLatch(bitResult, 1));

                   //set clock low

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, LOW);

                   //digitalWrite(inClockPin, LOW);

                   fastGpioDigitalWriteDestructive(returnLatch(bitResult, 0));

                   //Shift the bit of the mask RIGHT

                   mask = mask >> 1;

                 }

               }

               else

               {

                 for(cnt=7; cnt>=0; cnt--)

                 {

                   //The mask is preset to '00000001'

                   //AND the mask and the data value

                   bitResult = data & mask;

                   //Shift the result by the CNT to get 1 or 0

                   bitResult = bitResult >> (7-cnt);

                   //output result to data pin

                   //fastGpioDigitalWrite(GPIO_FAST_IO3, bitResult);

                   //digitalWrite(inDataPin, bitResult);

                   if(bitResult)

                   {

                     fastGpioDigitalWriteDestructive(129);

                   }

                   else

                   {

                     fastGpioDigitalWriteDestructive(0);

                   }

                   //set clock high

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, HIGH);

                   //digitalWrite(inClockPin, HIGH);

                   fastGpioDigitalWriteDestructive(returnLatch(bitResult, 1));

                   //set clock low

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, LOW);

                   //digitalWrite(inClockPin, LOW);

                   fastGpioDigitalWriteDestructive(returnLatch(bitResult, 0));

                   //Shift the bit of the mask left

                   mask = mask << 1;

                 }

               }

            }

            //suport function

            byte returnLatch(byte dataPinValue, byte wantedValue)

            {

              if(dataPinValue==0 && wantedValue==1)

              {

                 return 65;

              }

              else if(dataPinValue==0 && wantedValue==0)

              {

                  return 0;

              }

              else if(dataPinValue==1 && wantedValue==1)

              {

                  return 255;

              }

              else if(dataPinValue==1 && wantedValue==0)

              {

                  return 129;

              } 

            }

             

            This version uses the next slowest write method, its more reliable

            void shiftOutSlow(byte data, byte inDataPin, byte inClockPin, bool mSigBit)

            {

              //dataPin must be GPIO_FAST_IO3

              //clockPin must be GPIO_FAST_IO2

              byte mask=1, bitResult=0;

              short int cnt=0;

             

              if(mSigBit)

              {

                 //Set the mask to '10000000'

                 mask = mask << 7;

                 for(cnt=0; cnt<8; cnt++)

                 {

                   //AND the mask and the data value

                   bitResult = data & mask;

                   //Shift the result by the CNT to get 1 or 0

                   bitResult = bitResult >> (7-cnt);

                   //output result to data pin

                   //fastGpioDigitalWrite(GPIO_FAST_IO3, bitResult);

                   digitalWrite(inDataPin, bitResult);

                   //set clock high

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, HIGH);

                   digitalWrite(inClockPin, HIGH);

                   //set clock low

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, LOW);

                   digitalWrite(inClockPin, LOW);

                   //Shift the bit of the mask RIGHT

                   mask = mask >> 1;

                 }

               }

               else

               {

                 for(cnt=7; cnt>=0; cnt--)

                 {

                   //The mask is preset to '00000001'

                   //AND the mask and the data value

                   bitResult = data & mask;

                   //Shift the result by the CNT to get 1 or 0

                   bitResult = bitResult >> (7-cnt);

                   //output result to data pin

                   //fastGpioDigitalWrite(GPIO_FAST_IO3, bitResult);

                   digitalWrite(inDataPin, bitResult);

                   //set clock high

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, HIGH);

                   digitalWrite(inClockPin, HIGH);

                   //set clock low

                   //fastGpioDigitalWrite(GPIO_FAST_IO2, LOW);

                   digitalWrite(inClockPin, LOW);

                   //Shift the bit of the mask left

                   mask = mask << 1;

                 }

               }

            }

            1 of 1 people found this helpful