Post Go back to editing

AD7190 default register not read

Hello Everyone,

  I am trying to communicate between AD7190 and MSP432P401M controller through SPI communication. My issue is I can't read default register value from AD7190.
I have attached circuit diagram and code for your reference.

The connections are as follows:-

Pin no 13,14 -left open

PIn no. 17 to GND

pin no 22 (SYNC') tied to 3.3V 

pin no. 5,6,7,8 left open

#include "msp.h"
#include "common.h"
#include "AD7730.h"

//**************SPI Initialization*******************//
void SPI_INT()
{
   P1->SEL0 |= BIT4 | BIT5 | BIT6 | BIT7;          // set 4-SPI pin as second function

   EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_SWRST;          // Put eUSCI state machine in reset
   EUSCI_B0->CTLW0 = EUSCI_B_CTLW0_SWRST |          // Remain eUSCI state machine in reset
                     EUSCI_B_CTLW0_MST |            // Set as SPI master
                     EUSCI_B_CTLW0_SYNC |           // Set as synchronous mode
                     EUSCI_B_CTLW0_MSB|             // MSB first
                     EUSCI_B_CTLW0_MODE_2 |         // 4-pin mode with slave enable when STE low
                     EUSCI_B_CTLW0_STEM |           // STE mode select
                     EUSCI_B_CTLW0_SSEL__SMCLK;     // SMCLK
   // Clock polarity initially low
   //data out on first rising edge
   //data out on first falling edge
   //this setting are according to AD7730 CLK_POL tie to ground or Zero
   EUSCI_B0->BRW = 0x01;                            // /2,fBitCl0ock = fBRCLK/(UCBRx+1).
   EUSCI_B0->CTLW0 &= ~EUSCI_B_CTLW0_SWRST;         // Initialize USCI state machine

}

//*************SPI transmit*****************
void spi_tx(uint8_t txdata)
{
   while(!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG));
   EUSCI_B0->TXBUF = txdata ;
}

//***********Function to write internal register
void WriteRegister(uint8_t W_address, int N_OF_Byte, int data)
{
    /* local variable declaration */
      int var32bit=data;
      uint8_t var8bit1,var8bit2,var8bit3,var8bit4;

      var8bit1 = var32bit;         // Lower Order byte
      var8bit2 = var32bit >> 8;
      var8bit3 = var32bit >> 16;
      var8bit4 = var32bit >> 24;   // Higher Order Byte

      spi_tx(W_address);
      __delay_cycles (200);
      if(N_OF_Byte==1)
       {
          spi_tx(var8bit1);
          __delay_cycles (200);
       }
      if(N_OF_Byte==2)
       {
          spi_tx(var8bit2);
          __delay_cycles (200);
          spi_tx(var8bit1);
          __delay_cycles (200);
       }

      if(N_OF_Byte==3)
       {
          spi_tx(var8bit3);
          __delay_cycles (200);
          spi_tx(var8bit2);
          __delay_cycles (200);
          spi_tx(var8bit1);
          __delay_cycles (200);
        }

      if(N_OF_Byte==4)
      {
          spi_tx(var8bit4);
          __delay_cycles (200);
          spi_tx(var8bit3);
          __delay_cycles (200);
          spi_tx(var8bit2);
          __delay_cycles (200);
          spi_tx(var8bit1);
          __delay_cycles (200);
      }
}

//*************SPI Receive****************
int spi_rx()
{
   uint8_t Data;
   spi_tx(0x00);            //send dummy data
   __delay_cycles (200);
   // Wait till a character is received
   // while (!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG));
   Data = EUSCI_B0->RXBUF;  // Move data to a temporary buffer
   // Clear the receive interrupt flag
   // EUSCI_B0->IFG &= ~EUSCI_B_IFG_RXIFG;
   return Data;
}

//*****************function to single read internal resister**********//
int ReadRegister(uint8_t R_address,int N_OF_Byte)
{
   /* local variable declaration */
   int var32bit1,var32bit2,var32bit3;
   spi_tx(R_address);
   __delay_cycles (200);
   if(N_OF_Byte==1)
    {
       var32bit1 = spi_rx();
       return var32bit1;
    }
   else if(N_OF_Byte==2)
    {
       var32bit1=spi_rx();          // higher byte
       __delay_cycles (200);
       var32bit2=spi_rx();          // lower byte
       var32bit1=var32bit1<<8;
       var32bit1=var32bit1|var32bit2; // masking into 16 bit data
       return var32bit1 ;
    }

       var32bit1=spi_rx();   //higher byte
       __delay_cycles (200);
       var32bit2=spi_rx();   //middle byte
       __delay_cycles (200);
       var32bit3=spi_rx();   //lower byte
       var32bit1=var32bit1<<8;
       var32bit2=var32bit1|var32bit2;
       var32bit2=var32bit2<<8;
       var32bit3=var32bit2|var32bit3; //masking into 24 bit data
       return var32bit3;

}
//******************Read AD7730 Data*******************//
int ReadData()
{
    /* local variable declaration */
    int var32bit1,var32bit2,var32bit3;
    var32bit1=spi_rx();
    __delay_cycles (200);
    var32bit2=spi_rx();
    __delay_cycles (200);
    var32bit3=spi_rx();
    // data mapping
    var32bit1=var32bit1<<8;
    var32bit2=var32bit1|var32bit2;
    var32bit2=var32bit2<<8;
    var32bit3=var32bit2|var32bit3;
    return var32bit3;
}

void main(void)
{

      STATUS_Result1 = ReadRegister(COM_READ_STATUS_REG_CMD,1);            // read DAC Register default value
        __delay_cycles (2000);
}

  • Hi,

    The schematic looks fine. Please make sure the voltage levels are as expected when measured. I would suggest you to use AD7190 No-OS Generic Driver. Using AD7730 header file wouldnt be exact fit to communicate with AD7190.

    Thanks

    Vikas J

  • #ifndef AD7190_H_
    #define AD7190_H_
    
    /********************COMMUNICATION Register**************************/
    //Read the data register continuously and place the data on DOUT
    #define COMM_REG_CREAD                            0x5C
    
    //Commands to write to specific registers
    #define COM_WRITE_CONFIG_REG_CMD                  0x10
    #define COM_WRITE_MODE_REG_CMD                    0x08
    #define COM_WRITE_GPCON_RED_CMD                   0x28
    
    //Commands to read from specific registers
    #define COM_READ_CONFIG_REG_CMD                   0x50
    #define COM_READ_STATUS_REG_CMD                   0x40
    #define COM_READ_MODE_REG_CMD                     0x48
    #define COM_READ_DATA_REG_CMD                     0x58
    #define COM_READ_GPCON_REG_CMD                    0x68
    #define COM_READ_ID_REG_CMD                       0x60
    #define COM_READ_OFFSET_REG_CMD                   0x70
    #define COM_READ_FULL_SCALE_REG_CMD               0x78
    
    
    /********************Configuration Register**************************/
    #define CONFIG_CHOP_ON                            0x800000
    #define CONFIG_CHOP_OFF                           0x000000
    
    #define CONFIG_REFSEL_IN1P_IN1N                   0x000000
    #define CONFIG_REFSEL_IN2P_IN2N                    0x100000
    
    #define CONFIG_CH_AIN1P_AIN2N                     0x000100
    #define CONFIG_CH_AIN3P_AIN4N                     0x000200
    #define CONFIG_CH_TEMP_SENSOR                     0x000400
    #define CONFIG_CH_AIN2P_AIN2N                     0x000800
    #define CONFIG_CH_AIN1P_AINCOM                    0x001000
    #define CONFIG_CH_AIN2P_AINCOM                    0x002000
    #define CONFIG_CH_AIN3P_AINCOM                    0x004000
    #define CONFIG_CH_AIN4P_AINCOM                    0x008000
    
    #define CONFIG_BURNOUT_ON                         0x000080
    #define CONFIG_BURNOUT_OFF                        0x000000
    
    #define CONFIG_REFDET_ON                          0x000040
    #define CONFIG_REFDET_OFF                         0x000000
    
    #define CONFIG_BUF_ENABLE                         0x000010
    #define CONFIG_BUF_DISABLE                        0x000000
    
    #define CONFIG_UNIPOLAR                           0x000008
    #define CONFIG_BIPOLAR                            0x000000
    
    #define CONFIG_GAIN_1                             0x000000          //±5 V  ADC I/P range
    #define CONFIG_GAIN_8                             0x000003          //±625 mV
    #define CONFIG_GAIN_16                            0x000004          //±312.5 mV
    #define CONFIG_GAIN_32                            0x000005          //±156.2 mV
    #define CONFIG_GAIN_64                            0x000006          //±78.125 mV
    #define CONFIG_GAIN_128                           0x000007          //±39.06 mV
    
    /*****************************MODE REGISTER**************************/
    #define MODE_CONTINUOUS                           0x000000
    #define MODE_SINGLE                               0x200000
    #define MODE_IDLE                                 0x400000
    #define MODE_POWERDOWN                            0x600000
    #define MODE_INTERNAL_ZERO_CALIBRATION            0x800000
    #define MODE_INTERNAL_FULL_CALIBRATION            0xA00000
    #define MODE_SYSTEM_ZERO_CALIBRATION              0xC00000
    #define MODE_SYSTEM_FULL_CALIBRATION              0xE00000
    
    #define MODE_DAT_STA                              0x100000
    
    #define MODE_EXT_CRYSTAL                          0x000000
    #define MODE_EXT_CLOCK                            0x040000
    #define MODE_INTERNAL                             0x080000
    #define MODE_INTERNAL_MCLK2PIN                    0x0C0000
    
    #define MODE_SINC3                                0x008000
    #define MODE_SINC4                                0x000000
    
    #define MODE_PARITY_EN                            0x002000
    #define MODE_PARITY_DS                            0x000000
    
    #define MODE_SINGLE_CONV_EN                       0x000800
    #define MODE_SINGLE_CONV_DS                       0x000000
    
    #define MODE_NOTCH_ON                             0x000400
    #define MODE_NOTCH_OFF                            0x000000
    
    #define FS_100_HZ                                 0x30
    #define FS_1200_HZ                                0x04
    #define FS_960_HZ                                 0x05
    #define FS_2400_HZ                                0x02
    
    
    
    /* Register settings commands for Configuration Register */
    #define CONFIG_REG_CMD_MSB                        0x08
    #define CONFIG_REG_CMD_MID                        0x02
    /*May have to change Gain depending on input signal voltage
    See Table 19 in AD7190 datasheet for more information*/
    #define CONFIG_REG_CMD_LSB                        0x00//0x1F
    /* Register settings commands for Mode Register */
    #define MODE_REG_CMD_MSB                          0x08
    #define MODE_REG_CMD_MID                          0x00
    #define MODE_REG_CMD_LSB                          FS_100_HZ
    
    
    
    ///* Structure Map of AD7190 internal registers
    // * for read and write operations
    // */
    //typedef struct{
    //    unsigned char cmd_rd_status_reg;
    //    unsigned char cmd_wr_mode_reg;
    //    unsigned char cmd_rd_mode_reg;
    //    unsigned char cmd_wr_config_reg;
    //    unsigned char cmd_rd_config_reg;
    //    unsigned char cmd_rd_data_reg;
    //    unsigned char cmd_rd_ID_reg;
    //    unsigned char cmd_rd_gpocon_reg;
    //    unsigned char cmd_wr_gpocon_reg;
    //    unsigned char cmd_rd_offset_reg;
    //    unsigned char cmd_rd_full_scale_reg;
    //}AD7190_REG_T, *AD7190_REG_Ptr;0
    //0
    //
    ///* Enum commands to dump register contents */
    //typedef enum{
    //    DUMP_CONFIG_REG_CONTENTS,
    //    DUMP_MODE_REG_CONTENTS,
    //    DUMP_STATUS_REG_CONTENTS,
    //    DUMP_ID_REG_CONTENTS,
    //    DUMP_CONFIG_AND_MODE_REG_CONTENTS
    //}REG_DumpT;
    //
    ///* AD7190 API's */
    //extern char AD7190_configure(unsigned char cbyte_2, unsigned char cbyte_1, unsigned char cbyte_0);
    //extern char AD7190_mode(unsigned char mbyte_2, unsigned char mbyte_1, unsigned char mbyte_fs);
    //extern unsigned long AD7190_read_data();
    //extern void AD7190_reset();
    //extern unsigned char AD7190_get_ID();
    //extern unsigned char AD7190_read_status_reg();
    //extern void AD7190_dump_regs(REG_DumpT regs_to_dump);
    //extern void init_AD7190_cmds();
    
    #endif /* AD7190_H_ */
    

    Hello,

       I have already attached library related AD7190.c.attached file for ref still unable to read default value.Is there any issue in code that I have attached in previous answer.

    In SPI setup:-

    *SPI clock is high

    *Data is changed on the first UCLK edge and captured on the following edge

  • Hi, 

    We usually don't support custom firmware or codes so If you'd think this is a code issue then we would suggest to use our available No-OS driver so someone from the (+) Q&A - Microcontroller no-OS Drivers - EngineerZone (analog.com) would be able to assist you. 

    We also have this FAQ that would help you check and debug your interface. 

    Digital Interface FAQ - Sigma Delta ADC - Q&A - Precision ADCs - EngineerZone (analog.com) 

    Thanks,

    Jellenie