Relevant registers and configurations are defined in fdc1004.h.
-
To use the driver,
#include "fdc1004.h". -
Configure an I2C peripheral with the right timings by writing to its
TIMINGRregister. -
Define an
fdc1004instance with its associated I2C peripheral ex:fdc1004 fdc = (fdc1004) { .i2c = I2C1 }; -
Call the driver's interrupt handler in the I2C peripheral's interrupt handler ex:
void I2C1_IRQHandler(void)
{
fdc1004_handler(&fdc);
}
-
Configure the I2C peripheral using CMSIS by calling
fdc1004_init(&fdc); -
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
);
- 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.
- 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;
- 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));
- Numerous helper functions are given to allow converting floating point values to register values and vice versa.