Skip to main content
Visitor II
April 9, 2020
Question

Receiving wrong value for "Who am I".....Always getting 255 in received data (both bytes)

  • April 9, 2020
  • 1 reply
  • 987 views

I am using STM32F429 Discovery board and trying to communicate to on-board MEMS L3GD20 Angular sensor using SPI protocol. Problem is not receiving correct data as per Angular sensor. I am receiving value decimal 255. Where I am making mistake? Please help me. Thank you in advance. Code is given below for your reference:

 HAL_GPIO_WritePin(CS_SPI_GPIO_Port, CS_SPI_Pin, GPIO_PIN_SET); // Chip Select(SPI mode Start)

  Tx_Data[0] = 0; // Transmit Data Byte0// uint8_t type

 Tx_Data[1] = 15;// Transmitted Data Byte1// Who am I

 Rx_Data[0] = 0;// Received Data Byte0 // uint8_t type

 Rx_Data[1] = 0;// Received Data Byte1

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

   /* USER CODE END WHILE */

    HAL_GPIO_WritePin(CS_SPI_GPIO_Port, CS_SPI_Pin, GPIO_PIN_RESET);// SPI Mode active...

    HAL_SPI_Transmit(&hspi5,Tx_Data,2,100);

    HAL_SPI_Receive(&hspi5,Rx_Data,2,100);

    HAL_GPIO_WritePin(CS_SPI_GPIO_Port, CS_SPI_Pin, GPIO_PIN_SET);

    HAL_Delay(1000);

    Tx_Data[0] = 0;

    Tx_Data[1] = 0;

    Rx_Data[0] = 0;

    Rx_Data[1] = 0;

    HAL_Delay(1000);

    This topic has been closed for replies.

    1 reply

    Graduate II
    April 9, 2020

    Inspect signals with a scope confirm what's actually on the wire.

    I'd use HAL_SP_TransmitReceive() with 4 byte array

    AKuma.61Author
    Visitor II
    April 9, 2020

    Hi Clive1,

    Thank you for your response. I tried using HAL_SPI_TransmitReceive() with 4 byte array but problem persists. I dont have oscilloscope to check the wires so couldnt do that.

    Thank you,

    Ajay Kumar