cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to talk to BMP280 over SPI

BadEngineer
Associate II

I am attempting to talk to BMP280 over SPI using Nucelo-F401RE. 

I am using SPI2 on the F401RE board to do so, I am able to read from it correctly but I can't seem to write to it in order to communicate with it. 

My code is as follows 

 

  /* USER CODE BEGIN WHILE */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);	// Setting this high, to not select the chip

  char send_buff [8] = {0,0,0,0,0,0,0,0};
  char recieve_buff_0 [8] = {0,0,0,0,0,0,0,0};
  char recieve_buff_1 [8] = {0,0,0,0,0,0,0,0};

  HAL_StatusTypeDef ret;

  while (1)
  {
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);	// Setting this low to enable the chip
	  send_buff[0] = 208;
	  ret = HAL_SPI_Transmit(&hspi2, send_buff, 1, 1000);			// Reading the register ID
	  ret = HAL_SPI_Receive(&hspi2, recieve_buff_0, 1, 1000);			// I receive 88 (0x58) back which is correct
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);	// Setting this high, to not select the chip

	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);	// Setting this low to enable the chip
	  send_buff[0] = 244;
	  send_buff[1] = 39;
	  ret = HAL_SPI_Transmit(&hspi2, send_buff, 2, 1000);			// Reading the ctrl_meas register
	  ret = HAL_SPI_Receive(&hspi2, recieve_buff_1, 1, 1000);			// Should receive 39 but getting back all 0s
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);	// Setting this high, to not select the chip

    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

 

My SPI settings are as it follows: 

BadEngineer_0-1729687715488.png

 

I have attached the bmp280 datasheet as well as the main.c file for my project. 

I have attached some images of my project. (I have got this sensor working with I2C and searched the internet for a possible solution but every git repo seems to only have it working with I2C not SPI). 

 

BadEngineer_1-1729687992419.pngBadEngineer_2-1729688014300.png

 

 

0 REPLIES 0