STM32F767zi: ICM200948 over SPI

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
tsm
Posts: 16
Joined: Tue Mar 03, 2020 9:12 pm
Has thanked: 1 time
Been thanked: 1 time

STM32F767zi: ICM200948 over SPI

Post by tsm »

Hi,

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
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F767zi: ICM200948 over SPI

Post by Giovanni »

Hi,

If you use spiSelect() then NSS should be a normal GPIO output.

Giovanni
tsm
Posts: 16
Joined: Tue Mar 03, 2020 9:12 pm
Has thanked: 1 time
Been thanked: 1 time

Re: STM32F767zi: ICM200948 over SPI

Post by tsm »

Hi Giovanni,

thanks for taking the time.
I'm not sure what you mean. Isn't the configuration I showed for NSS PIN_MODE_OUTPUT(GPIOB_SPI2_NSS) , etc enough to set it as an output GPIO?

Best
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F767zi: ICM200948 over SPI

Post by Giovanni »

Hi,

I think you should look at signals using a logic analyser, that would help understanding the problem. Do you see anything on those pins?

Giovanni
rew
Posts: 383
Joined: Sat Jul 19, 2014 12:59 pm
Has thanked: 2 times
Been thanked: 14 times

Re: STM32F767zi: ICM200948 over SPI

Post by rew »

Giovanni's first remark is on target:

The hardware CAN do something with the NSS line, but chibios considers that "not handy to work with", so the driver expects the NSS pin to be GPIO, and when it needs it low, it will simply palClearPad (spicfg->ssport, spicfg->sspad);
Post Reply