STM32 SPI Slow Compute

后端 未结 2 1796
小鲜肉
小鲜肉 2020-12-06 13:46

I\'m using a STM32F4 and its SPI to talk to a 74HC595 like in this tutorial. Difference is for starters I\'m using the non-DMA version for simplicity. I used STMCubeMX to co

2条回答
  •  执笔经年
    2020-12-06 14:30

    How do i get that to toggle faster?

    If possible, use the hardware NSS pin

    Some STM32 controllers can toggle their NSS pin automatically, with a configurable delay after transmission. Check the Reference Manual, if yours is one of these, reconnect the latch pin of the shifter to the SPIx_NSS pin on the MCU.

    Don't use HAL

    HAL is quite slow and overcomplicated for anything with tight timing requirements. Don't use it.

    Just implement the SPI transmit procedure in the Reference Manual.

    SPI->CR1 |= SPI_CR1_SPE; // this is required only once
    GPIOA->BSRR = 1 << (8 + 16);
    *(volatile uint8_t *)&SPI->DR = 0b00000010;
    while((SPI->SR & (SPI_SR_TXE | SPI_SR_BSY)) != SPI_SR_TXE)
        ;
    GPIOA->BSRR = 1 << 8;
    

提交回复
热议问题