stll some issues

This commit is contained in:
Robin Müller 2021-06-03 16:44:02 +02:00
parent abe62d807a
commit a9390b145b
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC

View File

@ -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);
}
/**