SPI Communication

Discussions and support about ChibiOS/RT, the free embedded RTOS.
karthik
Posts: 10
Joined: Mon Jun 23, 2025 10:38 am

Re: SPI Communication

Post by karthik »

I enabled 2 SPI's, they are SPI1 and SPI4.

I changed configuration in mcuconf.h
#define STM32_SPI_USE_SPI1 TRUE
#define STM32_SPI_USE_SPI2 FALSE
#define STM32_SPI_USE_SPI3 FALSE
#define STM32_SPI_USE_SPI4 TRUE

I changed configuration in halconf.h
#if !defined(HAL_USE_SPI) || defined(__DOXYGEN__)
#define HAL_USE_SPI TRUE
#endif
in main code

Code: Select all

palSetPadMode(GPIOF, 2, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);                    // CS ICM20689
palSetPadMode(GPIOD, 7, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST);                           // SPI1SCK
palSetPadMode(GPIOA, 6, PAL_MODE_ALTERNATE(5)  | PAL_STM32_OSPEED_HIGHEST);                          // SPI1MISO
palSetPadMode(GPIOG, 11, PAL_MODE_ALTERNATE(5)  | PAL_STM32_OSPEED_HIGHEST);                        // SPI1MOSI

palSetPadMode(GPIOF, 10, PAL_MODE_OUTPUT_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);                  // CS MS5611
palSetPadMode(GPIOE, 2, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST);                            // SPI4SCK
palSetPadMode(GPIOE, 6, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST);                            // SPI4MISO
palSetPadMode(GPIOE, 13, PAL_MODE_ALTERNATE(5) | PAL_STM32_OSPEED_HIGHEST);                          // SPI4MOSI

spiStart(&SPID1, &spi1cfg);
uint8_t txbuf[2] = { reg | 0x80, 0x00 };
  uint8_t rxbuf[2];

  palClearPad(GPIOF, 2);

  spiAcquireBus(&SPID1);
  spiSelect(&SPID1);
  chprintf(&SD2, "SPI1 enter\r\n");
  spiExchange(&SPID1, 2, txbuf, rxbuf);
  chprintf(&SD2, "SPI1 exit\r\n");
  spiUnselect(&SPID1);
  spiReleaseBus(&SPID1);
palSetPad(GPIOF, 2);

spiStart(&SPID4, &spicfg_ms5611);
uint8_t cmd = 0xA2;
    uint8_t rx[2];
   palClearPad(GPIOF, 10);
    spiAcquireBus(&SPID4);
    spiSelect(&SPID4);
    chprintf(&SD2, "SPI4 enter\r\n");
    spiSend(&SPID4, 1, &cmd);
    chprintf(&SD2, "SPI4 exit\r\n");
    spiReceive(&SPID4, 2, rx);
    spiUnselect(&SPID4);
    spiReleaseBus(&SPID4);
palSetPad(GPIOF, 10);



the serial out after configuration is
SPI1 enter
SPI1 exit
SPI4 enter

Code stops, unable to process next command lines.

Please provide me the solution for spi configuration is anythings i have missed.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: SPI Communication

Post by Giovanni »

You need to determine how it stops, enable assertions and checks in chconf.h and then use the debugger to see where it stops and the cause.

Giovanni.
Post Reply