AnsweredAssumed Answered

AD7124-4 SPI read problem

Question asked by jay_hj on Oct 26, 2017
Latest reply on Nov 12, 2017 by JellenieR

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:

Attachments

Outcomes