2023-08-08 02:17 AM
I am using NUCLEO-L4R5ZI MCU to communicate with Murata SCA3300 sensor. As an initial step I am trying to read WHOAMI to check weather SPI communication is established. According to data sheet of the sensor returned value should be 51h but I am getting 0. While debugging I also see that WHOAMI variable which I have declared and given the address value changes to some garbage value.
I am pretty sure I am making mistakes as I am very new to this platform. I request and thank to valuable inputs.
Below is my code:
const int8_t Read_WHOAMI[4] = { 0x40, 0x00, 0x00, 0x91 }; //Address as given in datasheet
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_SPI_Transmit_DMA(&hspi2, Read_WHOAMI, 4); //While debugging the Read_WHOAMI changes to some garbage value here
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_0, GPIO_PIN_SET);
static void MX_SPI2_Init(void)
{
/* USER CODE BEGIN SPI2_Init 0 */
/* USER CODE END SPI2_Init 0 */
/* USER CODE BEGIN SPI2_Init 1 */
/* USER CODE END SPI2_Init 1 */
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 7;
hspi2.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi2.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI2_Init 2 */
/* USER CODE END SPI2_Init 2 */
}