5 Replies Latest reply on Oct 16, 2017 6:46 AM by user_300542545

    Bitshift operation in PSoC

    iamfantom

      Hi I'm trying to interface a HX711 weighing scale sensor with PSoC 4 BLE. The HX711is a 24-bit ADC for weighing scales that sends data one bit at a time in 24 clock cycles (datasheet attached).

         

      I used the following code in Arduino to obtain data.

         

      long Hx711::getValue()
      {
          byte data[3];

         

          while (digitalRead(_pin_dout))
              ;

         

          for (byte j = 0; j < 3; j++)
          {
              for (byte i = 0; i < 8; i++)
              {
                  digitalWrite(_pin_slk, HIGH);                //every HIGH pullup shifts one bit of data; hence _pin_slk needs to be pulled up 24 times
                  bitWrite(data[2 - j], 7 - i, digitalRead(_pin_dout));    //to read one bit at a time and store in data[]
                  digitalWrite(_pin_slk, LOW);
              }
          }

         

          digitalWrite(_pin_slk, HIGH);        //to pull the DOUT pin back to high to reach 25 pulses
          digitalWrite(_pin_slk, LOW);

         

          return ((long) data[2] << 16) | ((long) data[1] << 8) | (long) data[0];        //bitshift left operator used for shift the bits to the left
                                                  //bitwise OR operator to add the three bytes (24 bits) obtained
      }

         

      How do I implement the same in PSoC? Does PSoC support a bitshift operator (<<) like Arduino?

         

      Thanks,

         

      Ganesh