© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
DevHeads IoT Integration ServerDIIS
DevHeads IoT Integration Server•2y ago•
20 replies
lokii

Why does enabling SPI peripheral in STM32 Nucleo L476RG change the master bit to 0?

Guys I'm trying to implement the SPI in my stm32 Nucleo l476RG without hal drivers.

I have have implemented the spi configuration using spi_init function

then when it ready for the communication i enable the SPE: SPI enable using a seprate function which is

#define SPI_CR1_SPE            6

void SPI_PeripheralControl(SPI_RegDef_t *pSPIX, uint8_t EnOrDi)
{
    if(EnOrDi == ENABLE)
    {
        pSPIX->CR1 |= (1<<SPI_CR1_SPE);
    }
    else
    {
        pSPIX->CR1 &= ~(1<<SPI_CR1_SPE);
    }
}
#define SPI_CR1_SPE            6

void SPI_PeripheralControl(SPI_RegDef_t *pSPIX, uint8_t EnOrDi)
{
    if(EnOrDi == ENABLE)
    {
        pSPIX->CR1 |= (1<<SPI_CR1_SPE);
    }
    else
    {
        pSPIX->CR1 &= ~(1<<SPI_CR1_SPE);
    }
}


the problem here is when pSPIX->CR1 |= (1<<SPI_CR1_SPE); line executes it changes the master bit in the cr1 register to 0 again

how can i slove this?
DevHeads IoT Integration Server banner
DevHeads IoT Integration ServerJoin
The DevHeads IoT Integration Server accelerates technology engineering by helping pro devs learn, share and collaborate.
2,984Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Issues with Viewing PRINTF Output on STM32 Nucleo L476RG with X-Nucleo IDB05A1
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
17mo ago
Hard Fault When Using STM32 Nucleo-F446RE with Wiznet W5500 via SPI
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
17mo ago
Issues Writing to CANBus with STM32 Nucleo F429ZI Using Mbed OS 6.6.0
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago
Configuring USB CDC Rx Interrupt for STM32-F446RE (Nucleo)
DevHeads IoT Integration ServerDIISDevHeads IoT Integration Server / 🪲-firmware-and-baremetal
2y ago