Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Binary numbers on Raspberry Pi
Forum Updated to NodeBB v4.3 + New Features

Binary numbers on Raspberry Pi

Scheduled Pinned Locked Moved Solved Mobile and Embedded
raspberry pi 2spibinarybinary formatconversion
11 Posts 4 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan90
    wrote on last edited by
    #1

    Hello together,

    I have been trying for some time now to get my Raspberry PI Project to run but I have not yet found a solution to the following problem:

    For the use of the WiringPI SPI Library I need to transmit data - over the SPI - in the format of unsigned chars bytewise. To adress the Register i only have hex or binary values. How can I convert binary or hex values to be unsigned chars so I have the correct type for the parameter to call the function ?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vish
      wrote on last edited by
      #2

      i guess, u have to develop protocol.. u can choose bigendien or littleendian and than if u have qint16 than cut 2 bytes and make uint16.

      Development is possible at any level.

      D 1 Reply Last reply
      0
      • V vish

        i guess, u have to develop protocol.. u can choose bigendien or littleendian and than if u have qint16 than cut 2 bytes and make uint16.

        D Offline
        D Offline
        Dan90
        wrote on last edited by
        #3

        @vish I'm sorry, I don't understand what you mean.

        V 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Can you show what you want to use from the WiringPI library ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          D 1 Reply Last reply
          0
          • D Dan90

            @vish I'm sorry, I don't understand what you mean.

            V Offline
            V Offline
            vish
            wrote on last edited by
            #5

            @Dan90 like this
            qFromBigEndian<uint16>((const uchar*) byteArray.data())
            this will give u uint16 type from ur bytearray buffer.

            Development is possible at any level.

            1 Reply Last reply
            0
            • SGaistS SGaist

              Hi,

              Can you show what you want to use from the WiringPI library ?

              D Offline
              D Offline
              Dan90
              wrote on last edited by
              #6

              @SGaist said:

              Hi,

              Can you show what you want to use from the WiringPI library ?

              Hi,

              i want to use the method

              int wiringPiSPIDataRW (int channel, unsigned char *data, int len)

              where I neet to pass an unsigned char pointer. When I try to set one up like this

              unsigned char *data = 0b10000000

              I get the warning that conversion from int to unsigned char is not possible.

              @vish said:

              @Dan90 like this
              qFromBigEndian<uint16>((const uchar*) byteArray.data())
              this will give u uint16 type from ur bytearray buffer.

              I understand that this funtion gets an unsigned char and converts it to uint16 ? But as I said, I need an unsigned char in the first place.

              jsulmJ 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Then you can use a QByteArray to build your data and then use its data function to access them. You can cast data to unsigned char *

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                D 1 Reply Last reply
                0
                • SGaistS SGaist

                  Then you can use a QByteArray to build your data and then use its data function to access them. You can cast data to unsigned char *

                  D Offline
                  D Offline
                  Dan90
                  wrote on last edited by Dan90
                  #8

                  Thanks for the hint with QByteArray. I checked it and the problem I still have ist that the data function of my QByteArray object returns a char*, but the wiringPiSPIDataRW function needs an unsigned char*, so I still get an error out of this.

                  EDIT:
                  I just tried an explicit type conversion and it worked. Could this have a negative effect on my data by any means ?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Do a type cast: wiringPiSPIDataRW (static_cast<unsigned char *>(myByteArray.data()), myBateArry.size());

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dan90
                      wrote on last edited by
                      #10

                      Thanks a lot for the input. It gave no error messages while compiling, however it did not work. I switched to another Library (BCM2835) and i got it to work in just a few Minutes. This library is much better documented than wiringPI SPI.

                      Thanks again.

                      1 Reply Last reply
                      0
                      • D Dan90

                        @SGaist said:

                        Hi,

                        Can you show what you want to use from the WiringPI library ?

                        Hi,

                        i want to use the method

                        int wiringPiSPIDataRW (int channel, unsigned char *data, int len)

                        where I neet to pass an unsigned char pointer. When I try to set one up like this

                        unsigned char *data = 0b10000000

                        I get the warning that conversion from int to unsigned char is not possible.

                        @vish said:

                        @Dan90 like this
                        qFromBigEndian<uint16>((const uchar*) byteArray.data())
                        this will give u uint16 type from ur bytearray buffer.

                        I understand that this funtion gets an unsigned char and converts it to uint16 ? But as I said, I need an unsigned char in the first place.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @Dan90 You are assigning a value to a pointer, but data is actually an array of "unsigned char":

                        unsigned char *data = 0b10000000;
                        

                        Instead you should do (C++11):

                        unsigned char data[] = { (unsigned char)0b10000000 };
                        

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved