Skip to content

Repository files navigation

Relevant registers and configurations are defined in fdc1004.h.

  1. To use the driver, #include "fdc1004.h".

  2. Configure an I2C peripheral with the right timings by writing to its TIMINGR register.

  3. Define an fdc1004 instance with its associated I2C peripheral ex: fdc1004 fdc = (fdc1004) { .i2c = I2C1 };

  4. Call the driver's interrupt handler in the I2C peripheral's interrupt handler ex:

void I2C1_IRQHandler(void)
{
	fdc1004_handler(&fdc);
}
  1. Configure the I2C peripheral using CMSIS by calling fdc1004_init(&fdc);

  2. Configure the FDC1004 IC over I2C using the given defines by calling fdc1004_configure(...) ex:

fdc1004_configure(
  &fdc,
  FDC_CONF_RATE_100,
  FDC_CONF_REPEAT_ENABLED,
  FDC_CONF_MEAS_1_ENABLED,
  FDC_CONF_MEAS_2_DISABLED,
  FDC_CONF_MEAS_3_DISABLED,
  FDC_CONF_MEAS_4_DISABLED
);
  1. Configure the FDC1004 IC's measurements by calling fdc_configure_measurement(...) ex:
fdc1004_configure_measurement(
  &fdc,
  CONF_MEAS1,
  CONF_MEAS_CHA_CIN1,
  CONF_MEAS_CHB_CAPDAC,
  fdc1004_pf_to_capdac(3.125f)
);

Since the driver's read/write operations are non-blocking, use fdc1004_peripheral_busy(...) to make sure communication with the FDC1004 IC is finished before and after attempting an operation! The read and write functions will return false if the peripheral is busy.

  1. Read the FDC1004 IC's registers using fdc_read_register(...) ex:
while(fdc1004_peripheral_busy(&fdc));
fdc1004_read_register(&fdc, DEVICE_ID);
while(fdc1004_peripheral_busy(&fdc));

uint16_t device_id = fdc.data;
  1. Write the FDC1004 IC's registers using fdc_write_register(...) ex:
while(fdc1004_peripheral_busy(&fdc));
fdc1004_write_register(&fdc, OFFSET_CAL_CIN1, fdc1004_pf_to_offset_cal(1.5625f));
while(fdc1004_peripheral_busy(&fdc));
  1. Numerous helper functions are given to allow converting floating point values to register values and vice versa.

About

STM32 I2C driver to interface with the TI FDC1004 Capacitance-to-Digital Converter. Compatible with STM32C0 MCUs and others with the same I2C peripheral registers.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages