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.

ADS1256: ADS1256,READING

Part Number: ADS1256

Hello guys,

In my project i am working on ADS1256 with nucleo-STM32F446RE with STMCUBE IDE and for interfacing these i found library in github link https://github.com/majialou/STM32F1-ADS1256-Data-Collect  but i couldn't get any  output from this i stucked in reading DRDY pin, because i havve declared DRDY pin as external interrupt and when i try to initialize the ads1256 its stucked in the drdy pin loop like its not go low its always high.  so i have make connection like this 

MCU                                               ADS1256

(PA5)SCLK          -->                       SCLK

(PA6)MISO          -->                       MISO

(PA7)MOSI          -->                       MOSI

(PB6)CS              -->                       PA4

(PA12)DRDY       -->                       PA2

(PA10)RESET     -->                      PA3

5V                       -->                      5V

3.3V                    -->                      3.3V

GND                   -->                      GND 

(PA11)PDWN     -->                       Not connected to anything 

                           -->                       ANCOM -->AGND  // for single ended //

  and this is the code for initialization of ads1256

<code>

uint8_t ads1256_init(void)
{
	    uint8_t regs_buf[4];
	    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_6, GPIO_PIN_RESET);
	    HAL_NVIC_DisableIRQ(EXTI15_10_IRQn);
	    for(;;){
	        HAL_GPIO_WritePin(GPIOA, REST_Pin|PDWN_Pin, GPIO_PIN_RESET);
	        HAL_Delay(1);
	        HAL_GPIO_WritePin(GPIOA, REST_Pin|PDWN_Pin, GPIO_PIN_SET);
	        HAL_Delay(1);
	        printf("hello sagar1\r\n");
	        printf("status1:%d\r\n",HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	        while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	        printf("hello sagar2\r\n");
	        ads1256_read_regs(0,regs_buf,sizeof(regs_buf));
	        printf("hello sagar3\r\n");
	        if( regs_buf[1]==0x01 && regs_buf[2]==0x20 && regs_buf[3]==0xF0 )
	            printf("break\r\n");
	        	break;
	        HAL_Delay(100);
	    }
	    while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    printf("hello sagar4\r\n");
	    printf("status2:%d\r\n",HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    regs_buf[REG_STATUS]=0xf4;//STATUS REGISTER:Auto-Calibration Enabled,Analog Input Buffer Disabled
	    regs_buf[REG_ADCON]=CLKOUT_OFF+DETECT_OFF+ads125x_conf.gain;   //ADCON=00h
	    regs_buf[REG_DRATE]=ads125x_conf.sampling_rate;
	    ads1256_write_regs(REG_STATUS,regs_buf,sizeof(regs_buf));
	    printf("status3:%d\r\n",HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    while(!HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    printf("status4:%d\r\n",HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    printf("hello sagar5\r\n");
	    while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    ads1256_read_regs(0,regs_buf,sizeof(regs_buf));
	    while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    ads1256_channel_init();
	    ads1256_write_cmd(CMD_SYNC);
	    ads1256_write_cmd(CMD_WAKEUP);
	    printf("hello sagar6\r\n");
	    while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    ads1256_write_cmd(CMD_SELFCAL); //self-calibration
	    while(!HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
	    printf("hello sagar7\r\n");
	    HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

	    return 1;
}
<code>
 

SO i have connected my drdy pin to oscilloscope and pin is always high so what should i do please help me to resolve this 

thank you.

  • Hi sagar m,

    You should generally not leave digital inputs floating e.g. the SYNC/PWDN pin. You do not know what the voltage on this pin will float to, and therefore you cannot be certain of the state of the ADC. If you want to control SYNC using commands as per your code, then I would put a pull-up resistor from SYNC/PWDN to DVDD to ensure this pin is in a known state at powerup.

    If you have the ADC powered correctly, and have supplied a valid clock signal on the CLKIN pin, you should be able to toggle the SYNC pin to start a conversion, which results in a pulse on the DRDY pin. See the "Synchronization" section on page 27 in the datasheet for more information. This is a simple test you can perform that will verify if the ADC is at least working. If you follow the datasheet directions and you still don't see a pulse on DRDY, then the ADC is not powered correctly, the clock signal is not valid, or both.

    Also, those printf() statements can take a long time to execute, which can cause the controller to miss the DRDY interrupt in some cases. You might just store those values in memory/buffer and then print them once the code completes.

    -Bryan

  • Hello Bryan thanks for the reply,

    Connecting SYNC/PDWN pin to 3.3 V is like 

    ADS1256 

    SYNC/PDWN    --> 3.3V

    or

    MCU 

    SYNC/PWDN   --> 3.3 V

    Please confirm this because in ads1256 also we have PDWN/SYNC PIN at P1 so.

    and one more thing like to check the ads12456 working by toggling the SYNC/PDWN pin before starting of the code you can see in my code since i have connected my MCU pin PA11 which is declared as SYNC/PDWN  to 3.3 V i hope its correct after this also nothing change the control still on the while loop it means DRDY is not LOW .  i observed in oscilloscope also but i have doubt in SCLK only in stm32 i have selected for 16MHZ but in ads1256 they have mentioned 7.68MHz even i have tried to set 8MHz also but result will be same .

     so Please let me know if any mistake i would have done .

    Thank You.

  • Hi sagar m,

    In the list of signals you sent, PWDN says "Not connected to anything". So I am not sure how you can toggle this pin if it is not connected to anything. Nor is it clear to me how that could mean anything other than the SYNC/PWDN pin is not connected to anything, and is therefore floating.

    The ADS1256 requires an SCLK period that is 1/4 of the system clock frequency (CLKIN). Since the maximum CLKIN frequency that the ADS1256 can support is 8 MHz, SCLK must be <=2 MHz. If you are running at any SCLK speed greater than this, the ADC will not work.

    Please make sure you have provided a valid CLKIN signal to the ADC, and make sure that the SCLK frequency is <= CLKIN/4.

    -Bryan

  • Hello Bryan,

    So I am not sure how you can toggle this pin if it is not connected to anything. Nor is it clear to me how that could mean anything other than the SYNC/PWDN pin is not connected to anything, and is therefore floating.

    No actual before your suggestion its in float now i have connected it to 3.3 V like

    MCU  

    SYNC/PDWN   --> 3.3 V

    but here i have small doubt in ADS1256 SYNC/PDWN pin is P1 so my MCU configured SYNC/PDWN pin (PA11) is tied to 3.3 V so in ADS1256 can we leave this pin float?? 

    Please make sure you have provided a valid CLKIN signal to the ADC, and make sure that the SCLK frequency is <= CLKIN/4.

    in STM32 output frequency set to 8MHz and i have validate my spi working or not by loop test and its working fine even when i connect ADS1256  and i have sort MISO & MOSI pins and i transferred some data and receive the same at this time i can see my SCLK ticking but when i start ADS1256 initialization by

    1. toggling RESET and PDWN pin 

    2. waiting for the DRDY goes to LOW

    here i am not getting my SCLK pulses its HIGH signal only in logic analyzer

    SO i found problem with SCLK ticking, while waiting for DRDY low pulse  SCLK is HIGH so i couldn't send any command  without making DRDY pin LOW .

    SO any suggestion to solve this problem.

    thank you.

  • Hi sagar m,

    I am confused, how can the SYNC pin be floating if you tied it to 3.3V? Do you have a level translator between the ADC and MCU? Or does the SYNC trace go directly to the MCU?

    I would recommend adding a pull-up on SYNC/PWDN to DVDD at the ADC.

    The SCLK speed needs to be  <= CLKIN/4, so please make sure that you apply an SCLK signal no greater than this. It was not clear to me if you have fixed this issue.

    Also, SCLK should idle low, not high. If SCLK is high and not toggling, then your SPI peripheral is not configured correctly in your MCU.

    -Bryan

  • Hello Bryan sorry for the late reply, and i have tried resetting the RESET and PDWN pin with 200 milli second now DRDY is toggling continuously and i started to read the chip ID from STATUS registers in this way 

    <code>
    uint8_t  ADS1256RREG(uint8_t reg_addr)
    {
    
    		uint8_t wrbuf1;
    		uint8_t wrbuf2;
    		uint8_t final;
    		wrbuf1 = ADS1256_CMD_RREG | reg_addr;
    		wrbuf2 = 0x00;
    		while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
    		HAL_SPI_Transmit(&hspi2,&wrbuf1,1,10);
    		HAL_SPI_Transmit(&hspi2,&wrbuf2,1,10);
    		HAL_SPI_Receive(&hspi2,&final,1,10);
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
    		printf("read_data1:0x%x\r\n",final);
    		return final;
    }
    
    
    
    //ID Verification//
    while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
    uint8_t ID = ADS1256RREG(ADS1256_STATUS);
    printf("ID:0x%x\r\n",ID);
    <code>
     

    so after reading data i got 0x00 only but the value should be 0x34-0x36  then if shift 4 bits right ID should be 3 i have gone through lot of codes even with arduino but still the result was same .

    thank you. 

  • Hi sagar m,

    Can you post logic analyzer plots showing the data transactions during these commands? This will help verify how the ADC is responding as well as timing.

    -Bryan

  • Hello Bryan,

    Thanks for the reply, now chip ID read was some times it reads proper ID like 3 but some times 15, then i have started reading the potentiometer analog value but values are zero's.

    here is the code and logic analyzer image.

    <code>
    //  ads1256.c//
    #include "ads12.h"
    #include "main.h"
    uint32_t sum;
    uint8_t data[3];
    long ulResult;
    long double ldVolutage;
    SPI_HandleTypeDef hspi2;
    int scanMode=0;
    
    void ADS1256WREG(uint8_t regaddr,uint8_t databyte)
    {
    		uint8_t cmd;
    		uint8_t dummy=0x00;
    		while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
    		cmd = ADS1256_CMD_WREG | regaddr;
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
    		HAL_SPI_Transmit(&hspi2, &cmd, 1, 10);
    		HAL_SPI_Transmit(&hspi2, &dummy, 1, 10);
    		HAL_SPI_Transmit(&hspi2, &databyte, 1, 10);
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
    }
    
    uint8_t  ADS1256RREG(uint8_t reg_addr)
    {
    
    		uint8_t wrbuf[2];
    		uint8_t final;
    		wrbuf[0] = ADS1256_CMD_RREG | reg_addr;
    		wrbuf[1] = 0x00;
    		while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
    		HAL_SPI_Transmit(&hspi2,wrbuf,2,1);
    		HAL_Delay(0.00625);
    		HAL_SPI_Receive(&hspi2,&final,1,1);
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
    		return final;
    }
    
    void ConfigADC()
    {
    	uint8_t cmd2 = 0x53;
    	uint8_t cmd3 = 0x00;
    	uint8_t cmd4 = 0x63;
    	HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
    	HAL_SPI_Transmit(&hspi2,&cmd2,1,1);
    	HAL_SPI_Transmit(&hspi2,&cmd3,1,1);
    	HAL_SPI_Transmit(&hspi2,&cmd4,1,1);
    	HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
        HAL_Delay(1);
    
    }
    void ADS1256_Init(void)
    {
    	HAL_NVIC_DisableIRQ(EXTI4_IRQn);
    	HAL_GPIO_WritePin(GPIOA,REST_Pin,GPIO_PIN_RESET);
    	HAL_Delay(200);
    	HAL_GPIO_WritePin(GPIOA,REST_Pin,GPIO_PIN_SET);
    	HAL_Delay(200);
    	uint8_t ID = ADS1256RREG(0);
    	printf("ID:0x%x\r\n",ID);
    	printf("ID:%d\r\n",(ID >>4));
    	ConfigADC();
    	printf("Configuration updated\r\n");
    	HAL_NVIC_EnableIRQ(EXTI4_IRQn);
    
    }
    
    void set_single_channel(uint8_t channel)
    {
      ADS1256WREG(ADS1256_MUX,(channel<<4) | (1<<3));
    }
    void set_diff_channel(uint8_t channel)
    {
    	if(channel == 0)
    	{
    		ADS1256WREG(ADS1256_MUX,(0 << 4) | 1);
    	}
    	else if(channel == 1)
    	{
    		ADS1256WREG(ADS1256_MUX,(2 << 4) | 3);
    	}
    	else if(channel == 2)
    	{
    		ADS1256WREG(ADS1256_MUX,(4 << 4) | 5);
    	}
    	else if(channel == 3)
    	{
    		ADS1256WREG(ADS1256_MUX,(6 << 4) | 7);
    	}
    }
    long double ADS1256ReadData(uint8_t channel)
    {
    
      uint8_t cmd1;
      uint8_t cmd2;
      uint8_t cmd3;
    if(scanMode == 0)
    {
    
    	if (channel > 8)
    	{
    		return 0;
    	}
    	else
    	{
    		//set_single_channel(channel);
    		cmd1 = ADS1256_CMD_SYNC;
    		cmd2 = ADS1256_CMD_WAKEUP;
    		cmd3 = 0x01;
    		uint8_t d=0x00;
    
    
    //		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
    //		HAL_SPI_Transmit(&hspi2, &cmd1, 1, 0.5);
    //		HAL_SPI_Transmit(&hspi2, &cmd2, 1, 0.5);
    //		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
    
    		while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET);
    		HAL_SPI_Transmit(&hspi2,&cmd3,1,0.5);
    		HAL_Delay(0.00683);
    		HAL_SPI_Transmit(&hspi2,&d,1,0.1);
    		HAL_SPI_Receive(&hspi2,&data[0],1,0.1);
    		HAL_SPI_Transmit(&hspi2,&d,1,0.1);
    		HAL_SPI_Receive(&hspi2,&data[1],1,0.1);
    		HAL_SPI_Transmit(&hspi2,&d,1,0.1);
    		HAL_SPI_Receive(&hspi2,&data[2],1,0.1);
    		HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET);
    		sum = (data[0]<<16)|(data[1]<<8) | data[2];
    		if (sum & 0x800000)
    		{
    		    sum &= 0xF000000;
    		}
    
    	ldVolutage = (long double)sum*5.0/0x7FFFFF;
    	printf("single_end_voltage:%.3Lf\r\n",ldVolutage);
    	return ldVolutage;
    
    	}
    }
    else
    {
    	if(channel >=4)
    	{
    		return 0;
    	}
    	else
    	{
    		set_diff_channel(channel);
    		cmd1 = ADS1256_CMD_SYNC;
    		cmd2 = ADS1256_CMD_WAKEUP;
    		cmd3 = ADS1256_CMD_RDATA;
    		HAL_SPI_Transmit(&hspi2, &cmd1, 1, 10);
    		HAL_SPI_Transmit(&hspi2, &cmd2, 1, 100);
    		while(HAL_GPIO_ReadPin(DRDY_GPIO_Port,DRDY_Pin));
    		HAL_SPI_Transmit(&hspi2, &cmd3, 1, 10);
    		HAL_SPI_Receive(&hspi2, data, 3, 10);
    		sum = (data[0]<<16) & 0xff0000;
    		sum |=(data[1]<<8) &  0xff00;
    		sum |=data[2] & 0xff;
    		if (sum & 0x800000)
    		{
    			sum &= 0xF000000;
    		}
    	ldVolutage = (long double)sum*5.0/0x7FFFFF;
    	printf("diff_voltage:%.3Lf\r\n",ldVolutage);
    	return ldVolutage;
    
    	 }
     }
    }
    <code>
    
    //ads1256.h//
    <code>
    #include "main.h"
    #include "stdio.h"
    extern SPI_HandleTypeDef hspi2;
    
    
    #ifndef __ADS1256_H_
    #define __ADS1256_H_
    
    #define ADS1256_CMD_WAKEUP 0xFF
    #define ADS1256_CMD_RDATA  0x01
    #define ADS1256_CMD_RDATAC 0x03
    #define buffer_en 1
    //#define ADS1256_CMD_SDATAC 0x0F
    #define ADS1256_CMD_RREG 0x10
    #define ADS1256_CMD_WREG 0x50
    #define ADS1256_CMD_SELFCAL 0xf0
    #define ADS1256_CMD_SELFOCAL 0xf1
    #define ADS1256_CMD_SELFGCAL 0xf2
    #define ADS1256_CMD_SYSOCAL 0xf3
    #define ADS1256_CMD_SYSGCAL 0xf4
    #define ADS1256_CMD_SYNC   0xFC
    #define ADS1256_CMD_STANDBY 0xfd
    //#define ADS1256_CMD_REST 0xFE
    
    
    
    // define the ADS1256 register values
    #define ADS1256_STATUS 0x00
    #define ADS1256_MUX 0x01
    #define ADS1256_ADCON 0x02
    #define ADS1256_DRATE 0x03
    #define ADS1256_IO 0x04
    #define ADS1256_OFC0 0x05
    #define ADS1256_OFC1 0x06
    #define ADS1256_OFC2 0x07
    #define ADS1256_FSC0 0x08
    #define ADS1256_FSC1 0x09
    #define ADS1256_FSC2 0x0A
    
    // define multiplexer codes
    #define ADS1256_MUXP_AIN0 0x00
    #define ADS1256_MUXP_AIN1 0x10
    #define ADS1256_MUXP_AIN2 0x20
    #define ADS1256_MUXP_AIN3 0x30
    #define ADS1256_MUXP_AIN4 0x40
    #define ADS1256_MUXP_AIN5 0x50
    #define ADS1256_MUXP_AIN6 0x60
    #define ADS1256_MUXP_AIN7 0x70
    #define ADS1256_MUXP_AINCOM 0x80
    
    #define ADS1256_MUXN_AIN0 0x00
    #define ADS1256_MUXN_AIN1 0x01
    #define ADS1256_MUXN_AIN2 0x02
    #define ADS1256_MUXN_AIN3 0x03
    #define ADS1256_MUXN_AIN4 0x04
    #define ADS1256_MUXN_AIN5 0x05
    #define ADS1256_MUXN_AIN6 0x06
    #define ADS1256_MUXN_AIN7 0x07
    #define ADS1256_MUXN_AINCOM 0x08
    
    // define gain codes
    #define ADS1256_GAIN_1 0x00
    #define ADS1256_GAIN_2 0x01
    #define ADS1256_GAIN_4 0x02
    #define ADS1256_GAIN_8 0x03
    #define ADS1256_GAIN_16 0x04
    #define ADS1256_GAIN_32 0x05
    #define ADS1256_GAIN_64 0x06
    //#define ADS1256_GAIN_64 0x07
    
    // define drate codes
    #define ADS1256_DRATE_30000SPS 0xF0
    #define ADS1256_DRATE_15000SPS 0xE0
    #define ADS1256_DRATE_7500SPS 0xD0
    #define ADS1256_DRATE_3750SPS 0xC0
    #define ADS1256_DRATE_2000SPS 0xB0
    #define ADS1256_DRATE_1000SPS 0xA1
    #define ADS1256_DRATE_500SPS 0x92
    #define ADS1256_DRATE_100SPS 0x82
    #define ADS1256_DRATE_60SPS 0x72
    #define ADS1256_DRATE_50SPS 0x63
    #define ADS1256_DRATE_30SPS 0x53
    #define ADS1256_DRATE_25SPS 0x43
    #define ADS1256_DRATE_15SPS 0x33
    #define ADS1256_DRATE_10SPS 0x23
    #define ADS1256_DRATE_5SPS 0x13
    #define ADS1256_DRATE_2_5SPS 0x03
    
    long double ADS1256ReadData(uint8_t channel);
    void ADS1256_Init(void);
    
    #endif
    <code>
    
    //main.c//
    /* USER CODE BEGIN Header */
    /**
      ******************************************************************************
      * @file           : main.c
      * @brief          : Main program body
      ******************************************************************************
      * @attention
      *
      * Copyright (c) 2022 STMicroelectronics.
      * All rights reserved.
      *
      * This software is licensed under terms that can be found in the LICENSE file
      * in the root directory of this software component.
      * If no LICENSE file comes with this software, it is provided AS-IS.
      *
      ******************************************************************************
      */
    /* USER CODE END Header */
    /* Includes ------------------------------------------------------------------*/
    #include "main.h"
    #include "stdio.h"
    #include "string.h"
    #include "retarget.h"
    #include "ads12.h"
    /* Private includes ----------------------------------------------------------*/
    /* USER CODE BEGIN Includes */
    
    /* USER CODE END Includes */
    
    /* Private typedef -----------------------------------------------------------*/
    /* USER CODE BEGIN PTD */
    
    /* USER CODE END PTD */
    
    /* Private define ------------------------------------------------------------*/
    /* USER CODE BEGIN PD */
    /* USER CODE END PD */
    
    /* Private macro -------------------------------------------------------------*/
    /* USER CODE BEGIN PM */
    
    /* USER CODE END PM */
    
    /* Private variables ---------------------------------------------------------*/
    
    
    UART_HandleTypeDef huart5;
    UART_HandleTypeDef huart2;
    
    /* USER CODE BEGIN PV */
    
    /* USER CODE END PV */
    
    /* Private function prototypes -----------------------------------------------*/
    void SystemClock_Config(void);
    static void MX_GPIO_Init(void);
    static void MX_USART2_UART_Init(void);
    static void MX_SPI2_Init(void);
    static void MX_UART5_Init(void);
    /* USER CODE BEGIN PFP */
    
    /* USER CODE END PFP */
    
    /* Private user code ---------------------------------------------------------*/
    /* USER CODE BEGIN 0 */
    
    /* USER CODE END 0 */
    
    /**
      * @brief  The application entry point.
      * @retval int
      */
    static uint8_t is_adc_drdy;
    long double AD_value0;
    long double AD_value1;
    long double AD_value2;
    long double AD_value3;
    long double AD_value4;
    long double AD_value5;
    long double AD_value6;
    long double AD_value7;
    int main(void)
    {
      /* USER CODE BEGIN 1 */
    
      /* USER CODE END 1 */
    
      /* MCU Configuration--------------------------------------------------------*/
    
      /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
      HAL_Init();
    
      /* USER CODE BEGIN Init */
    
      /* USER CODE END Init */
    
      /* Configure the system clock */
      SystemClock_Config();
    
      /* USER CODE BEGIN SysInit */
    
      /* USER CODE END SysInit */
    
      /* Initialize all configured peripherals */
      MX_GPIO_Init();
      MX_USART2_UART_Init();
      MX_SPI2_Init();
      MX_UART5_Init();
      RetargetInit(&huart5);
      ADS1256_Init();
      /* USER CODE BEGIN 2 */
    
      /* USER CODE END 2 */
    
      /* Infinite loop */
      /* USER CODE BEGIN WHILE */
      while (1)
      {
        /* USER CODE END WHILE */
    	  if(is_adc_drdy==1)
    	  {
    	   AD_value0 = ADS1256ReadData(0);
    	  }
        /* USER CODE BEGIN 3 */
      }
      /* USER CODE END 3 */
    }
    
    /**
      * @brief System Clock Configuration
      * @retval None
      */
    void SystemClock_Config(void)
    {
      RCC_OscInitTypeDef RCC_OscInitStruct = {0};
      RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
    
      /** Configure the main internal regulator output voltage
      */
      __HAL_RCC_PWR_CLK_ENABLE();
      __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
    
      /** Initializes the RCC Oscillators according to the specified parameters
      * in the RCC_OscInitTypeDef structure.
      */
      RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
      RCC_OscInitStruct.HSIState = RCC_HSI_ON;
      RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
      RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
      RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
      RCC_OscInitStruct.PLL.PLLM = 8;
      RCC_OscInitStruct.PLL.PLLN = 64;
      RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
      RCC_OscInitStruct.PLL.PLLQ = 2;
      RCC_OscInitStruct.PLL.PLLR = 2;
      if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
      {
        Error_Handler();
      }
    
      /** Initializes the CPU, AHB and APB buses clocks
      */
      RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                                  |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
      RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
      RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV4;
      RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
      RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    
      if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
      {
        Error_Handler();
      }
    }
    
    /**
      * @brief SPI2 Initialization Function
      * @param None
      * @retval None
      */
    static void MX_SPI2_Init(void)
    {
    
      /* USER CODE BEGIN SPI2_Init 0 */
    
      /* USER CODE END SPI2_Init 0 */
    
      /* USER CODE BEGIN SPI2_Init 1 */
    
      /* USER CODE END SPI2_Init 1 */
      /* SPI2 parameter configuration*/
      hspi2.Instance = SPI2;
      hspi2.Init.Mode = SPI_MODE_MASTER;
      hspi2.Init.Direction = SPI_DIRECTION_2LINES;
      hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
      hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
      hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
      hspi2.Init.NSS = SPI_NSS_SOFT;
      hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
      hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
      hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
      hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
      hspi2.Init.CRCPolynomial = 10;
      if (HAL_SPI_Init(&hspi2) != HAL_OK)
      {
        Error_Handler();
      }
      /* USER CODE BEGIN SPI2_Init 2 */
    
      /* USER CODE END SPI2_Init 2 */
    
    }
    
    /**
      * @brief UART5 Initialization Function
      * @param None
      * @retval None
      */
    static void MX_UART5_Init(void)
    {
    
      /* USER CODE BEGIN UART5_Init 0 */
    
      /* USER CODE END UART5_Init 0 */
    
      /* USER CODE BEGIN UART5_Init 1 */
    
      /* USER CODE END UART5_Init 1 */
      huart5.Instance = UART5;
      huart5.Init.BaudRate = 115200;
      huart5.Init.WordLength = UART_WORDLENGTH_8B;
      huart5.Init.StopBits = UART_STOPBITS_1;
      huart5.Init.Parity = UART_PARITY_NONE;
      huart5.Init.Mode = UART_MODE_TX_RX;
      huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
      huart5.Init.OverSampling = UART_OVERSAMPLING_16;
      if (HAL_UART_Init(&huart5) != HAL_OK)
      {
        Error_Handler();
      }
      /* USER CODE BEGIN UART5_Init 2 */
    
      /* USER CODE END UART5_Init 2 */
    
    }
    
    /**
      * @brief USART2 Initialization Function
      * @param None
      * @retval None
      */
    static void MX_USART2_UART_Init(void)
    {
    
      /* USER CODE BEGIN USART2_Init 0 */
    
      /* USER CODE END USART2_Init 0 */
    
      /* USER CODE BEGIN USART2_Init 1 */
    
      /* USER CODE END USART2_Init 1 */
      huart2.Instance = USART2;
      huart2.Init.BaudRate = 115200;
      huart2.Init.WordLength = UART_WORDLENGTH_8B;
      huart2.Init.StopBits = UART_STOPBITS_1;
      huart2.Init.Parity = UART_PARITY_NONE;
      huart2.Init.Mode = UART_MODE_TX_RX;
      huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
      huart2.Init.OverSampling = UART_OVERSAMPLING_16;
      if (HAL_UART_Init(&huart2) != HAL_OK)
      {
        Error_Handler();
      }
      /* USER CODE BEGIN USART2_Init 2 */
    
      /* USER CODE END USART2_Init 2 */
    
    }
    
    /**
      * @brief GPIO Initialization Function
      * @param None
      * @retval None
      */
    static void MX_GPIO_Init(void)
    {
      GPIO_InitTypeDef GPIO_InitStruct = {0};
    
      /* GPIO Ports Clock Enable */
      __HAL_RCC_GPIOC_CLK_ENABLE();
      __HAL_RCC_GPIOH_CLK_ENABLE();
      __HAL_RCC_GPIOA_CLK_ENABLE();
      __HAL_RCC_GPIOB_CLK_ENABLE();
      __HAL_RCC_GPIOD_CLK_ENABLE();
    
      /*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(REST_GPIO_Port, REST_Pin, GPIO_PIN_RESET);
    
      /*Configure GPIO pin Output Level */
      HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, GPIO_PIN_RESET);
    
      /*Configure GPIO pin : B1_Pin */
      GPIO_InitStruct.Pin = B1_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
    
      /*Configure GPIO pin : DRDY_Pin */
      GPIO_InitStruct.Pin = DRDY_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      HAL_GPIO_Init(DRDY_GPIO_Port, &GPIO_InitStruct);
    
      /*Configure GPIO pin : REST_Pin */
      GPIO_InitStruct.Pin = REST_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      HAL_GPIO_Init(REST_GPIO_Port, &GPIO_InitStruct);
    
      /*Configure GPIO pin : CS_Pin */
      GPIO_InitStruct.Pin = CS_Pin;
      GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
      GPIO_InitStruct.Pull = GPIO_NOPULL;
      GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
      HAL_GPIO_Init(CS_GPIO_Port, &GPIO_InitStruct);
    
      /* EXTI interrupt init*/
      HAL_NVIC_SetPriority(EXTI4_IRQn, 0, 0);
      HAL_NVIC_EnableIRQ(EXTI4_IRQn);
    
    }
    void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
    {
        if( GPIO_Pin == DRDY_Pin )
        {
            is_adc_drdy = 1;
        }
    }
    /* USER CODE BEGIN 4 */
    
    /* USER CODE END 4 */
    
    /**
      * @brief  This function is executed in case of error occurrence.
      * @retval None
      */
    void Error_Handler(void)
    {
      /* USER CODE BEGIN Error_Handler_Debug */
      /* User can add his own implementation to report the HAL error return state */
      __disable_irq();
      while (1)
      {
      }
      /* USER CODE END Error_Handler_Debug */
    }
    
    #ifdef  USE_FULL_ASSERT
    /**
      * @brief  Reports the name of the source file and the source line number
      *         where the assert_param error has occurred.
      * @param  file: pointer to the source file name
      * @param  line: assert_param error line source number
      * @retval None
      */
    void assert_failed(uint8_t *file, uint32_t line)
    {
      /* USER CODE BEGIN 6 */
      /* User can add his own implementation to report the file name and line number,
         ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
      /* USER CODE END 6 */
    }
    #endif /* USE_FULL_ASSERT */
    <code>
    
    
    

    image   of logic analyzer

    i have gone through the datasheet and for reading a chip with time 6.5 micro sec same i have used but still some times giving me 15,

    and data reading is also zero.

    i  have lot of doubt's in delay time so please help to resolve this.

    thank you.

  • Hi sagar m,

    What command are you trying to send in the logic analyzer plot? There are about 40 SCLK pulses in that image but it looks like you are sending either all 0s or all 1s on MOSI. This is just multiple WAKEUP commands.

    SCLK should trigger on the falling edge for the ADS1256, as described in the "DIN and DOUT" section of the datasheet. The correct settings for the Saleae logic analyzer are shown below.

    Also, your SCLK speed appears to be way too slow. You need to be able to send the RDATA command and clock out data before the next DRDY pulse. I only count 3-4 SCLK pulses between DRDY pulses, so you either need to speed up SCLK or slow down the ADC data rate. Otherwise you are going to get corrupted data.

    If you want to fix some of these issues and send me more logic analyzer data, you can just send the .sal files so I can review the entire communication, as opposed to sending screenshots.

    -Bryan

  • Hello bryan,

    To increase the clock speed i decreased the pre scalar in configuration and now delay for each cycle is reduced to nano sec but still i don't know how to make DRDY low until my whole transmission/reception complete.??

     also i configured in saleae logic analyzer CPOL =0 and CPHS =1 and DRDY signal as a enabling signal but the data was measurement was wrong but if i configured CPOL =0 and  CPHS =0 then its measure  properly so what was the problem.??

    i am trying to get the .saleae files  but there is no option for .saleae files so can i send each transmission screenshot .??

    the major doubt i had was how we can calculate the delay for correct  transmission/reception like in stm32 we have HAL_SIP_Transmit(&hspi1,write_data_buf,size(write_data_buf), delay) function so for transmission also we need to provide delay as well as we need to maintain the exact delay for reading /writing in ADS1256 so how can we do that.?/

  • Hi sagar m,

    The ADC controls the DRDY signal, not the controller. The DRDY drops low when new data is ready from the ADC. The DRDY pin will pulse at an interval that is approximately equal to 1/DR. So if DR = 30 kSPS, then the DRDY pulse interval will be ~33us assuming you are continuously converting. Therefore, you need to ensure that your SCLK speed is sufficiently fast to be able to clock out data within this interval. If you are supplying a 7.68 MHz system clock to the ADC, I would recommend using a 1.92 MHz SCLK. If you want to sample at <30kSPS, it is possible for SCLK to be <1.92 MHz

    Thanks for the reply, now chip ID read was some times it reads proper ID like 3 but some times 15, then i have started reading the potentiometer analog value but values are zero's.

    You said in this previous post that you were not able to read registers properly, which seemed like an issue with the way the Saleae was set up. But now you are able to read registers and get data correctly using CPOL = 0 and CPHA = 0? I am confused as to what the actual issue is then

    i am trying to get the .saleae files  but there is no option for .saleae files so can i send each transmission screenshot .??

    You should be able to save a capture as shown below

    the major doubt i had was how we can calculate the delay for correct  transmission/reception like in stm32 we have HAL_SIP_Transmit(&hspi1,write_data_buf,size(write_data_buf), delay) function so for transmission also we need to provide delay as well as we need to maintain the exact delay for reading /writing in ADS1256 so how can we do that.?/

    I am not sure what this question is asking? Do you need help setting up the delays in your controller? If so, that would be a question for ST. The delays required for correct communication with the ADS1256 are shown on pages 6 and 7 in the ADC datasheet. Specifically, make sure the delays between commands (t11) and DIN to DOUT (t6) are respected. Again, you will have to program these delays in your firmware, and if you need help with writing firmware you will need to contact the MCU manufacturer.

    -Bryan