- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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