AnsweredAssumed Answered

Weird write problems in some registers

Question asked by jay_hj on Dec 5, 2017
Latest reply on Dec 13, 2017 by jay_hj

Hi, 

 

I'm trying to configure the AD7124-4. I'm facing really bizarre issues.

1. when I try to write 0x8087 to Channel_0 register (0x10), it doesn't get written. I know this since when I read back I get 0x8081. And this is not limited to this register, but in multiple 16-bit registers.

 

2. I have successfully read 0x05 register and it returns 0x04.

 

3. I successfully wrote 0x008011 to the IO_CONTROL_1 register and I'm able to read back the same value.

 

I'm using an STM32 discovery microcontroller to interface with the ADC7124 chip using a SPI bus running at 0.175 Mhz.

 

My SPI_write code:

 

uint8_t SPI_Tx(uint8_t address, uint32_t data, uint8_t nbytes){


   uint8_t i;
   uint32_t mask;


   GPIO_ResetBits(GPIOE,GPIO_Pin_4);// Pull CS low


   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE));
   SPI_I2S_SendData(SPI2,address);
   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE));
   SPI_I2S_ReceiveData(SPI2);
   while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE));

 

   for(i=0 ; i< (nbytes); i++){
      mask = ((1<<8)-1)<< (8*i);
      SPI_I2S_SendData(SPI2, (uint8_t)((data & mask) >> (8*i)));
      while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE));
      SPI_I2S_ReceiveData(SPI2);
      while(!SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE));
}

 

GPIO_SetBits(GPIOE,GPIO_Pin_4);// Pull CS HIGH

 

return i;
}

 

Am I missing something here ? Any help would be greatly appreciated.

Outcomes