AD7124-4 SPI read problem

Hello,

I''m trying to read the device ID at 0x05 on the AD7124-4 using an stm32f4 discover board. Here are my initialization and read routines. 

//initialization

SPI_InitStruct.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_256; // This would come to 45/256 Mhz
SPI_InitStruct.SPI_Direction=SPI_Direction_2Lines_FullDuplex;
SPI_InitStruct.SPI_Mode=SPI_Mode_Master;
SPI_InitStruct.SPI_DataSize=SPI_DataSize_8b;
SPI_InitStruct.SPI_FirstBit=SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CPOL=SPI_CPOL_Low; //Clock polarity
SPI_InitStruct.SPI_CPHA=SPI_CPHA_2Edge; //Clock phase
SPI_InitStruct.SPI_NSS=SPI_NSS_Soft;

//read

uint8_t SPI_Rx(uint8_t adress)
{
   GPIO_ResetBits(GPIOE,GPIO_Pin_4); // This is the chip select
   adress=0x40|adress; // creating the command byte


   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE));
   SPI_I2S_SendData(SPI2,adress);


   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE));
   SPI_I2S_ReceiveData(SPI2);


   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE));
   SPI_I2S_SendData(SPI2,0x00); //dummy byte


   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE));

   GPIO_SetBits(GPIOE,GPIO_Pin_4);
   return SPI_I2S_ReceiveData(SPI2);
}

Here's what my logic analyzer was reading. Data is MOSI and DIO15 is MISO:

  • 0
    •  Analog Employees 
    on Oct 26, 2017 11:48 PM over 3 years ago

    Hi,

    May I know what is your SCLK frequency? I noticed that your CS is low for a short period of time. Can you add delays to make it longer? Can you also try to just monitor the DRDY pin. Upon power up, can you reset the part by applying at least 64 consecutive 1s. This will ensure that all registers are set to their default values. Pull CS low, you should see that the DRDY pin is pulsing at the default output data rate. Does it pulse at correct ODR?

    Thanks,

    Jellenie

  • 0
    •  Analog Employees 
    on Nov 2, 2017 10:48 PM over 2 years ago

    Hi,

    What are the instances that it is not 0x04?

    Yes, it is recommended to perform a reset upon power up to ensure that everything is on default settings and correct you only need to write at least 64 consecutive 1s to MOSI and there's no any address to call.

    What I mean with " Pull CS low, you should see that the DRDY pin is pulsing at the default output data rate" is upon power up just tie your CS low, do not write or read back the registers, just monitor the DRDY pin and it should be pulsing at default output data rate which is about 6.25sps (160ms). I only see glitches on the above scope shot. Have you properly connected and grounded the digital lines? Glitches on the SCLK line can make serial interface become asynchronous. Can you ensure that there's no glitches on the SPI interface? May I know also what is your digital supply?  

    Thanks,

    Jellenie

  • Hi JellenieR

    Thanks for your reply. I'm running at 0.175 MHz. For now I grounded the chip select and I was able to read 0x04. But it seems very erratic. It doesn't always read 0x04 every time I read the device id register. 

    What could the issues be?

    Is the resetting the device a compulsory procedure? (how do i reset: Should I be sending consecutive 1's to MOSI without an address?)

    Also I didn't quite get what you meant by " Pull CS low, you should see that the DRDY pin is pulsing at the default output data rate." Pull CS down during a SPI read or write? 

    If i do

    while(1){

       SPI_read(0x05);

    }

    and Check DRDY, I see (attached scope picture).

  • Hi Jellenie,

    Thanks for your reply and apologies for the late response. To avoid signal integrity and noise issues I'm trying to do a spi read on the 0x05 register on the EVAL-AD7124-4SDZ. I removed the EVAL-SDP-CB1Z from the 120 pin header and used the test points TSCLK,T\CS, TDIN, DOUT (image attached). Although I'm not sure why you asked to remove the 0 ohm resistor in an earlier post. I have not removed the 0 ohm resistor here.

    When I tried to do a SPI read with CS pulled to ground, I can see the clock pulsing and the MOSI also sending the data, but MISO is high all the time.

    I tried one of your suggestions to monitor the DOUT pin while CS is grounded. It was not pulsing like you suggested it was high all the time.