2020-04-09 01:08 PM
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);
2020-04-09 01:14 PM
Inspect signals with a scope confirm what's actually on the wire.
I'd use HAL_SP_TransmitReceive() with 4 byte array
2020-04-09 01:34 PM
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