cancel
Showing results for 
Search instead for 
Did you mean: 

The value in the WhoAmI register cannot be read properly.

baby_chicken
Senior

Hi guys,

I am currently trying to read the value of the WhoAmI register using SPI communication with the ICM42688P, but it returns 0xf3 when it should return 0x47.

 

Is there something wrong with my program or configuration?

Please tell me about it.

 

.hpp

 

 

 

 

#pragma once #include "arm_math.h" #include "stm32f4xx_hal.h" #include "stm32f4xx_hal_gpio.h" #include "spi.h" class IMUICM42688P { public: IMUICM42688P(SPI_HandleTypeDef &hspi, GPIO_TypeDef *cs_x, uint16_t cs_pin); void init(); uint8_t getWhoAmI(); float32_t getAccelX(); float32_t getAccelY(); float32_t getAccelZ(); private: uint8_t read(const uint8_t address); void write(const uint8_t address, const uint8_t data); void setConfigs(); void setAccelConfig(); void setPowerManage(); SPI_HandleTypeDef &_hspi; GPIO_TypeDef *cs_x_; const uint16_t cs_pin_; float32_t accel_range_; // default: 2.0f float32_t imu_range_; };
View more

 

 

 

 

 

 

.cpp

 

 

 

 

#include "halplus/layer_driver/circuit/icm42688p.hpp" IMUICM42688P::IMUICM42688P(SPI_HandleTypeDef &hspi, GPIO_TypeDef *cs_x, uint16_t cs_pin): _hspi(hspi), cs_x_(cs_x), cs_pin_(cs_pin){} void IMUICM42688P::init(){ HAL_SPI_Init(&_hspi); HAL_GPIO_WritePin(cs_x_, cs_pin_, GPIO_PIN_SET); setConfigs(); } uint8_t IMUICM42688P::getWhoAmI(){ const uint8_t address = 0x75; //< Input who_am_i: 0x75, return: 0x47 return read(address); } float32_t IMUICM42688P::getAccelX(){ const int16_t raw_accel_x = static_cast<int16_t>(((read(0x1F) << | read(0x20))); return (accel_range_ * static_cast<float32_t>(raw_accel_x) / static_cast<float32_t>(INT16_MAX)); } float32_t IMUICM42688P::getAccelY(){ const int16_t raw_accel_y = static_cast<int16_t>((read(0x21) << | read(0x22)); return (accel_range_ * static_cast<float32_t>(raw_accel_y) / static_cast<float32_t>(INT16_MAX)); } float32_t IMUICM42688P::getAccelZ(){ const int16_t raw_accel_z = static_cast<int16_t>((read(0x23) << | read(0x24)); return (accel_range_ * static_cast<float32_t>(raw_accel_z) / static_cast<float32_t>(INT16_MAX)); } uint8_t IMUICM42688P::read(const uint8_t address){ constexpr uint16_t size = 2; const uint8_t read_mode = 0b10000000; //< (read:1, write:0) const uint8_t tx_data[size] = {static_cast<uint8_t>(read_mode | address), 0x00}; uint8_t rx_data[size] = {0x00, 0x00}; HAL_GPIO_WritePin(cs_x_, cs_pin_, GPIO_PIN_RESET); // CS pin: LOW HAL_SPI_TransmitReceive(&_hspi, (uint8_t*)tx_data, (uint8_t*)rx_data, size, 100); HAL_GPIO_WritePin(cs_x_, cs_pin_, GPIO_PIN_SET); return rx_data[1]; } void IMUICM42688P::write(const uint8_t address, const uint8_t data){ constexpr uint16_t size = 2; const uint8_t tx_data[size] = {address, data}; HAL_GPIO_WritePin(cs_x_, cs_pin_, GPIO_PIN_RESET); // CS pin: LOW HAL_SPI_Transmit(&_hspi, (uint8_t*)tx_data, size, 100); HAL_GPIO_WritePin(cs_x_, cs_pin_, GPIO_PIN_SET); // CS pin: HIGH } void IMUICM42688P::setConfigs(){ HAL_Delay(10); setPowerManage(); HAL_Delay(10); setAccelConfig(); HAL_Delay(10); } void IMUICM42688P::setAccelConfig(){ constexpr uint8_t accel_conf_addr = 0x50; constexpr uint8_t accel_conf_data = 0b01100110; // range:2[g], rate:1k[Hz] write(accel_conf_addr, accel_conf_data); } void IMUICM42688P::setPowerManage(){ constexpr uint8_t accel_conf_addr = 0x4E; constexpr uint8_t accel_conf_data = 0b00011111; // range:2[g], rate:1k[Hz] write(accel_conf_addr, accel_conf_data); }
View more

 

 

 

 

 

 

 

スクリーンショット 2024-08-30 183826.png

Microcontroller STM32F407vgt6,cubeide

Best regards.

 

20 REPLIES 20

Show waveforms on the bus taken by oscilloscope or logic analyzer.

JW

スクリーンショット 2024-09-03 193635.png

スクリーンショット 2024-09-03 194351.png

  

Orange is CS and blue is SCLK.

 

Best regards.

So what about MOSI and MISO?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

スクリーンショット 2024-09-03 201958.png

スクリーンショット 2024-09-03 202526.png

 

Orange is MOSI and blue is MISO.

Can't really see much from those images - please increase the resolution.

Also, it seems to be all "blue" - no orange?

Can you not show all 4 channels together?

 

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

The blue and orange colors are overlapped so that only blue is visible.

Sorry, but I can only do 2 channels.

Best regards.

So shift the traces to not overlap!

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

 

 

  

How about this?

スクリーンショット 2024-09-03 205925.png

スクリーンショット 2024-09-03 205939.png

Sorry, I made a mistake.
This is the original one.