cancel
Showing results for 
Search instead for 
Did you mean: 

Nucelo L053r8 SPI Comminucation issue

srm
Associate II
Posted on April 21, 2016 at 14:51

Heloo,

I Get some Randon Value when i call for data receive. I kindly request you to provide me soultion for my code.

SPI config in Mainis declared as :

void MX_SPI1_Init(void)

{

  hspi1.Instance = SPI1;

  hspi1.Init.Mode = SPI_MODE_MASTER;

  hspi1.Init.Direction = SPI_DIRECTION_2LINES;

  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;

  hspi1.Init.NSS = SPI_NSS_SOFT;

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;

  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

  hspi1.Init.CRCPolynomial = 7;

  HAL_SPI_Init(&hspi1);

}

I am trying to receive and transmit value . Is this the way you transmit and receive a value using SPI communication.

void ADS1220SendByte(uint8_t Byte)

{

uint8_t *dummy;

  /* Call SPI read generic function */

  if(HAL_SPI_Transmit(&hspi1, (uint *)Byte, 1,5000) != HAL_OK)

  {

    set_ERROR();

  }

 

//  if(HAL_SPI_Receive(&hspi1, dummy, 1,5000) != HAL_OK)

//  {

//    set_ERROR();

//  }   

}

unsigned char ADS1220ReceiveByte(void)

{

   unsigned char *Result;

/* Call SPI read generic function */

//  if(HAL_SPI_Transmit(&hspi1, (uint8_t *)0xFF, 1,5000) != HAL_OK)

//  {

//    set_ERROR();

//  }

  if(HAL_SPI_Receive(&hspi1, Result, 1, 5000) != HAL_OK)

  {

    set_ERROR();

  }

return *Result;

}

#stm32l053 #stm32f4 #nucleo #nucleo #discovery #spi #spi #!stm32 #device
2 REPLIES 2
Nesrine M_O
Lead II
Posted on April 21, 2016 at 16:11

Hi malladi.sandeep.001,

I recommend you to have a look to SPI examples under the STM32L0 cube firmware package, it may be helpful :

STM32Cube_FW_L0_V1.5.0\Projects\STM32L053R8-Nucleo\Examples\SPI

-Syrine-

srm
Associate II
Posted on April 25, 2016 at 10:28

Hello Syrine,

Thanks for the reply but my problem is i am able to communicate with the slave device using STM32-Nucleo L053R8 board but when i read a particular register by call SPI read and Write i get differnt values if i tell SPI to read a particular rigester value it gives some value as 0x00000008 but while writing in to particular register  the value is 0x00000000 i am unable to identify the problem could you please help me out. I here by send my code that i had implemented.

void ADS1220Config(void)

{

//ADS1220ReadRegister(ADS1220_0_REGISTER, 0x01, &Temp);

   

// clear prev value;

  // Temp &= 0x0f;

    Temp1 |= ADS1220_MUX_0_G;

   

    // write the register value containing the new value back to the ADS

    ADS1220WriteRegister(ADS1220_0_REGISTER, 0x01, &Temp1);

   

//ADS1220ReadRegister(ADS1220_1_REGISTER, 0x01, &Temp);

   

// clear prev DataRate code;

//Temp &= 0x0f;

Temp2 |= (ADS1220_DR_20 + ADS1220_CC); // Set default start mode to 600sps and continuous conversions

   

// write the register value containing the new value back to the ADS

ADS1220WriteRegister(ADS1220_1_REGISTER, 0x01, &Temp2);

}

my spi Transmit and receive functions are this way 

void ADS1220SendByte(uint8_t Byte)

{

  if(HAL_SPI_Transmit_IT(&hspi1,&Byte, sizeof(Byte))!= HAL_OK)

  {

    /* Transfer error in transmission process */

    set_ERROR();

  }

  while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)

  {

  } 

}

unsigned char ADS1220ReceiveByte(void)

{

   uint8_t Result;

  if(HAL_SPI_Receive_IT(&hspi1,&Result, sizeof(Result))!= HAL_OK)

  {

    set_ERROR();

   }

  while (HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)

  {

  } 

return Result;

}

Can you please look in to the code. Thanks