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.