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:

Parents
  • 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).

Reply
  • 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).

Children
No Data