From a9390b145bb19e98809e36d26187be91c8cdc73c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 3 Jun 2021 16:44:02 +0200 Subject: [PATCH] stll some issues --- stm32h7/devicetest/GyroL3GD20H.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/stm32h7/devicetest/GyroL3GD20H.cpp b/stm32h7/devicetest/GyroL3GD20H.cpp index fad9923..10e5335 100644 --- a/stm32h7/devicetest/GyroL3GD20H.cpp +++ b/stm32h7/devicetest/GyroL3GD20H.cpp @@ -17,12 +17,17 @@ DMA_HandleTypeDef rxDmaHandle; GyroL3GD20H::GyroL3GD20H(SPI_HandleTypeDef *spiHandle): spiHandle(spiHandle) { setDmaHandles(&txDmaHandle, &rxDmaHandle); + GPIO_InitTypeDef chipSelect = {}; + chipSelect.Pin = GPIO_PIN_14; + chipSelect.Mode = GPIO_MODE_OUTPUT_PP; + HAL_GPIO_Init(GPIOD, &chipSelect); + HAL_GPIO_WritePin(GPIOD, 14, GPIO_PIN_SET); } ReturnValue_t GyroL3GD20H::initialize() { // Configure the SPI peripheral spiHandle->Instance = SPI1; - uint32_t test = HAL_RCC_GetHCLKFreq(); + //uint32_t test = HAL_RCC_GetHCLKFreq(); spiHandle->Init.BaudRatePrescaler = spi::getPrescaler(HAL_RCC_GetHCLKFreq(), 3900000); spiHandle->Init.Direction = SPI_DIRECTION_2LINES; spi::assignSpiMode(spi::SpiModes::MODE_3, spiHandle); @@ -47,7 +52,18 @@ ReturnValue_t GyroL3GD20H::initialize() { ReturnValue_t GyroL3GD20H::performOperation() { transferState = TransferStates::WAIT; + + const uint8_t WHO_AM_I_REG = 0b00001111; + const uint8_t STM_READ_MASK = 0b10000000; + const uint8_t EXPECTED_WHO_AM_I_VAL = 0b11010111; + + sif::printInfo("GyroL3GD20H::performOperation: Reading WHO AM I register\n"); + + txBuffer[0] = WHO_AM_I_REG | STM_READ_MASK; + txBuffer[1] = 0; + // Start SPI transfer via DMA + HAL_GPIO_WritePin(GPIOD, 14, GPIO_PIN_RESET); if(HAL_SPI_TransmitReceive_DMA(spiHandle, txBuffer.data(), rxBuffer.data(), 2) != HAL_OK) { // Transfer error in transmission process sif::printWarning("Error transmitting SPI with DMA\n"); @@ -64,6 +80,11 @@ ReturnValue_t GyroL3GD20H::performOperation() { switch(transferState) { case(TransferStates::SUCCESS): { sif::printInfo("Transfer success\n"); + uint8_t whoAmIVal = rxBuffer[1]; + if(whoAmIVal != EXPECTED_WHO_AM_I_VAL) { + sif::printDebug("GyroL3GD20H::performOperation: " + "Read WHO AM I value not equal to expected value!\n"); + } transferState = TransferStates::IDLE; break; } @@ -88,6 +109,7 @@ ReturnValue_t GyroL3GD20H::performOperation() { */ void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi) { transferState = TransferStates::SUCCESS; + HAL_GPIO_WritePin(GPIOD, 14, GPIO_PIN_SET); } /**