I'm working on a driver for this IMU device on some custom hardware based on the stm32f767zi. There might be something wrong with my configuration as I can't read the device's ID.
This is what I have currently:
relevant parts from board.h
Code: Select all
#define GPIOB_SPI2_NSS 12U
#define GPIOB_SPI2_SCK 13U
#define GPIOB_SPI2_MISO 14U
#define GPIOB_SPI2_MOSI 15U
#define LINE_SPI2_NSS PAL_LINE(GPIOB, 12U)
#define LINE_SPI2_SCK PAL_LINE(GPIOB, 13U)
#define LINE_SPI2_MISO PAL_LINE(GPIOB, 14U)
#define LINE_SPI2_MOSI PAL_LINE(GPIOB, 15U)
PIN_MODE_OUTPUT(GPIOB_SPI2_NSS) | \
PIN_MODE_ALTERNATE(GPIOB_SPI2_SCK) | \
PIN_MODE_ALTERNATE(GPIOB_SPI2_MISO) | \
PIN_MODE_ALTERNATE(GPIOB_SPI2_MOSI))
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_NSS) | \
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_SCK) | \
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_MISO) | \
PIN_OTYPE_PUSHPULL(GPIOB_SPI2_MOSI))
PIN_OSPEED_HIGH(GPIOB_SPI2_NSS) | \
PIN_OSPEED_HIGH(GPIOB_SPI2_SCK) | \
PIN_OSPEED_HIGH(GPIOB_SPI2_MISO) | \
PIN_OSPEED_HIGH(GPIOB_SPI2_MOSI))
PIN_PUPDR_FLOATING(GPIOB_SPI2_NSS) | \
PIN_PUPDR_FLOATING(GPIOB_SPI2_SCK) | \
PIN_PUPDR_FLOATING(GPIOB_SPI2_MISO) | \
PIN_PUPDR_FLOATING(GPIOB_SPI2_MOSI))
PIN_AFIO_AF(GPIOB_SPI2_NSS, 0U) | \
PIN_AFIO_AF(GPIOB_SPI2_SCK, 5U) | \
PIN_AFIO_AF(GPIOB_SPI2_MISO, 5U) | \
PIN_AFIO_AF(GPIOB_SPI2_MOSI, 5U))
This is the SPI configuration I'm setting:
Code: Select all
static const SPIConfig SPID2_CONFIG = {
// circular mode
.circular = false,
// callback
.end_cb = nullptr,
// chip select port
.ssport = GPIOB,
// chip select pad number
.sspad = GPIOB_SPI2_NSS,
// control register 1
.cr1 = SPI_CR1_BR_0 | SPI_CR1_CPOL | SPI_CR1_CPHA,
// control register 2
.cr2 = SPI_CR2_DS_0 | SPI_CR2_DS_1 | SPI_CR2_DS_2
};
Then after calling spiStart I just call spiExchange to read from the proper register where the device ID should be. I'm controlling chip select with spiSelect. I'm not very experience with SPI so I might failing to configure properly the pins?
Thank you