Unsolved How to use bit operations
-
Hi @k-str,
now it get's interesting - low level programming :)
Computer : Raspberry zero
Radtio receiver : RX868SH-DVStill unclear for me how your receive the data in the PI. Is the receiver connected to and toggles a GPIO pin? How do you sample the data?
The transmitter sends 11 bytes of data as follows.
That's good. So you will need 11 bytes to store the complete data. Plus a bit of handling to detect the start of the frame etc.
Then the fun begins:
#include <array> #include <iostream> using namespace std; int main() { std::array<uint8_t, 11> data; // add sample data data[0] = 0x12; data[1] = 0x30; data[2] = 0x26; // calculate vendor and temperature as example const uint16_t vendor = (data[0] << 4) | (data[1] >> 4); const uint16_t temperature = ((data[1] & 0x0F) << 8) | data[2]; cout << hex << "vendor: " << vendor << endl; cout << dec << "temperature: " << temperature << endl; return 0; } // Output: vendor: 123 temperature: 38
The other data can be used in similar ways. If both nibbles are in the same byte, you can just use it. If they are distributed over several bytes, you need to extract the nibbles and shift. BCD just means, that each nibble encodes a decimal digit of 0..9.
I hope that helps you.
Regards
[Edit: fixed typo in temperature shift]
-
@aha_1980
Thanks for your answer:
yes it is connected to GPIO,
The DATA is connectet to pin 13 (GPIO02) as input
The EN = RX Enable is connected to pin 15 (GPIO03) as output set to on
Kurt -
@k-str said in How to use bit operations:
The DATA is connectet to pin 13 (GPIO02) as input
And where do you get clock from? Or how do you know when a bit starts and ends?
-
@aha_1980
There is a description only in german. But I try to explain :
When you set the EN to ON then the input on the DATA pin rises when a new bit is received.
the sequence is as follows :- Set EN to ON
- wait until the DATA goes ON
- read from DATA
- set DATA to OFF
- repeat from 2.
Kurt
-
-
@aha_1980 said in How to use bit operations:
Or how do you know when a bit starts and ends?
Priceless :)
-
@jonb Usually a bit starts when 3 or 5 V are on the bin right 😉
-
@aha_1980 :
yes here some descriptions in german:
Descripton in german
Its a programm for reading RX868SH.DV and WH1080 weather station as well a description ( see link Datenprotokolle on the end)
and here the link to the R868SH-DV module
@JonB @J-Hilk :
I will check it!
Kurt -
Ok, thanks.
As I expected, this is really implemented by polling a GPIO pin. And it leads to a CPU load of 14% on Raspberry Pi when using 200µs polling interval :-O
Regards
-
@aha_1980
Thank you for this tip.
This means I have to implement a timer with a interval of 200µs which kicks off reading of one new bit from the RX868SH-DV.
OK I will try it. And then I give you an answer.
But now I got a new problem using timers in QT-Creator. I make a new topic for this.
my new topic for two timer