PSoC-FDC1004Q
PSoC FDC1004Q Library
FDC1004Q.c
1 
5 #include "FDC1004Q.h"
6 #include "I2C_Interface.h"
7 
11 #define FDC1004Q_I2C_ADDR 0x50
12 
16 #define FDC1004Q_MANUFACTURED_ID_VALUE 0x5449
17 
21 #define FDC1004Q_DEVICE_ID_VALUE 0x1004
22 
23 // =============================================
24 // FDC REGISTER BITS
25 // =============================================
26 
30 #define FDC_FDC_CONF_RESET_BIT 15
31 
35 #define FIXED_POINT_FRACTIONAL_BITS_OFFSET 11
36 
40 #define FIXED_POINT_FRACTIONAL_BITS_GAIN 14
41 
42 // Converts unsigned fixed point format to double
43 static float fixed_to_float_unsigned(uint16_t input, uint8_t fract_bits);
44 
45 // Converts double to unsigned fixed point format
46 static int16_t float_to_fixed_unsigned(float input, uint8_t fract_bits);
47 
48 // Converts signed fixed point format to double
49 static float fixed_to_float_signed(int16_t input, uint8_t fract_bits);
50 
51 // Converts double to signed fixed point format
52 static int16_t float_to_fixed_signed(float input, uint8_t fract_bits);
53 
54 // ===========================================================
55 // INITIALIZATION FUNCTIONS
56 // ===========================================================
57 
58 uint8_t FDC_Start(void)
59 {
62  {
63  return FDC_Reset();
64  }
65  return FDC_DEV_NOT_FOUND;
66 }
67 
68 void FDC_Stop(void)
69 {
71 }
72 // Check if device is connected
73 uint8_t FDC_IsDeviceConnected(void)
74 {
75  uint8_t error = FDC_DEV_NOT_FOUND;
76  uint16_t id = 0x00;
77  if (FDC_ReadManufacturerId(&id) == FDC_OK)
78  {
79  if ( id == FDC1004Q_MANUFACTURED_ID_VALUE)
80  {
81  if (FDC_ReadDeviceId(&id) == FDC_OK)
82  {
83  if ( id == FDC1004Q_DEVICE_ID_VALUE)
84  {
85  error = FDC_OK;
86  }
87  }
88  }
89  }
90 
91  return error;
92 }
93 
94 // Reset the sensor
95 uint8_t FDC_Reset(void)
96 {
97  // Read FDC register, set RESET bit, write FDC register
98  uint8_t temp[2];
99  uint16_t register_value = 0;
100  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
101  if (error == FDC_OK)
102  {
103  temp[0] |= 1 << (FDC_FDC_CONF_RESET_BIT-8);
104  error = FDC_WriteRegister(FDC1004Q_FDC_CONF, temp);
105  // Wait for reset to be completed
106  uint8_t flag = 1;
107  do
108  {
109  error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
110  if ( error != FDC_OK)
111  {
112  break;
113  }
114  uint16_t register_value = temp[0] << 8 | temp[1];
115  flag = (register_value & 0x8000) > 0 ? 1 : 0;
116  } while (flag == 1);
117  }
118  return error;
119 }
120 
121 // ===========================================================
122 // CONFIGURATION FUNCTIONS
123 // ===========================================================
124 
125 uint8_t FDC_SetSampleRate(uint8_t sampleRate)
126 {
127  if (sampleRate > FDC_400_Hz)
128  return FDC_CONF_ERR;
129  // Read FDC register, set RATE bits, write FDC register
130  uint8_t temp[2];
131  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
132  if (error == FDC_OK)
133  {
134  // Clear bits [11:10]
135  temp[0] &= ~0x0C;
136  temp[0] |= (sampleRate << 2);
137  error = FDC_WriteRegister(FDC1004Q_FDC_CONF, temp);
138 
139  }
140  return error;
141 }
142 
143 // Read sample rate
144 uint8_t FDC_ReadSampleRate(uint8_t* sampleRate)
145 {
146  uint8_t temp[2];
147  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
148  if (error == I2C_NO_ERROR)
149  {
150  *sampleRate = (temp[0] & 0x0C) >> 2;
151  }
152  return error;
153 }
154 
155 // Set offset calibration in float format
156 uint8_t FDC_SetOffsetCalibration(uint8_t channel, float offset)
157 {
158  if (channel > FDC_CH_4)
159  {
160  return FDC_CONF_ERR;
161  }
162  if ( (offset < -16) || (offset > 16))
163  {
164  return FDC_CONF_ERR;
165  }
166  uint16_t offset_raw = float_to_fixed_signed(offset, FIXED_POINT_FRACTIONAL_BITS_OFFSET);
167  uint8_t temp[2] = {offset_raw >> 8, offset_raw & 0xFF};
168  return FDC_WriteRegister(FDC1004Q_OFFSET_CAL_CIN1 + channel, temp);
169 }
170 
171 // Set offset calibration in raw format
172 uint8_t FDC_SetRawOffsetCalibration(uint8_t channel, int16_t offset)
173 {
174  if (channel > FDC_CH_4)
175  return FDC_CONF_ERR;
176  float offset_f = fixed_to_float_signed(offset, FIXED_POINT_FRACTIONAL_BITS_OFFSET);
177  if ( (offset_f < 0) || (offset_f > 16))
178  return FDC_CONF_ERR;
179  uint8_t temp[2] = {offset >> 8, offset & 0xFF};
180  return FDC_WriteRegister(FDC1004Q_OFFSET_CAL_CIN1 + channel, temp);
181 }
182 
183 // Read offset calibration in float format
184 uint8_t FDC_ReadOffsetCalibration(uint8_t channel, float* offset)
185 {
186  if (channel > FDC_CH_4)
187  return FDC_CONF_ERR;
188  uint8_t temp[2];
189  uint8_t error = FDC_ReadRegister(FDC1004Q_OFFSET_CAL_CIN1 + channel, temp);
190  if (error == FDC_OK)
191  {
192  int16_t reg = temp[0] << 8 | temp[1];
193  float off = (float) (reg);
194  *offset = off/(2048); // off / (2<<11)
195 
196  *offset = fixed_to_float_signed(temp[0] << 8 | temp[1], FIXED_POINT_FRACTIONAL_BITS_OFFSET);
197  }
198  return error;
199 }
200 
201 // Read offset calibration as signed int
202 uint8_t FDC_ReadRawOffsetCalibration(uint8_t channel, int16_t* offset)
203 {
204  if (channel > FDC_CH_4)
205  return FDC_CONF_ERR;
206  uint8_t temp[2];
207  uint8_t error = FDC_ReadRegister(FDC1004Q_OFFSET_CAL_CIN1 + channel, temp);
208  if (error == FDC_OK)
209  {
210  *offset = temp[0] << 8 | temp[1];
211  }
212  return error;
213 }
214 
215 // Set calibration gain in float format
216 uint8_t FDC_SetGainCalibration(uint8_t channel, float gain)
217 {
218  if (channel > FDC_CH_4)
219  return FDC_CONF_ERR;
220  if ( (gain < 0) || (gain > 4))
221  return FDC_CONF_ERR;
222  uint16_t gain_u16 = float_to_fixed_unsigned(gain, FIXED_POINT_FRACTIONAL_BITS_GAIN);
223  uint8_t temp[2] = {gain_u16 >> 8, gain_u16 & 0xFF};
224  return FDC_WriteRegister(FDC1004Q_GAIN_CAL_CIN1 + channel, temp);
225 }
226 
227 // Set gain calibration in raw format
228 uint8_t FDC_SetRawGainCalibration(uint8_t channel, uint16_t gain)
229 {
230  if (channel > FDC_CH_4)
231  return FDC_CONF_ERR;
232  float gain_f = fixed_to_float_unsigned(gain, FIXED_POINT_FRACTIONAL_BITS_GAIN);
233  if ( (gain_f < 0) || (gain_f > 4))
234  return FDC_CONF_ERR;
235  uint8_t temp[2] = {gain >> 8, gain & 0xFF};
236  return FDC_WriteRegister(FDC1004Q_GAIN_CAL_CIN1 + channel, temp);
237 }
238 
239 // Read gain calibration in float format
240 uint8_t FDC_ReadGainCalibration(uint8_t channel, float* gain)
241 {
242  if (channel > FDC_CH_4)
243  return FDC_CONF_ERR;
244  uint8_t temp[2];
245  uint8_t error = FDC_ReadRegister(FDC1004Q_GAIN_CAL_CIN1 + channel, temp);
246  if (error == I2C_NO_ERROR)
247  {
248  *gain = fixed_to_float_unsigned(temp[0] << 8 | temp[1], FIXED_POINT_FRACTIONAL_BITS_GAIN);
249  }
250  return error;
251 }
252 
253 // Read raw gain calibration in raw format
254 uint8_t FDC_ReadRawGainCalibration(uint8_t channel, uint16_t* gain)
255 {
256  if (channel > FDC_CH_4)
257  return FDC_CONF_ERR;
258  uint8_t temp[2];
259  uint8_t error = FDC_ReadRegister(FDC1004Q_GAIN_CAL_CIN1 + channel, temp);
260  if (error == I2C_NO_ERROR)
261  {
262  *gain = temp[0] << 8 | temp[1];
263  }
264  return error;
265 }
266 
267 // ===========================================================
268 // MEASUREMENTS CONFIGURATIONS
269 // ===========================================================
270 
271 // Init a measurement for a given channel
272 uint8_t FDC_InitMeasurement(uint8_t channel)
273 {
274  if (channel > FDC_CH_4)
275  return FDC_CONF_ERR;
276  uint8_t temp[2];
277  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
278  if (error == FDC_OK)
279  {
280  // Clear bit of channel
281  temp[1] &= ~ ( 1 << (7 - channel));
282  // Set bit
283  temp[1] |= (1 << (7 - channel));
284  error = FDC_WriteRegister(FDC1004Q_FDC_CONF, temp);
285  }
286  return error;
287 }
288 
289 // Stop a measurement for a given channel
290 uint8_t FDC_StopMeasurement(uint8_t channel)
291 {
292  if (channel > FDC_CH_4)
293  return FDC_CONF_ERR;
294  uint8_t temp[2];
295  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
296  if (error == FDC_OK)
297  {
298  // Clear bit of channel
299  temp[1] &= ~ (1 << (7 - channel));
300 
301  error = FDC_WriteRegister(FDC1004Q_FDC_CONF, temp);
302  }
303  return error;
304 }
305 
306 // Check if channel measurement is complete
307 uint8_t FDC_IsMeasurementDone(uint8_t channel, uint8_t* done)
308 {
309  if (channel > FDC_CH_4)
310  return FDC_CONF_ERR;
311  uint8_t temp[2];
312  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
313  if (error == FDC_OK)
314  {
315  *done = temp[1] & (0x08 >> channel);
316  }
317  return error;
318 }
319 
320 // Enable repeated measurements --> all measurements must be already enabled
321 uint8_t FDC_EnableRepeatMeasurement(uint8_t channel_flags)
322 {
323  // Read FDC register, set REPEAT Bits and write register again
324  uint8_t temp[2];
325  // Disable all measurements
326  uint8_t error = FDC_CONF_ERR;
327  for (uint8_t ch = FDC_CH_1; ch < FDC_CH_4; ch ++)
328  {
329  error = FDC_StopMeasurement(ch);
330  if ( error != FDC_OK)
331  {
332  return FDC_COMM_ERR;
333  }
334  }
335  // Read configuration register
336  error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
337  if (error == FDC_OK)
338  {
339  // Set REPEAT bit
340  temp[0] |= 1;
341  temp[1] |= channel_flags;
342  error = FDC_WriteRegister(FDC1004Q_FDC_CONF, temp);
343 
344  }
345  return error;
346 }
347 
348 // Disable repeated measurements
350 {
351  // Read FDC register, set REPEAT Bits
352  uint8_t temp[2];
353  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
354  if (error == FDC_OK)
355  {
356  // Clear bit 8
357  temp[0] &= 0xFE;
358  error = FDC_WriteRegister(FDC1004Q_FDC_CONF, temp);
359  }
360  return error;
361 }
362 
363 // Configure inputs for measurement
364 uint8_t FDC_ConfigureMeasurementInput(uint8_t meas_channel,
365  uint8_t pos,
366  uint8_t neg,
367  uint8_t capdac)
368 {
369 
370  // Check positive and negative input
371  if ( ( neg == pos ) || ( pos > neg) || (capdac > 31) || (pos == FDC_CAPDAC) || (pos == FDC_DISABLED) )
372  {
373  return FDC_CONF_ERR;
374  }
375  if (meas_channel > FDC_CH_4)
376  return FDC_CONF_ERR;
377  // Read current value in the register
378  uint8_t temp[2];
379  uint8_t error = FDC_ReadRegister(FDC1004Q_CONF_MEAS1 + meas_channel, temp);
380  if ( error == I2C_NO_ERROR)
381  {
382  uint16_t temp16 = temp[0] << 8 | temp[1];
383  // Clear all required bits
384  temp16 &= ~0xFFF0;
385  // Configure capdac
386  temp16 |= capdac << 5;
387  // Configure pos
388  temp16 |= pos << 13;
389  // Configure neg
390  temp16 |= neg << 10;
391  // Write new register value
392  temp[0] = temp16 >> 8;
393  temp[1] = temp16 & 0xFF;
394  error = FDC_WriteRegister(FDC1004Q_CONF_MEAS1 + meas_channel, temp);
395  }
396  return error;
397 }
398 
399 // Configure channel
400 uint8_t FDC_ConfigureMeasurement(uint8_t meas_channel,
401  uint8_t pos_channel,
402  uint8_t neg_channel,
403  uint8_t capdac,
404  int16_t offset,
405  uint16_t gain)
406 {
407  if (meas_channel > FDC_CH_4)
408  return FDC_CONF_ERR;
409  uint8_t error = FDC_SetRawGainCalibration(meas_channel, gain);
410  error = FDC_SetRawOffsetCalibration(meas_channel, offset);
411  error = FDC_ConfigureMeasurementInput(meas_channel, pos_channel, neg_channel, capdac);
412  return error;
413 }
414 
415 // ===========================================================
416 // READOUT CAPACITANCE VALUES
417 // ===========================================================
418 
419 // Read capacitance in raw format
420 uint8_t FDC_ReadRawMeasurement(uint8_t channel, uint32_t* capacitance)
421 {
422  if (channel > FDC_CH_4)
423  return FDC_CONF_ERR;
424  uint8_t temp[2];
425  uint8_t error = FDC_ReadRegister(FDC1004Q_MEAS1_MSB + (2*channel), temp);
426  if (error == FDC_OK)
427  {
428  *capacitance = (temp[0] << 24) | (temp[1] << 16);
429  error = FDC_ReadRegister(FDC1004Q_MEAS1_LSB + (2*channel), temp);
430  if (error == FDC_OK)
431  {
432  *capacitance |= temp[0] << 8 | temp[1];
433  }
434  }
435  return error;
436 }
437 
438 // Read capaciity in float format
439 uint8_t FDC_ReadMeasurement(uint8_t channel, double* capacitance)
440 {
441  if (channel > FDC_CH_4)
442  return FDC_CONF_ERR;
443  uint32_t capRaw;
444  uint8_t error = FDC_ReadRawMeasurement(channel, &capRaw);
445  if ( error == FDC_OK)
446  {
447  double temp_cap = (double)(capRaw >> 8);
448  if (temp_cap > ( (1 << 23) -1))
449  {
450  temp_cap -= ( 1 << 24);
451  }
452  temp_cap /= (2<<18);
453  // Read current capdac setting
454  uint8_t temp[2];
455  error = FDC_ReadRegister(FDC1004Q_CONF_MEAS1 + channel, temp);
456  if ( error == I2C_NO_ERROR)
457  {
458  // Read current capdac
459  uint16_t temp16 = temp[0] << 8 | temp[1];
460  uint8_t capdac = (temp16 >> 5) & 0x1F;
461  // Add offset
462  *capacitance = temp_cap + capdac * FDC_CAPDAC_FACTOR;
463  error = FDC_OK;
464  }
465  }
466  return error;
467 }
468 
469 // Convert raw to double
470 double FDC_ConvertRawMeasurement(uint32_t capacitance)
471 {
472  double temp_cap = (double)(capacitance >> 8);
473  if (temp_cap > ( (1 << 23) -1))
474  {
475  temp_cap -= ( 1 << 24);
476  }
477  temp_cap /= (2<<18);
478  return temp_cap;
479 }
480 
481 uint8_t FDC_ReadRawCapdacSetting(uint8_t channel, uint8_t* capdac)
482 {
483  if (channel > FDC_CH_4)
484  return FDC_CONF_ERR;
485  // Read current capdac setting
486  uint8_t temp[2];
487  uint8_t error = FDC_ReadRegister(FDC1004Q_CONF_MEAS1 + channel, temp);
488  if ( error == FDC_OK)
489  {
490  // Read current capdac
491  uint16_t temp16 = temp[0] << 8 | temp[1];
492  *capdac = (temp16 >> 5) & 0x1F;
493  }
494  return error;
495 }
496 
497 uint8_t FDC_ReadCapdacSetting(uint8_t channel, float* capdac)
498 {
499  if (channel > FDC_CH_4)
500  return FDC_CONF_ERR;
501  // Read current capdac setting
502  uint8_t temp[2];
503  uint8_t error = FDC_ReadRegister(FDC1004Q_CONF_MEAS1 + channel, temp);
504  if ( error == I2C_NO_ERROR)
505  {
506  // Read current capdac
507  uint16_t temp16 = temp[0] << 8 | temp[1];
508  *capdac = (temp16 >> 5) & 0x1F;
509  *capdac *= FDC_CAPDAC_FACTOR;
510  }
511  return error;
512 }
513 uint8_t FDC_ReadPositiveChannelSetting(uint8_t channel, uint8_t* input)
514 {
515  if (channel > FDC_CH_4)
516  return FDC_CONF_ERR;
517  // Read current capdac setting
518  uint8_t temp[2];
519 
520  uint8_t error = FDC_ReadRegister(FDC1004Q_CONF_MEAS1 + channel, temp);
521  if ( error == I2C_NO_ERROR)
522  {
523  uint16_t temp16 = temp[0] << 8 | temp[1];
524  *input = (temp16 >> 13) & 0x07;
525  }
526  return error;
527 }
528 
529 
530 uint8_t FDC_ReadNegativeChannelSetting(uint8_t channel, uint8_t* input)
531 {
532  if (channel > FDC_CH_4)
533  return FDC_CONF_ERR;
534  // Read current capdac setting
535  uint8_t temp[2];
536 
537  uint8_t error = I2C_Peripheral_ReadRegisterMulti(FDC1004Q_I2C_ADDR, FDC1004Q_CONF_MEAS1 + channel, 2, temp);
538  if ( error == I2C_NO_ERROR)
539  {
540  uint16_t temp16 = temp[0] << 8 | temp[1];
541  *input = (temp16 >> 10) & 0x07;
542  }
543  return error;
544 }
545 
546 // Check if one of the channels has new data
547 uint8_t FDC_HasNewData(uint8_t* done)
548 {
549  // Check if there are new measurement data
550  uint8_t temp[2]; // temp buffer
551  uint8_t error = FDC_ReadRegister(FDC1004Q_FDC_CONF, temp);
552  if (error == FDC_OK)
553  {
554  // Mask with last 4 bits
555  *done = temp[1] & 0xF;
556  }
557  return error;
558 }
559 
560 
561 // ===========================================================
562 // MANUFACTURER ID / DEVICE ID FUNCTIONS
563 // ===========================================================
564 
565 // Read manufacturer ID
566 uint8_t FDC_ReadManufacturerId(uint16_t* reg_value)
567 {
568  uint8_t temp[2];
569  uint8_t error = FDC_ReadRegister(FDC1004Q_MANUFACTURER_ID, temp);
570  if (error == FDC_OK)
571  {
572  *reg_value = (temp[0] << 8) | temp[1];
573  }
574 
575  return error;
576 
577 }
578 
579 // Read device ID
580 uint8_t FDC_ReadDeviceId(uint16_t* reg_value)
581 {
582  uint8_t temp[2];
583  uint8_t error = FDC_ReadRegister(FDC1004Q_DEVICE_ID, temp);
584  if (error == FDC_OK)
585  {
586  *reg_value = (temp[0] << 8) | temp[1];
587  }
588 
589  return error;
590 }
591 
592 // ===========================================================
593 // READ / WRITE REGISTER
594 // ===========================================================
595 
596 // Read register with 16 bit of data
597 uint8_t FDC_ReadRegister(uint8_t reg_addr, uint8_t* data)
598 {
599  uint8_t error = I2C_Peripheral_ReadRegisterMulti(FDC1004Q_I2C_ADDR, reg_addr, 2, data);
600  if (error == I2C_NO_ERROR)
601  {
602  return FDC_OK;
603  }
604  else
605  {
606  return FDC_COMM_ERR;
607  }
608 }
609 
610 // Write register with 16 bit of data
611 uint8_t FDC_WriteRegister(uint8_t reg_addr, uint8_t* data)
612 {
613  uint8_t error = I2C_Peripheral_WriteRegisterMulti(FDC1004Q_I2C_ADDR, reg_addr, 2, data);
614  if (error == I2C_NO_ERROR)
615  {
616  return FDC_OK;
617  }
618  else
619  {
620  return FDC_COMM_ERR;
621  }
622 }
623 
624 
625 
626 // ===================================================================
627 // HELPER FUNCTIONS
628 // ===================================================================
629 
630 float fixed_to_float_unsigned(uint16_t input, uint8_t fract_bits)
631 {
632  return ((float)input / (float)(1 << fract_bits));
633 }
634 
635 int16_t float_to_fixed_unsigned(float input, uint8_t fract_bits)
636 {
637  return (uint16_t)(input * (1 << fract_bits));
638 }
639 
640 float fixed_to_float_signed(int16_t input, uint8_t fract_bits)
641 {
642  return ((float)input / (float)(1 << fract_bits));
643 }
644 
645 int16_t float_to_fixed_signed(float input, uint8_t fract_bits)
646 {
647  return (int16_t)(input * (1 << fract_bits));
648 }
649 
650 /* [] END OF FILE */
#define FDC_CH_1
FDC Capacitance channel 1.
uint8_t FDC_ReadRawOffsetCalibration(uint8_t channel, int16_t *offset)
Read channel offset calibration register as Q5.11 format.
Definition: FDC1004Q.c:202
uint8_t FDC_ReadCapdacSetting(uint8_t channel, float *capdac)
Read current capdac setting in float format.
Definition: FDC1004Q.c:497
#define FDC_DISABLED
Channel disabled - GND.
I2C_ErrorCode I2C_Peripheral_Start(void)
Start the I2C peripheral.
Definition: I2C_Interface.c:23
uint8_t FDC_ReadNegativeChannelSetting(uint8_t channel, uint8_t *input)
Read current negative input channel setting.
Definition: FDC1004Q.c:530
uint8_t FDC_Reset(void)
Perform a software reset of the sensor.
Definition: FDC1004Q.c:95
Hardware specific I2C interface.
#define FDC_COMM_ERR
Communication error on I2C bus.
double FDC_ConvertRawMeasurement(uint32_t capacitance)
Convert raw capacitance measurement in double format.
Definition: FDC1004Q.c:470
#define FDC_CH_4
FDC Capacitance channel 4.
#define FDC_400_Hz
400 Samples/second sample rate.
#define FDC1004Q_MANUFACTURER_ID
ID of Texas Instruments Register.
uint8_t FDC_ReadRawCapdacSetting(uint8_t channel, uint8_t *capdac)
Read current capdac setting.
Definition: FDC1004Q.c:481
uint8_t FDC_DisableRepeatMeasurement(void)
Disable repated measurement.
Definition: FDC1004Q.c:349
Header file for the FDC1004Q driver.
uint8_t FDC_ConfigureMeasurement(uint8_t meas_channel, uint8_t pos_channel, uint8_t neg_channel, uint8_t capdac, int16_t offset, uint16_t gain)
Configure measurement settings.
Definition: FDC1004Q.c:400
#define FDC_CAPDAC
CAPDAC input.
uint8_t FDC_ReadManufacturerId(uint16_t *id)
Read the manufacturer ID from the sensor.
Definition: FDC1004Q.c:566
I2C_ErrorCode I2C_Peripheral_WriteRegisterMulti(uint8_t device_address, uint8_t register_address, uint8_t register_count, uint8_t *data)
Write multiple bytes over I2C.
uint8_t FDC_ReadDeviceId(uint16_t *id)
Read the device ID from the sensor.
Definition: FDC1004Q.c:580
uint8_t FDC_StopMeasurement(uint8_t channel)
Stop measurement for given channel.
Definition: FDC1004Q.c:290
uint8_t FDC_IsDeviceConnected(void)
Check if device is connected on the I2C bus.
Definition: FDC1004Q.c:73
#define FDC1004Q_CONF_MEAS1
Measurement 1 Configuration Register.
uint8_t FDC_ReadRegister(uint8_t reg_addr, uint8_t *data)
Read a register from the FDC1004Q.
Definition: FDC1004Q.c:597
uint8_t FDC_ReadOffsetCalibration(uint8_t channel, float *offset)
Read channel offset calibration register as float value.
Definition: FDC1004Q.c:184
#define FDC_CAPDAC_FACTOR
CAPDAC multiplying factor.
Definition: FDC1004Q_Defs.h:14
#define FDC_CONF_ERR
Channel configuration error.
uint8_t FDC_ReadRawMeasurement(uint8_t channel, uint32_t *capacitance)
Read capacitance measurement in raw format.
Definition: FDC1004Q.c:420
uint8_t FDC_ReadMeasurement(uint8_t channel, double *capacitance)
Read capacitance measurement in double format.
Definition: FDC1004Q.c:439
uint8_t FDC_EnableRepeatMeasurement(uint8_t channel_flags)
Enable repeated measurement.
Definition: FDC1004Q.c:321
#define FDC1004Q_DEVICE_ID
ID of FDC1004Q device Register.
#define FDC_OK
No error occurred.
uint8_t FDC_ReadGainCalibration(uint8_t channel, float *gain)
Read gain calibration register in float format.
Definition: FDC1004Q.c:240
uint8_t FDC_WriteRegister(uint8_t reg_addr, uint8_t *data)
Write a register to the FDC1004Q.
Definition: FDC1004Q.c:611
uint8_t FDC_IsMeasurementDone(uint8_t channel, uint8_t *done)
Check if measurement for a given channel is complete.
Definition: FDC1004Q.c:307
uint8_t FDC_SetRawOffsetCalibration(uint8_t channel, int16_t offset)
Set channel offset calibration register in raw format.
Definition: FDC1004Q.c:172
uint8_t FDC_Start(void)
Start the FDC1004Q.
Definition: FDC1004Q.c:58
uint8_t FDC_InitMeasurement(uint8_t channel)
Init measurement for given channel.
Definition: FDC1004Q.c:272
#define FDC1004Q_OFFSET_CAL_CIN1
CIN1 Offset Calibration Register.
#define FDC_DEV_NOT_FOUND
Device not found on I2C bus.
uint8_t FDC_SetSampleRate(uint8_t sampleRate)
Set up sample rate for continuous measurements.
Definition: FDC1004Q.c:125
#define FDC1004Q_MEAS1_MSB
MSB Portion of Measurement 1 Register.
Definition: FDC1004Q_Defs.h:37
uint8_t FDC_SetOffsetCalibration(uint8_t channel, float offset)
Set channel offset calibration register in float format.
Definition: FDC1004Q.c:156
#define FDC1004Q_GAIN_CAL_CIN1
CIN1 Gain Calibration Register.
#define FDC1004Q_FDC_CONF
Capacitance to Digital Configuration Register.
I2C_ErrorCode I2C_Peripheral_Stop(void)
Stop the I2C peripheral.
Definition: I2C_Interface.c:33
uint8_t FDC_SetRawGainCalibration(uint8_t channel, uint16_t gain)
Set gain calibration register in Q2.14 format.
Definition: FDC1004Q.c:228
uint8_t FDC_ReadSampleRate(uint8_t *sampleRate)
Read current sample rate.
Definition: FDC1004Q.c:144
uint8_t FDC_SetGainCalibration(uint8_t channel, float gain)
Set gain calibration register.
Definition: FDC1004Q.c:216
uint8_t FDC_HasNewData(uint8_t *done)
Check if new measurement data are available to be read.
Definition: FDC1004Q.c:547
void FDC_Stop(void)
Stop communication with the FDC1004Q.
Definition: FDC1004Q.c:68
uint8_t FDC_ReadPositiveChannelSetting(uint8_t channel, uint8_t *input)
Read current positive input channel setting.
Definition: FDC1004Q.c:513
uint8_t FDC_ConfigureMeasurementInput(uint8_t meas_channel, uint8_t pos_channel, uint8_t neg_channel, uint8_t capdac)
Configure measurement input settings.
Definition: FDC1004Q.c:364
uint8_t FDC_ReadRawGainCalibration(uint8_t channel, uint16_t *gain)
Read gain calibration register in fixed point Q2.14 formta.
Definition: FDC1004Q.c:254
#define FDC1004Q_MEAS1_LSB
LSB Portion of Measurement 1 Register.
Definition: FDC1004Q_Defs.h:46
I2C_ErrorCode I2C_Peripheral_ReadRegisterMulti(uint8_t device_address, uint8_t register_address, uint8_t register_count, uint8_t *data)
Read multiple bytes over I2C.
Definition: I2C_Interface.c:71