cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Disc - receive data from accelerometer using SPI and transmit the data to bluetooth using UART with HAL

MO'Su
Associate

I'm having trouble using the HAL libraryies to send data I receive from the LIS3DSH accelerometer on the STM32F4 discovery to a HC-06 Bluetooth board.

I can receive the data from the LIS3DSH fine and use STMStudio to check that the data is all streaming ok.

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  UNUSED(GPIO_Pin);
		
	//SPI Recieve**********************
	// 1. Bring Slave Sel Low
	HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_RESET);
	// 2. Transmit register+0x80 (set MSB bit high -read mode)
	spiTxBuf[0] = 0x29|0x80;
	HAL_SPI_Transmit(&SPIHand, spiTxBuf, 1, 50);
	// 3. Receive Data
	HAL_SPI_Receive(&SPIHand, spiRxBuf, 1, 50);
	// 4. Bring Slave Sel High
	HAL_GPIO_WritePin(GPIOE, GPIO_PIN_3, GPIO_PIN_SET);
	
	HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);			
}

Now, I want to take the data I receive from HAL_SPI_Receive and pass it to a HAL_UART_Transmit function to send the data to a HC-06 Bluetooth chip. I've checked that my UART code is working fine. I can send strings no problem, and check that I receive them properly in a Bluetooth terminal.

But I can't figure out how to send the spiRxBuf. All I am doing so far is adding the following line to the end of the HAL_GPIO_EXTI_Callback function. I do not receive any data using this code.

HAL_UART_Transmit(&UartHand, spiRxBuf, 1, 20);

Can someone please tell me how to do this?

Thanks,

Mark

0 REPLIES 0