1

Interfacing with Maxi 11060 ADC (16 bit) over SPI seems an issue with my code, can you please look and let me know what's missing?

NOTE: Code is generated using STM32CubeMX

in main after all standard inits

configure_MAX11060();

in

while (1) 
{
    while( (GPIOB->IDR & (1 << 0)) != 0);
    MAX11060_full_read();
    HAL_Delay(500);
}

in

void configure_MAX11060()
{
    uint8_t config_reg_write[] = {CONFIG_REG_WRITE_ADDR, CONFIG_REG_WRITE_VALUE}; //0x60 and 0x00
    /* (1) : SPI Transmit, write to config reg on address 0xE0 */
    // Step(1): Bring the CS pin low to activate the slave device
    CS0_ENABLE
    HAL_Delay(10); //delay to initially setup the configuration register
    // Step(2): Transmit config reg address  & data
    HAL_SPI_Transmit(&hspi1, &config_reg_write[0], 1, TIMEOUT_VAL);
    HAL_SPI_Transmit(&hspi1, &config_reg_write[1], 1, TIMEOUT_VAL);
    // Step(3): Bring the CS pin high again
    CS0_DISABLE
    // give the sensor time to set up
    HAL_Delay(100);
}

in MAX11060_full_read()

void MAX11060_full_read()
{
    uint8_t reg_read_addr = READ_REG_DATA; //0xF0

    /* (2) : SPI Receive, read the contents of registers */
    // Step(1): Bring the CS pin low to activate the slave device
    CS0_ENABLE //#define CS0_ENABLE     do { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET); } while(0);
    HAL_Delay(10);
    // Step(2): Transmit read reg address telling IC that we want to 'read' and start at register 0
    HAL_SPI_Transmit(&hspi1, &reg_read_addr, 1, TIMEOUT_VAL); //TIMEOUT is 60, epecting 96 bits
    /* Step (3): Receive the first 8 bits (Config reg data) */
  HAL_SPI_Receive(&hspi1, &read_data[0], 12, TIMEOUT_VAL * 100);
    // Step(4): Bring the CS pin high again
    CS0_DISABLE
    /* Step (5): Store the data read from the sensor */
    //TBD
}

SPI init is standard as follows

static void MX_SPI1_Init(void)
{

  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

}

GPIO pin is handled as follows

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{

  GPIO_InitTypeDef GPIO_InitStruct;
  if(hspi->Instance==SPI1)
  {
  /* USER CODE BEGIN SPI1_MspInit 0 */

  /* USER CODE END SPI1_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_SPI1_CLK_ENABLE();

    /**SPI1 GPIO Configuration    
    PA5     ------> SPI1_SCK
    PA6     ------> SPI1_MISO
    PA7     ------> SPI1_MOSI 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI1_MspInit 1 */
        GPIO_InitStruct.Pin = GPIO_PIN_4;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  /* USER CODE END SPI1_MspInit 1 */
  }

}

I receive either series of 00 in my read_data and randomly FF's. This is my second attempt with SPI and bot are a no success, any help would be greatly appreciated.

  • HAL - disaster. But for SPI & I2C you need to connect the logic analyser (even $10 one from China). Otherwise it is very difficult to debug – 0___________ Aug 04 '17 at 15:17

0 Answers0