AD9251 communication with Stm32746

Hi all,

Anyone know how to connect AD9251 with Stm32F746g using CubeMX via SPI?

void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI5_Init(void);

hspi5.Instance = SPI5;
hspi5.Init.Mode = SPI_MODE_MASTER;
hspi5.Init.Direction = SPI_DIRECTION_1LINE;
hspi5.Init.DataSize = SPI_DATASIZE_8BIT;
hspi5.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi5.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi5.Init.NSS = SPI_NSS_SOFT;
hspi5.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi5.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi5.Init.TIMode = SPI_TIMODE_DISABLE;
hspi5.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi5.Init.CRCPolynomial = 7;
hspi5.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi5.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi5) != HAL_OK)
{
Error_Handler();
}

__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
/**Initializes the CPU, AHB and APB busses clocks
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 12;
RCC_OscInitStruct.PLL.PLLN = 192;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 2;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/**Activate the Over-Drive mode
*/
if (HAL_PWREx_EnableOverDrive() != HAL_OK)
{
Error_Handler();
}



AD9251
[edited by: Hotak at 10:32 AM (GMT 0) on 30 Sep 2019]
  • +1
    •  Analog Employees 
    on Sep 30, 2019 2:26 PM over 1 year ago

    Hi Mr. Hotak,

    I'm sorry I do not know anything about CubeMX or Stm32746.

    In case you have not seen it, AN-877 explains generally about SPI from the AD9251 perspective. The AD9251 specifics are in the AD9251 datasheet.

    I hope you can find the resources you need.

    Take care.

    Doug

  • Thank you for your reply,

    Any Idea how to read and write to AD9251? so far I am using HAL library as below but no response from ADC.

    MX_GPIO_Init();
    MX_SPI5_Init();
    /* USER CODE BEGIN 2 */
    //Write data
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_SET);// deactivact the slave
    HAL_Delay(5);// delay

    // Read Data
    // CS-low-activate
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_RESET);

    // Transmit Reg Address
    spiData[1]= 0x00;

    HAL_SPI_Transmit(&hspi5, spiData, 1, 10);

    // Read the register content
    HAL_SPI_Receive(&hspi5, &spiData[1], 1, 10 );
    // bring the CS to high- deactivate it
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_SET);

    //write to register
    //CS low -deactivate
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_RESET);
    spiData[0]= 0x0B;
    spiData[1]= 0x02;

    //Address 0xFF = 0x01;
    HAL_SPI_Transmit(&hspi5, spiData, 1, 5);

    //CS high-deactivate
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_SET);

    // Read Data
    // CS-low-activate
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_RESET);// this will activat the SPI device

    // Transmit Reg Address
    spiData[1]= 0x00;
    HAL_SPI_Transmit(&hspi5, &spiData[1], 1, 5);

    // Read register content
    HAL_SPI_Receive(&hspi5, &spiData[1], 1, 5 );
    HAL_GPIO_WritePin(GPIOF, GPIO_PIN_8 ,GPIO_PIN_SET);
    /* USER CODE END 2 */

  • +1
    •  Analog Employees 
    on Oct 4, 2019 5:54 PM over 1 year ago in reply to Hotak

    Hi Mr. Hotak,

    Some examples of SPI reads and writes are shown in AN-877. I do not know anything about how your system is applying SPI signals to AD9251.

    • Is the frequency of SCLK within specification?
    • Are setup and hold time requirements being met?
    • Be sure to take CSB low before any SPI communication is performed.

    Maybe someone in the EngineerZone community who is familiar with the HAL library can comment further.

    Thanks,

    Doug