Code API Reference - ManojBR105/SIC4340-NFC-Sensor-Patch GitHub Wiki

SIC4340 Code API Reference

There are two classes SIC4340Manager and SIC4340Config that are used to interact with the SIC4340 through NFC.

SIC4340Manager

This class deals with the interactions such as sending and receiving commands and data.

Data Members

Type Name Description
int offsetError used to store ADC offset error
double gainError used to store ADC gain error
bool toggle flag used to start/stop reading from ADC
SIC4340Config myConfig used to store ADC configuration set by user
double samplingTime used to store ADC sampling time in seconds for UI and calculation
int sensCurrent used to store bias current value in uA for calculation
double bufferSize used to store buffer(x-axis) size of the graph
Function updateGraph used to store a function that receives the latest ADC value as argument and updates the graph
Function updateState used to store a function to update the state of the widget that contains this class instance
bool scanned flag used to check if a NFC tag is scanned or not for updating UI
bool configured flag used to check if ADC configuration is sent to SIC4340

Member Functions

Return Type Name Arguments Desciption
Future scan none Call this function to poll a NFC tag. To communicate with an NFC tag it needs to be polled first
Future getError none This function reads the gain and offset error of ADC from EEPROM of SIC4340 and stores it for further calculation
Future readADC none It keeps sending read ADC command to the SIC4340 and updates the received value by calling updateGraph function until toggle is true
Future setConfig SIC4340Config config This function takes a SIC4340Config type argument and sends the commands to SIC4340 according to the configuration
void setParameters String time, int current This function takes in two arguments time in string format and current in int format which are updated after sending a new configuration to SIC4340. It updates the samplingTime and sensCurrent from the received arguments.
void show var err This function takes in an error or any error message as an argument and shows it to the user as a toast

SIC4340Config

This class has all the ADC configuration registers addresses and data members to store configuration settings.

enum Data Types

There are few custom enums that are defined for the ease of selecting different configurations.

Name index 0 index 1 index 2 index 3 index 4 index 5 index 6 index 7
AVG N_SAMPLES_1 N_SAMPLES_2 N_SAMPLES_4 N_SAMPLES_8 N_SAMPLES_16 N_SAMPLES_32 N_SAMPLES_64 N_SAMPLES_128
NBit OSR_32_BIT_5 OSR_64_BIT_7 OSR_128_BIT_8 OSR_256_BIT_9 OSR_512_BIT_10 OSR_1024_BIT_10 OSR_2048_BIT_10 OSR_4096_BIT_10
AutoConvPeriod MS_50 MS_100 MS_200 MS_500 SEC_1 SEC_2 SEC_5 SEC_10
T_CMP ns_2360 ns_2655 ns_2950 ns_3245 ns_1180 ns_1475 ns_1770 ns_2065
LPF ANTI_ALIASING KHz_1250 KHz_623 KHz_325
ConvMode SINGLE SINGLE_ CONTINUOUS AUTO
CHANNEL S0 S1 S2 NC
SIGN UNSIGNED SIGNED
AutoResp INSTANT HOLD
EN DISABLE ENABLE
MODE DIFFERENTIAL SINGLE
DC PULSE CONSTANT
STEP uA_1 uA_8

Static Data Members

The ADC register addresses are stored as static constants since it remains same for all SIC4340 chips.

Register Name Address
ADC_DIVIDER_REG 0x04
ADC_PRESCALER_REG 0x05
ADC_SAMPLE_DELAY_REG 0x06
ADC_NWAIT_REG 0x07
ADC_BIT_CONFIG_REG 0x08
ADC_MODE_CONFIG_REG 0x09
ADC_BUF_CONFIG_REG 0x0A
ADC_CH_CONFIG_REG 0x0B
ISEN_CONFIG_REG 0x0C
ISEN_VALUE_REG 0x0D
VLM_VALUE_REG 0x0E
VDD_CONFIG_REG 0x13
SENSOR_CONFIG_REG 0x18
GAP_CMPEN_REG 0x1A

Data Members

There are few data members used to store the configuration of ADC. Its types and default values are shown in the following table.

Type Name Deafault Value
int adcDivider 143
int adcPrescaler 0
int sampleDelay 160
AVG adcAvg AVG.N_SAMPLES_4
SIGN adcSign SIGN.SIGNED
NBit adcNBit NBit.OSR_1024_BIT_10
AutoConvPeriod adcAutoConvPeriod AutoConvPeriod.MS_100
AutoResp adcAutoResp AutoResp.HOLD
ConvMode adcConvMode ConvMode.AUTO
EN adcBuffer EN.ENABLE
LPF adcLPF LPF.KHz_1250
MODE adcMode MODE.SINGLE
CHANNEL adcNegChannel CHANNEL.NC
CHANNEL adcPosChannel CHANNEL.S1
CHANNEL isenChannel CHANNEL.NC
DC isenDC DC.COSTANT
EN isenVLM EN.DISABLE
STEP isenRNG STEP.uA_8
int isenValue 0
int vlmValue 255
EN vdd EN.ENABLE
EN cmpenEN EN.DISABLE
T_CMP cmpenTime T_CMP.ns_2360

Member Function

This Class has one member function. Its details are as follows.

Return Type Name Arguments Description
List<String> geConfigCommands none This function generates a list of NFC commands that needs to be sent to SIC4340 to set the configuration and returns it as a list of String.
⚠️ **GitHub.com Fallback** ⚠️