Post Go back to editing

Initializing the AD5421

Hello, I am working with the AD5421 Eval Board, and I was wondering about how to make sure the AD5421_Init() function provided in the drivers for the device is working properly. More specifically, I want to ensure that the AD5421_SetRegisterValue() function called in the Init is working the way it should. I am following the instructions given in the datasheet for the device for how to write data to a register--chip select goes low to write data into the Input Shift Register, then on chip select rising edge the data is processed into the user-provided register.

I am using SPI communication to send information over to the AD5421 from my microcontroller, and the information is being transmitted correctly.

unsigned char AD5421_Init(void)
{
	unsigned char status = 0x1;
    
	// setup 
	AD5421_SetRegisterValue(AD5421_REG_CTRL,
		AD5421_CTRL_WATCHDOG_DISABLE |
		AD5421_CTRL_ADC_SOURCE_TEMP |
		AD5421_CTRL_ADC_ENABLE
		);
	if(AD5421_GetRegisterValue(AD5421_REG_CTRL) != 0x1180)
        {
		status = 0x0;
	}
	 
	return (status);
}

This is the Init() function provided by Analog Devices for the hardware.

void AD5421_SetRegisterValue(unsigned char regAddress, unsigned short regValue)
{
	unsigned char data[5] = {0x03, 0x00, 0x00, 0x00, 0x00};	
	
	data[0] = regAddress;
	data[1] = (unsigned char)((regValue & 0xFF00) >> 8);
	data[2] = (unsigned char)((regValue & 0x00FF) >> 0);	    
        sendBuffer(data, 3);
}

This is the modified code for the SetRegisterValue() function which is called in the Init(). It is the same as the original provided by Analog but it is using my own write function to send data to the AD5421 over SPI.

void sendBuffer(char* txBuffer, int bufferSize)
{
  USART_TypeDef *spi = USART1;
  
  GPIO_PinOutClear(gpioPortC, 10);
  for(int i = 0; i < bufferSize; i++)
  {
    while(!(spi->STATUS & USART_STATUS_TXBL));
    
    if(txBuffer != NULL)
    {
      spi->TXDATA = *txBuffer;
      txBuffer++;
    }
    else
      spi->TXDATA = 0;
  }
  while(!(spi->STATUS & USART_STATUS_TXC));
  GPIO_PinOutSet(gpioPortC, 10);
  GPIO_PinOutSet(gpioPortD, 11);
}

This is the write function I call. The GPIO_PinOutClear() function is the chip select line control.

Could the problem be that the Eval Board is broken in some way? I did some testing with a multimeter and found that the fault pin is constantly set high and the alarm current is always running, so I assume that the board just might be toast. If the problem lies in my initialization or in my code, I would like to know as well.

  • Hi,

    Can you provide the supplies used? Have you tried measuring them to ensure that they are set correctly?

    Can you also check whether the microcontroller actually sends the correct SPI frames to the device?

    Cheers,

    Ivan

  • I am using an oscilloscope to view the SPI transmission from the microcontroller, and it is sending the right data to the AD5421. I did some current and voltage testing with a multimeter with the AD5421 connected to a 5V source and found the fault pin is always high and the current flowing in the loop was the loop alarm current of 3.2mA shown in the data sheet. If I connected the alarm current to DVDD then it gave a reading of 22.4mA, which is the alarm current when connected to DVDD.

  • Hi,

    It is normal that you observe a FAULT and the loop current on alarm state during power-on, more details on POWER-ON DEFAULT section of the data sheet, page 24.

    Can you share some screenshots of the SPI frames you sent upon power-up?

    Looks like the device was not able to detect a valid SPI transaction. 

    Other way to test is to do a readback on the control register and the fault register and observe if the device provides the expected data.

    Cheers,

    Ivan

  • The issue I am having is that even a simple write command to initialize the device does not seem to be working correctly.

    This is the data being sent in AD5421_Init() to set up the device. The first 8 bits are 0x02, which is the control register write command, followed by 0x1980, which is the correct set of bits to do

    AD5421_CTRL_WATCHDOG_DISABLE |
    AD5421_CTRL_AUTO_FAULT_READBACK |
    AD5421_CTRL_ADC_SOURCE_TEMP |
    AD5421_CTRL_ADC_ENABLE

    according to AD5421.h and the AD5421 software. All of the bits being written are shown in green and are sent on the falling edge of the clock, which is in yellow.

    The chip select line is in purple, and it does what the AD5421 expects on a write: low to write data into the Input Shift Register,  and then high to trigger the Input Shift register to send the data to the correct register. I made sure the LDAC pin is pulled low so this should be the correct way to write to the AD5421.

    After this, even if my read function does not work properly, the AD5421 should be operating as a 4-20mA, but there is no change to the device.

  • I seem to have done something strange. I can get the loop to work, but only for values of 0xFFFF, 0x7FFF, and 0x3FFF. 0x7FFF is 0xFFFF/2, and 0x3FFF is 0xFFFF/4. I think this may have to do with the LDAC pin. When the LDAC pin gets pulled low, the device draws additional current up to 8mA. Does this have to do with the ground I am tying the pin to? I am tying the LDAC pin to COM.

  • Hi,

    Looks like you already created a new query for this one. Let's continue the discussion on that particular thread.

    https://ez.analog.com/data_converters/precision_dacs/f/q-a/122178/tying-ldac-pin-of-ad5421-low

    Cheers,

    Ivan