AD5420 library note

Hello all,

I recently implemented communication to the AD5420/AD5422 on the EVAL board (EVAL-AD5420/22EBZ) and was pointed to the following library. 

https://github.com/d-wsky/DAC-AD5420

It was very helpful but wanted to give others a heads up that might be working with the same library. 

It expects your SPI write function to be blocking. If you are using a microcontroller that uses buffers and interrupts so "sending" data to the write command just queues it up, the library call returns and immediately pulses the latch pin too early. This was the case for my PSOC 5LP. 

If you run into the same problem I recommend adding a check in the ad5420_write function to make sure the data is finished sending first. 

If you are ok with blocking the whole code execution this is a simple implementation that I used for the PSOC.

void ad5420_write(_uint24_t data) 
{
	// write highest byte
	SPI_MA_WriteTxData((uint8_t)(data >> 16));
	// write middle byte
    SPI_MA_WriteTxData((uint8_t)(data >> 8));
	// write lowest byte
    SPI_MA_WriteTxData((uint8_t)(data));
    //Wait here for transfer to finish, needed for timing of latching
    while(SPI_MA_GetTxBufferSize() != 0)
    {
    }
	
}

Just thought it might be helpful to others.