Bitshift operation in PSoC

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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] << 😎 | (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

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This is not a question of the board or processor, it is a question of the programming language used.

   

PSoC Creator uses C-language while with Arduino you may use C++.

   

Of course the hardware is quite different: Creator uses "components" whose properties you configure at design time (as pin drive mode etc) and at runtime you control them with the appropriate APIs.

   

The  difference between PSoCs and other embedded is: PSoCs contain real configurable hardware that can be routed chip internally to fit your needs. Just as building up a pcb you connect the required signals. Have a look at the video demos

   

 

   

Bob

View solution in original post

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This is not a question of the board or processor, it is a question of the programming language used.

   

PSoC Creator uses C-language while with Arduino you may use C++.

   

Of course the hardware is quite different: Creator uses "components" whose properties you configure at design time (as pin drive mode etc) and at runtime you control them with the appropriate APIs.

   

The  difference between PSoCs and other embedded is: PSoCs contain real configurable hardware that can be routed chip internally to fit your needs. Just as building up a pcb you connect the required signals. Have a look at the video demos

   

 

   

Bob

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

tl;dr: yes

   

(as Bob said, the shioft operators are not a question of the hardware, but for the programming language. And C supports them).

   

You can do manual bit-banging as with the Arduino, by using direct pin access (look in the system reference for that). Or you use a SPI master to read the data, which will do most of the work in hardware.

Anonymous
Not applicable

Thanks for the reply. I figured out that it was a case of the programming language only after I posted the question. I was able to write the code on PSoC Creator.

   

Ganesh

0 Likes
Anonymous
Not applicable

Can you provide me some details for this project ?

   

Library HX711? 

   

thank you 

0 Likes
Anonymous
Not applicable

I am also working on HX711, Can i Get ur Help???

0 Likes