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.

ADS1232ref Board

Other Parts Discussed in Thread: ADS1232REF, ADS1232

Hello,

I am developing a project on weigh scale application using ADS1232. I bought a reference design board to work on it. ADS1232ref Board. Now my problem is that I would like to take the signals from ADS1232 digital output signals and interface my prefered controller for communicating using SPI. I am unable to follow the code that TI has given in there ftp server. 

ftp://ftp.ti.com/pub/data_acquisition/ADS123xREF/ADS123x_CDROM/Firmware/Firmware_Source_Code/

 But Here in the ADs1232.c and headerfiles Iam unable to follow the way to interface Using SPI could you please provide me a small quick start for this application program.

  • Hi Sandeep,

    Welcome to the forum!  Your request is a little difficult to answer as the code author no longer works for TI, and the code itself uses freeRTOS which complicates any explanation.  Keep in mind that this code is not example code, but rather project code used for a specific purpose.

    All operational control for the ADS1232 as far as setting the data rate, mux, and PGA is done through pin control using the microcontroller GPIO.  Early in the ADS1232.c file are macros that define which pins control the designated functions.  The init function also sets the SPI peripheral and clock speeds.  There is no need to follow the same conventions.  All you need to do is decide which GPIO on your controller are connected to the various ADS1232 pins and set the GPIO to the appropriate states.

    When DOUT/DRDY falls from high to low signaling an end of conversion period, there is a designated interrupt request function that is called to read the data.  If an offset calibration is desired, additional SCLKS are sent to initiate the calibration.  The calibration is basically turning off the normal SPI SCLK and bit-banging 2 more clocks as a GPIO, then setting the pin back to the SPI SCLK peripheral.

    That is pretty much all there is to know.  This is a very simple pin controlled device that only requires reading the data as far as the communication is concerned.

    Best regards,

    Bob B

  • Hello Benjamin,

    Thank for your suggestions and i was able to capture the signal rising and falling edge using GPIO_ External Event Occurance. I have one question regarding the ADS1232 that when i measure the timing of SCK signal for every 8 bits of transfer there is ~2 usec delay for the next 8 bits is my assumption true or false but as per data sheet there is no data regarding this. I had worked as per your suggestion but could not trace the output data. Could you please go through my code and i need to know how to accquire this 24 bits .

    /**
    ******************************************************************************
    * File Name : main.c
    * Description : Main program body
    ******************************************************************************
    *
    * COPYRIGHT(c) 2016 STMicroelectronics
    *
    * Redistribution and use in source and binary forms, with or without modification,
    * are permitted provided that the following conditions are met:
    * 1. Redistributions of source code must retain the above copyright notice,
    * this list of conditions and the following disclaimer.
    * 2. Redistributions in binary form must reproduce the above copyright notice,
    * this list of conditions and the following disclaimer in the documentation
    * and/or other materials provided with the distribution.
    * 3. Neither the name of STMicroelectronics nor the names of its contributors
    * may be used to endorse or promote products derived from this software
    * without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
    * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
    * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    ******************************************************************************
    */
    /* Includes ------------------------------------------------------------------*/
    #include "stm32l0xx_hal.h"

    /* USER CODE BEGIN Includes */

    /* USER CODE END Includes */

    /* Private variables ---------------------------------------------------------*/
    UART_HandleTypeDef huart2;
    int32_t buffer;

    /* USER CODE BEGIN PV */
    /* Private variables ---------------------------------------------------------*/

    union ADS1232 {
    char dataready_flag;
    char ClockOut_flag;
    } ADS1232_flag;

    /* USER CODE END PV */

    /* Private function prototypes -----------------------------------------------*/
    void SystemClock_Config(void);
    static void MX_GPIO_Init(void);
    static void MX_USART2_UART_Init(void);

    /* USER CODE BEGIN PFP */
    /* Private function prototypes -----------------------------------------------*/

    /* USER CODE END PFP */

    /* USER CODE BEGIN 0 */

    /* USER CODE END 0 */

    int main(void)
    {

    char mask_bit = 0x01;
    /* USER CODE BEGIN 1 */

    /* USER CODE END 1 */

    /* MCU Configuration----------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* Configure the system clock */
    SystemClock_Config();

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_USART2_UART_Init();

    /* USER CODE BEGIN 2 */

    // HAL_GPIO_EXTI_IRQHandler(Data_out_Pin);

    /* USER CODE END 2 */

    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    while (1)
    {
    /* USER CODE END WHILE */
    if(ADS1232_flag.dataready_flag && ADS1232_flag.ClockOut_flag )
    {
    ADS1232_flag.dataready_flag = 0;
    ADS1232_flag.ClockOut_flag = 0;
    for(char cnt = 0; cnt < 24; cnt++)
    {
    if (HAL_GPIO_ReadPin(Data_Out_GPIO_Port, Data_Out_Pin))
    {
    buffer = (mask_bit & 0x01) << 1;
    }
    else
    buffer = (mask_bit & 0x00) << 1;
    }
    HAL_UART_Transmit(&huart2, (uint8_t *) buffer, sizeof(buffer), 5000);

    }

    /* USER CODE BEGIN 3 */
    /* USER CODE END 3 */
    }

    }

    /** System Clock Configuration
    */
    void SystemClock_Config(void)
    {

    RCC_OscInitTypeDef RCC_OscInitStruct;
    RCC_ClkInitTypeDef RCC_ClkInitStruct;
    RCC_PeriphCLKInitTypeDef PeriphClkInit;

    __HAL_RCC_PWR_CLK_ENABLE();

    __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
    RCC_OscInitStruct.MSIState = RCC_MSI_ON;
    RCC_OscInitStruct.MSICalibrationValue = 0;
    RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
    RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);

    RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
    |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
    RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
    RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
    RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
    RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
    HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);

    PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;
    PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

    /* SysTick_IRQn interrupt configuration */
    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
    }

    /* USART2 init function */
    void MX_USART2_UART_Init(void)
    {

    huart2.Instance = USART2;
    huart2.Init.BaudRate = 115200;
    huart2.Init.WordLength = UART_WORDLENGTH_7B;
    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;
    huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
    huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
    HAL_UART_Init(&huart2);

    }

    /** Configure pins as
    * Analog
    * Input
    * Output
    * EVENT_OUT
    * EXTI
    */
    void MX_GPIO_Init(void)
    {

    GPIO_InitTypeDef GPIO_InitStruct;

    /* GPIO Ports Clock Enable */
    __HAL_RCC_GPIOC_CLK_ENABLE();
    __HAL_RCC_GPIOH_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();

    /*Configure GPIO pin : B1_Pin */
    GPIO_InitStruct.Pin = B1_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_EVT_RISING;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);

    /*Configure GPIO pin : Data_Out_Pin */
    GPIO_InitStruct.Pin = Data_Out_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(Data_Out_GPIO_Port, &GPIO_InitStruct);

    /*Configure GPIO pin : Clk_out_Pin */
    GPIO_InitStruct.Pin = Clk_out_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    HAL_GPIO_Init(Clk_out_GPIO_Port, &GPIO_InitStruct);

    /*Configure GPIO pin : LD2_Pin */
    GPIO_InitStruct.Pin = LD2_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);

    /*Configure GPIO pin Output Level */
    HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

    /* EXTI interrupt init*/
    HAL_NVIC_SetPriority(EXTI0_1_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);

    }

    /* USER CODE BEGIN 4 */

    void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
    {
    if(GPIO_Pin == Data_Out_Pin)
    {
    ADS1232_flag.dataready_flag = 1;
    }
    if(GPIO_Pin == Clk_out_Pin)
    {
    ADS1232_flag.ClockOut_flag = 1;
    }
    }
    /* USER CODE END 4 */

    #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

    /**
    * @}
    */

    /**
    * @}
    */

    /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  • Hi Sandeep,

    I'm sorry but it is not clear to me what you are asking as there appears to be both questions about timing as well as your code and I'm not sure if they are connected in any way.  If you are talking about the ADS1232REF and monitoring SCLK, you will see some delay.  This has nothing to do with the ADS1232, but rather the delay is with the micro making sure that all clocks have been transmitted and the receive buffer full before reading the data from the buffer.  There will be some delay using the micro SPI peripheral in this way.

    It appears that you are attempting to bit-bang the GPIO port to receive the data.  Unfortunately I cannot tell the timing of SCLK from code as there appears to be no SCLK being transmitted.  I see that you 'readpin' 24 times, but no where do I see that an SCLK is transmitted. 

    What you need to do is set the SCLK high for a minimum of 100ns, then set the SCLK low, read the DOUT pin and keep the SCLK low for a minimum of 100ns.  You would repeat this process until all data is read.

    Best regards,

    Bob B