|
|
@@ -63,48 +63,52 @@ D15.
|
|
|
*/
|
|
|
static uint8_t construct_config_byte(ADC_Params *params) {
|
|
|
|
|
|
- uint8_t config = 0;
|
|
|
-
|
|
|
- config |= ((params->channel) << 5); // Channel Selection (Bits 6-5)
|
|
|
-
|
|
|
-
|
|
|
- config |= (1 << 4); // Continous mode
|
|
|
- //config |= (1 << 7); // One-Shot Mode: enable measurement (set read/not ready byte)
|
|
|
-
|
|
|
-
|
|
|
- switch (params->resolution) {
|
|
|
+ uint8_t config = 0;
|
|
|
|
|
|
- case 12:
|
|
|
- config |= (0b00 << 2);
|
|
|
- break;
|
|
|
- case 14:
|
|
|
- config |= (0b01 << 2);
|
|
|
- break;
|
|
|
- case 16:
|
|
|
- config |= (0b10 << 2);
|
|
|
- break;
|
|
|
- default:
|
|
|
- //printf("ERROR: Invalid Resolution!\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
-
|
|
|
- switch (params->gain) {
|
|
|
+ config |= ((params->channel) << 5); // Channel Selection (Bits 6-5)
|
|
|
|
|
|
- case 1:
|
|
|
- config |= (0b00);
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- config |= (0b01);
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- config |= (0b10);
|
|
|
- break;
|
|
|
- default:
|
|
|
- //printf("ERROR: Invalid Gain!\n");
|
|
|
- return 0;
|
|
|
- }
|
|
|
+ if (params->continuous == 1) {
|
|
|
+ config |= (1 << 4); // Continous mode
|
|
|
+ } else {
|
|
|
+ // One-Shot mode
|
|
|
+ // Bit set to zero, BUT the Ready bit needs to be set to start meausrement
|
|
|
+ // (read/not write bit)
|
|
|
+ config |= (1 << 7);
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (params->resolution) {
|
|
|
+
|
|
|
+ case 12:
|
|
|
+ config |= (0b00 << 2);
|
|
|
+ break;
|
|
|
+ case 14:
|
|
|
+ config |= (0b01 << 2);
|
|
|
+ break;
|
|
|
+ case 16:
|
|
|
+ config |= (0b10 << 2);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //printf("ERROR: Invalid Resolution!\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ switch (params->gain) {
|
|
|
+
|
|
|
+ case 1:
|
|
|
+ config |= (0b00);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ config |= (0b01);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ config |= (0b10);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //printf("ERROR: Invalid Gain!\n");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
|
|
|
- return config;
|
|
|
+ return config;
|
|
|
}
|
|
|
|
|
|
/* Tansmit Data from MCU to ADC: Function to SET configuration to ADC over
|