BLE array Bit Shifting

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

cross mob
SeMo_1393826
Level 1
Level 1
Welcome! First question asked

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.

0 Likes
1 Solution
Anonymous
Not applicable

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; //Save MSB to temp
        arrayValues = 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

View solution in original post

0 Likes
1 Reply
Anonymous
Not applicable

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; //Save MSB to temp
        arrayValues = 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

0 Likes