Laga.Freya

STM32F107 and SPI3 configuration

Discussion created by Laga.Freya on Mar 3, 2017
Latest reply on Mar 27, 2017 by H.Rick

Hi to all,
I have an issue with SPI3 port as it seems not working. I have no problems with SPI1 and SPI2 that are working with no problems, but I am not able to get a response from SPI3, that is when I check signals with a scope I got no clock and no MOSI.
Here is a snapshot of my initializing code. I enclosed all SPI routines in a class:

 


#define SPI3SCK        3        // GPIOB
#define SPI3MISO    4        // GPIOB
#define SPI3MOSI    5        // GPIOB

 

MYSPI::MYSPI(uint32_t clock, uint8_t spin)
{
    spi = (SPI_TypeDef *) 0xFFFFFFFF;
    bclock = clock;
    
    /* I cut some code here for  not posting too much lines */
    if(spin == MYSPI2)
    {
        spi = SPI2;
        if(!(RCC->APB2ENR & RCC_APB2ENR_IOPBEN)) RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;        // Enable GPIOB clock
        GPIOB->CRH &= ~(0x0F<<(4*(SPI2SCK-8)) | 0x0F<<(4*(SPI2MISO-8)) | 0x0F<<(4*(SPI2MOSI-8)));    //Resert CRL_MODE and CRL_CNF register
        GPIOB->CRH |= 0x0A<<(4*(SPI2SCK-8)) | 0x04<<(4*(SPI2MISO-8)) | 0x0A<<(4*(SPI2MOSI-8));
        RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;        // Enable SPI2 clock
    }
    
    if(spin == MYSPI3)
    {
        RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
        spi = SPI3;
        if(!(RCC->APB2ENR & RCC_APB2ENR_IOPBEN)) RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;        // Enable GPIOB clock
        GPIOB->CRL &= ~(0x0F<<(4*SPI3SCK) | 0x0F<<(4*SPI3MISO) | 0x0F<<(4*SPI3MOSI));    //Resert CRL_MODE and CRL_CNF register
        GPIOB->CRL |= 0x0A<<(4*SPI3SCK) | 0x04<<(4*SPI3MISO) | 0x0A<<(4*SPI3MOSI);    // 0x0A = Alternate function output Push-pull | Output mode, max speed 2 MHz
        AFIO->MAPR &= ~AFIO_MAPR_SPI3_REMAP;    // SPI no remap
        RCC->APB1ENR |= RCC_APB1ENR_SPI3EN;        // Enable SPI3 clock
    }
    
    
    spi->CR1 = 0x0000;    // Disable and reset SPI
    spi->CR1 |= SPI_CR1_SSM | SPI_CR1_SSI | 2<<3 | SPI_CR1_MSTR | SPI_CR1_CPHA;    // Bidirectional | 8 bit | Fclk/8 = 1 MHz | Master | CPOL = 0 | CPHA = 1
    spi->CR2 = 0x0000;    // Reset CR2
    spi->I2SCFGR = 0x00000000;    // Disable I2S mode
    spi->CR1 |= SPI_CR1_SPE;    // Enable SPI
}

 

Did I forget something?

 

Thank you
Freya

Outcomes