cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I'm new to STM32L4. I'm trying to connect an ADI evaluation board to my STEVAL-STWIN through SPI2. I had to adapt the different functions to the HAL library.

GLoiz.1
Associate

I am trying to read the register of the chip_id, but the function returns a nDevId that is probably wrong. I set STG3692 switch to obtain SPI configuration and I introduce a GPIO_PIN to configure CS.

What could be wrong? below the basic

steps of the code

Thanks

if (adi_adpddrv_RegRead(ADPD4x_REG_CHIP_ID, &nDevId) == ADI_ADPD_DRV_SUCCESS)
//the function returns ADI_ADPD_DRV_SUCCESS
  {
   if ((nDevId & ADPD400x_ID) == ADPD400x_ID)
   {
    /* Update the trace variable with success code, so the caller will get
    status of their request */
    nRetCode = ADI_ADPD_DRV_SUCCESS;
   }
  }
/*-------*/
 
uint16_t adi_adpddrv_RegRead(uint16_t nAddr, uint16_t *pnData)
{
 /* Declare variable to track the status of routine */
 uint16_t nRetCode = ADI_ADPD_DRV_SUCCESS;
 /* Declare variable to store number of byte to be transmit */
 uint16_t nTxSize = 0U;
 /* Declare variable to store register address */
 uint16_t nTmpAddr = 0U;
 /* Declare variable to store value from receive buffer */
 uint8_t anRxData[2] = {0U, 0U};
 /* Declare variable to prepare transmit buffer */
 uint8_t anTxData[2] = {0U, 0U};
 /* Check the communication type and proceed with selected peripheral */
 if (gAdiAdpdDrvInst.nAdpd400xCommMode == E_ADI_ADPD_SPI_BUS)
 {
  /* To set the last bit low for read operation */
  nTmpAddr = (nAddr << 1U)& ADPD400x_SPI_READ;
  /*! Prepare the transmit buffer with register address */
  anTxData[nTxSize++] = (uint8_t)(nTmpAddr >> 8U);
  anTxData[nTxSize++] = (uint8_t)(nTmpAddr);
  /*
  The first argument to the function is the register address of the
  ADPD400x device from where the data is to be read.
  The 2nd argument is the pointer to the buffer of received data.
  The size of this buffer should be equal to the number of data requested.
  The 3rd argument is the size of transmit data in bytes.
  The 4th argument is the size of requested data in bytes.
  Adpd400x_SPI_Receive() should be implemented in such a way that it transmits
  the register address from the first argument and receives the data
  specified by the address in the second argument. The received data will
  be of size specified by 3rd argument.
  */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET);
if(HAL_SPI_Transmit(&hspi2,anTxData,nTxSize, 1000)== HAL_OK){
if(HAL_SPI_Receive(&hspi2,anRxData,2U, 1000)!= HAL_OK)
// if (Adpd400x_SPI_Receive(anTxData, anRxData, nTxSize, 2U)!= ADI_ADPD_DRV_SUCCESS)
{
/* Update the trace variable with failure code, so the caller will get
status of their request */
nRetCode = ADI_ADPD_DRV_READ_ERROR;
}}
 }
 else
 {
  /*
  1. This block will get execute when the communication type set as none.
  2. Update the trace variable with failure code, so the caller will get
  status of their request */
  nRetCode = ADI_ADPD_DRV_PARAM_ERROR;
 }
 /* Copy the register value from receive buffer to output parameter with byte order [15:0]*/
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET);
 *pnData = (((uint16_t)anRxData[0]) << (8U)) + (anRxData[1]);
 /* Return routine status to caller function */
 return nRetCode;
}

0 REPLIES 0