Post Go back to editing

AD5940_BATImpedance Files

Category: Software
Product Number: AD5940
Software Version: 1

After writing c code for AD5940 SPI drivers that can read & write to the ad5940 registers, I am now trying to clone the necessary files to implement the full AD5940_BATImpedance system.
However while I can write my own "hardware porting file" code to provide the all the necessary low level SPI functions such as reading and writing to registers there appears a significant issue with integrating the core ad5940.c and ad5940.h files as there is confusion in regards to the functions defined in these files. 

For example the ad5940.h file suggests that only these functions need to be implemented for specific hardware controllers ?

void      AD5940_CsClr(void);
void      AD5940_CsSet(void);
void      AD5940_RstClr(void);
void      AD5940_RstSet(void);
void      AD5940_Delay10us(uint32_t time);
/* (Not used for now.)AD5940 has 8 GPIOs, some of them are connected to MCU. MCU can set or read the status of these pins. */
void      AD5940_MCUGpioWrite(uint32_t data);   /*  */
uint32_t  AD5940_MCUGpioRead(uint32_t);
void      AD5940_MCUGpioCtrl(uint32_t, BoolFlag);
void      AD5940_ReadWriteNBytes(unsigned char *pSendBuffer,unsigned char *pRecvBuff,unsigned long length);
/* Below functions are frequently used in example code but not necessary for library */
uint32_t  AD5940_GetMCUIntFlag(void);
uint32_t  AD5940_ClrMCUIntFlag(void);
uint32_t  AD5940_MCUResourceInit(void *pCfg);

However there are many other functions that are dependent on SPI functions that are not represented in the above .. these include the following ...
/* 1. Basic SPI functions */
void      AD5940_WriteReg(uint16_t RegAddr, uint32_t RegData);
uint32_t  AD5940_ReadReg(uint16_t RegAddr);
void      AD5940_FIFORd(uint32_t *pBuffer,uint32_t uiReadCount);
void      AD5940_HWReset(void);       /* Do hardware reset to AD5940 using RESET pin */
void      AD5940_Initialize(void);
static unsigned char AD5940_ReadWrite8B(unsigned char data);
static uint16_t AD5940_ReadWrite16B(uint16_t data);
static uint32_t AD5940_ReadWrite32B(uint32_t data);

Can someone please clarify exactly what functions in the ad5940.c and ad5940.h files need to be carried out externally in my "hardware porting file"

Thank you 
Collin.



  • Further to my investigation I find that the ad5940.c and ad5940.h files are bloated up with unnecessary complexities/functions with RAW SPI functions that are not required and will not work because they do not follow the ADI SPI protocol requirements. They don’t send SPICMD_SETADDR, SPICMD_READREG, or SPICMD_WRITEREG — which are mandatory protocol requirements for AD5940 register access, so what real function or purpose do they actually perform? Are they required or used by the higher level applications ( AppBATImpedance, etc.)  I cannot see how as these APP's should work even with these unnecessary functions, especially working outside the ADuCM355 ecosystem which relies on manually generated SPI CS logic unlike standard SPI control where the CS line is automatically controlled in the SPI transactions.

    The AD5940 SDK files (ad5940.c/.h) appear riddled with many abstractions that don’t match the actual ADI SPI protocol requirements? Its difficult to know which functions are actually needed. 

    Also functions are defined for 32bit writes to registers but the datasheet lists no 32 bit registers at all. They way I see it the only required RAW hardware functions that are needed to be provided are 
    1) 
    uint32_t ad5940_read_reg32(uint16_t addr)  .... read 32 bit data from 16bit address
    2) 
    void ad5940_write_reg16(uint16_t addr, uint16_t value)  ... write 16bit data to 16bit address since the chip only uses 16bits
    3)   ad5940_read_fifo()  ?

    I do not see the need for other functions .. can someone shed a light of these aspects?

    Thanks for your help.
    Collin

  • Hi,  ,

     will be able to assist you on this request.

    Best regards,
    Christian