1 Reply Latest reply on Jul 27, 2017 7:18 AM by e.pratt_1639216

    BLE array Bit Shifting

    senan.morris

      Hi,

         

      I am new to the forum so go please go easy on me. I am working on a BLE project which involves sending the 12 bit ADC readings of ten bend sensors out over a uint8[20] array. I am successfully receiving the adc readings on the receiver. But as the ADC readings are transmitted over a uint8 array, the LSB of each reading always arrives first in my receive array. What I want to is to switch the position of the LSB and MSB in the array and add them together so as i can transmit the results over a UART connection. I hope this makes sense and any help would be greatly appreciated.

        • 1. Re: BLE array Bit Shifting
          e.pratt_1639216

          Here is some code that should help you:

             

          uint8 arrayValues[20];
              uint8 i = 0;
              for (i = 0;i < 20; i = i + 2) {
                  uint8 temp = arrayValues[i]; //Save MSB to temp
                  arrayValues[i] = arrayValues[i + 1]; ///Write LSB to MSB location
                  arrayValues[i + 1] = temp; //Write saved MSB in temp to LSB location

             

          //Switched two bytes, on to the next 12-bit adc value
              }

             

          //After running, the code will have switched the LSB and MSB bytes of each ADC sample in the array