cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446 and ADS8885 code help

MDoln.1
Associate II

Hi

Please can someone help me with the code for STM32F446 and ADS8885 http://www.ti.com/lit/ds/sbas568a/sbas568a.pdf I'm not sure how to read the values ​​using SPI here is part of my code.

uint8_t adc_buff[3] = {0,0,0};
uint32_t adc_val = 0;
 
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
HAL_SPI_Receive(&hspi2, adc_buff, 3, 100);
adc_val = (adc_buff[0] << 10) | (adc_buff[1] << 2) | (adc_buff[2] & 0x03);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
 
//SPI2 Setup
void MX_SPI2_Init(void)
{
 
  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_2;
  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();
  }
 
}
 
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
 
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(spiHandle->Instance==SPI2)
  {
  /* USER CODE BEGIN SPI2_MspInit 0 */
 
  /* USER CODE END SPI2_MspInit 0 */
    /* SPI2 clock enable */
    __HAL_RCC_SPI2_CLK_ENABLE();
  
    __HAL_RCC_GPIOB_CLK_ENABLE();
    /**SPI2 GPIO Configuration    
    PB13     ------> SPI2_SCK
    PB14     ------> SPI2_MISO
    PB15     ------> SPI2_MOSI 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /* USER CODE BEGIN SPI2_MspInit 1 */
 
  /* USER CODE END SPI2_MspInit 1 */
  }
}
 
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
{
 
  if(spiHandle->Instance==SPI2)
  {
  /* USER CODE BEGIN SPI2_MspDeInit 0 */
 
  /* USER CODE END SPI2_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_SPI2_CLK_DISABLE();
  
    /**SPI2 GPIO Configuration    
    PB13     ------> SPI2_SCK
    PB14     ------> SPI2_MISO
    PB15     ------> SPI2_MOSI 
    */
    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
 
  /* USER CODE BEGIN SPI2_MspDeInit 1 */
 
  /* USER CODE END SPI2_MspDeInit 1 */
  }
}

4 REPLIES 4

What is the observed behaviour? What are the waveforms on the SPI pins of the ADS8885? Do they match the description in the ADS8885 datasheet?

JW

MDoln.1
Associate II

Hi

Manage it strangely when I connect pin 4 of AINN to GND so it works it doesn't work only in True-Differential when I use both AINP and AINN inputs.

MDoln.1
Associate II

Hi

I'm adding a few photos that show my problem with ADC in the first two photos is ADC without the input signal on the other two is the signal OK until it exceeds a certain value and then the output data will start to deform as seen in the last two photos. The signal displayed on the Oscilloscope is measured on 3.4 ADC pins.

0690X00000BwlrRQAR.jpg0690X00000BwlrbQAB.jpg0690X00000BwlrlQAB.jpg0690X00000BwlrqQAB.jpg0690X00000BwlrvQAB.jpg0690X00000Bwls0QAB.jpg

Looks like signed values interpreted as unsigned.

JW