This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

The code program of control register for ADS795XEVM

Other Parts Discussed in Thread: ADS7952

Could anyone help to provide The code program of control register for ADS795XEVM?

I'm not clear how to configurate Mode Control Register.

Thanks.

  • Walsh,

     

    The value to be written to the Mode Control Register would depend on the mode in which you intend to operate the device.

    Which of the 3 modes do you plan on using? Do you intend to change the Input range or use any of the GPIOs?

     

    Regards,

    Sandeep

     

     

  • Dear Sandeep:

    We have choosen the ADS7952 and want to use Auto-2 mode.

    We need to use all of 12 channels and GPIO.

    Walsh
  • Walsh,

    Sorry for this delay in responding.

    In case you plan on using all 12 channels of the ADS7952, either Auto-1 or Auto-2 modes may be used. The steps below should get you into the configuration you plan on using:

    1. Configure the GPIO as per Table 10 (since you mentioned GPIO and not GPIOs in your mail, I am assuming you are working with the QFN package which supports only GPIO0)

    First SDI frame: 0100_0000_0000_0001 - This assumes that GPIO0 is used as an output. Modify DIO0=0 incase you plan to use this as an input.

    2. Configure the Auto-2 register to ensure all channels are sampled, as per Table 6.

    Second frame: 1001_0010_1100_0000 - This is to ensure that the channel selection rolls back to CH0 only after CH11

    3. Configure the Mode Control Register to select Auto-2 mode as per Table 5.

    Third frame: 0011_1100_0001_0001 - This assumes that you are using Range 1 and that you need GPIO0 is driven high.

    4. Remain the Auto-2 mode

    All subsequent frames: 0000_0000_0000_0000

    Please note that, as described in Fig 53, that the data for the first channel (Ch0) comes two frames after entering the selected mode. This previous post for another device from the same family explain this in detail: https://e2e.ti.com/support/data_converters/precision_data_converters/f/73/t/307340

    Regards,

    Sandeep

  • SPI waveform when ADS7952 configurate.rarDear Sandeep:

    Thanks for the reply. It's useful to us.

    After we configurate the ADS7952, we couldn't read the date. Could you help to check if there is error in the code?

    Thanks,

    Walsh

  • ads7952_driver.c
    #include "stm32f4xx.h"
    #include "ads7952_driver.h"
    
    #define SPIx                               SPI4
    #define SPIx_CLK                       RCC_APB2Periph_SPI4
    
    #define SPIx_SCK_GPIO_CLK     RCC_AHB1Periph_GPIOE
    #define SPIx_CS_GPIO_CLK       RCC_AHB1Periph_GPIOE
    #define SPIx_MOSI_GPIO_CLK   RCC_AHB1Periph_GPIOE
    #define SPIx_MISO_GPIO_CLK   RCC_AHB1Periph_GPIOE
    
    #define SPIx_SCK_GPIO_PORT      GPIOE
    #define SPIx_CS_GPIO_PORT        GPIOE
    #define SPIx_MOSI_GPIO_PORT    GPIOE
    #define SPIx_MISO_GPIO_PORT    GPIOE
    
    #define SPIx_SCK_GPIO_PIN       GPIO_Pin_2
    #define SPIx_CS_GPIO_PIN         GPIO_Pin_4
    #define SPIx_MOSI_GPIO_PIN     GPIO_Pin_6
    #define SPIx_MISO_GPIO_PIN     GPIO_Pin_5
    
    #define SPI_SCK_SOURCE             GPIO_PinSource2
    #define SPI_MISO_SOURCE           GPIO_PinSource5
    #define SPI_MOSI_SOURCE           GPIO_PinSource6
    
    #define CS_HIGH()         do{GPIOE->BSRRL =SPIx_CS_GPIO_PIN;}while(0)
    #define CS_LOW()          do{GPIOE->BSRRH =SPIx_CS_GPIO_PIN;}while(0)
    
    
    
    #define  RESETCMD              0x4000
    
    #define  ManualMode            0x1080//  manual mode    channel -1
    #define  AutoMode_1		   0x2C00
    //#define  AutoMode_2            0x3800                     ////////
    #define  AutoMode_2            0x3C00                     ////////
    
    #define ProgramReg_Auto1FRAME1   0x8000
    #define ProgramReg_Auto1FRAME2   0x0FFF
    
    #define ProgramReg_Auto2   0x92C0   //CH00---CH11
    
    #define ContinuedSelecMode  0x00  //ignores data on DI11--DI00
    
    #define BUFFERSIZE 100
    
    uint8_t RxIndex=0;
    uint8_t TxIndex=0;
    
    uint8_t TxSize=0;
    uint8_t RxSize=0;
    
    uint8_t RxBuffer[BUFFERSIZE];
    uint8_t TxBuffer[BUFFERSIZE];
    
    u8 SPIx_ReadWriteByte(uint16_t value)
    {
    	while(SPI_I2S_GetFlagStatus(SPIx,SPI_I2S_FLAG_TXE) == RESET);
    	SPI_I2S_SendData(SPIx,value);
    
    	while(SPI_I2S_GetFlagStatus(SPIx,SPI_I2S_FLAG_RXNE) ==RESET);
    
    	return SPI_I2S_ReceiveData(SPIx);	
    }
    
    int ads7952_open(Driver *driver)
    {
    	GPIO_InitTypeDef GPIO_InitStructure;
    	SPI_InitTypeDef SPI_InitStructure;
    
    	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE,ENABLE);
    	RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI4,ENABLE);
    
    	GPIO_InitStructure.GPIO_Pin = SPIx_MISO_GPIO_PIN;
    	GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;
    	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    	GPIO_Init(SPIx_MISO_GPIO_PORT, &GPIO_InitStructure); 
    
    	GPIO_InitStructure.GPIO_Pin = SPIx_SCK_GPIO_PIN;
    	GPIO_Init(SPIx_SCK_GPIO_PORT,&GPIO_InitStructure);
    
    	GPIO_InitStructure.GPIO_Pin = SPIx_MOSI_GPIO_PIN;
    	GPIO_Init(SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure);  
    
    	GPIO_InitStructure.GPIO_Pin = SPIx_CS_GPIO_PIN;
    	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    	GPIO_Init(SPIx_CS_GPIO_PORT, &GPIO_InitStructure);
    
    	GPIO_PinAFConfig(SPIx_SCK_GPIO_PORT, SPI_SCK_SOURCE, GPIO_AF_SPI4);
    	GPIO_PinAFConfig(SPIx_MISO_GPIO_PORT, SPI_MISO_SOURCE, GPIO_AF_SPI4);
    	GPIO_PinAFConfig(SPIx_MOSI_GPIO_PORT, SPI_MOSI_SOURCE, GPIO_AF_SPI4);
    
    	SPI_I2S_DeInit(SPIx);
    
    	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    	SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
    	SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
    	SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
    	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
    	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    	SPI_InitStructure.SPI_CRCPolynomial = 7;
    	SPI_Init(SPIx,&SPI_InitStructure);
    	SPI_Cmd(SPIx,ENABLE);
    
    	return 0;
    }
    
    int ads7952_write(Driver *driver,void *buffer,int len,OFFSET offset1)
    { 
    	 return 0;
    }
    
    int ads7952_read(Driver *driver,void *buffer,int len,OFFSET offset1)
    {
        uint16_t *pbuff;
        uint16_t rxBuff[12];
        uint16_t ret1,ret2,ret3,ret4;
        
        ret1=0;
        ret2=0;
        ret3=0;
        ret4=0;
    #if 1
        CS_LOW() ;
        ret1= SPIx_ReadWriteByte(RESETCMD);
        
        CS_HIGH();
        
        CS_LOW();    
        ret2= SPIx_ReadWriteByte(ProgramReg_Auto2 ); 
        CS_HIGH();
        
        CS_LOW();    
        ret3= SPIx_ReadWriteByte(AutoMode_2);
        CS_HIGH();
        
        CS_LOW();   
        SPIx_ReadWriteByte(ContinuedSelecMode);
        CS_HIGH();
        
        pbuff=buffer;
        CS_LOW();	
        ret4= SPIx_ReadWriteByte(0xffff);//  first ignore 
        CS_HIGH();
        
        CS_LOW();       
        for(int i=0;i<12;i++)
        {
           *pbuff++ = SPIx_ReadWriteByte(0xffff)&0x0fff;  
        }
    
        CS_HIGH();
    //    memcpy(buffer,rxBuff,sizeof(rxBuff));
    #endif
        return 0;
    }
    
    int ads7952_ioControl(Driver *driver,int io_type,int data)
    {
     	 return 0;
    }
    
    int ads7952_close(Driver *driver)
    {
    	GPIO_InitTypeDef GPIO_InitStructure;
    
    	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4| GPIO_Pin_5 |GPIO_Pin_6;
    	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
    	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    	GPIO_Init(GPIOE,&GPIO_InitStructure);
    
    	SPI_I2S_DeInit(SPIx);
    
    	return 0;
    }
    
    Driver ads7952_driver =
    {
    	ads7952_open,
    	ads7952_write,
    	ads7952_read,
    	ads7952_ioControl,
    	ads7952_close
    };
    
    
    
    
    
    
    
    
    
    

  • Walsh,


    At a high level, the code seems to be fine.

    Before drilling down to each function, it would really help if we could observe the interface signals - CS, SCLK, SDI and SDO during a read and write transaction on a oscilloscope or logic analyzer, to look for potential sources of the error.

    Thanks.

    Regards,

    Sandeep

  • Dear Sandeep:

    Got it. Thanks

    Walsh
  • While Accessing the ads7952 driver.h code, I can't able to access the driver.h file. can you please provide me the source code file for driver.h .
    Thanks in Advance.

    Regards
    Saravanan
  • Hi Saravanan,

    Could you please highlight which software package are you referring to?

    Regards,
    Rahul
  • Hi Rahul,

    I am using Kinetis Design Sudio and using ADs7952 ADC, in that I could not able to find the Register address bits. Can you help in this ??

    Thanks in Advance

    Regards,
    Saravanan
  • Hi Saravaran,

    If I understood it right, here the IDE particular to digital host is the concern.
    I am not sure about the environment the IDE offers.

    You may refer to datasheet and access the registers using standard SPI module of the digital host.

    Regards,
    Rahul