AnsweredAssumed Answered

[solved] STM32L151UC: SPI3 problem - no activity on pins

Question asked by Selportion on Jun 15, 2015
Latest reply on Jun 15, 2015 by Selportion
Hello,

I am trying to configure the SPI3 port of an STM32L151UC micro controller. I have tried several things but I see no output on the related pins.
When using gpios instead of the AF of the SPI peripheral, I can control the pins and therefore verify that the hardware connections are ok. I would be satisfied to see the pins toggling, under any CPOL, speed, NSS, etc configuration. I have narrowed my tests down to a simple hello project as produced by the latest Eclipse version with GNU Cross Arm Gcc toolchain, adding only the peripheral drivers and device.h info. My debugger is J-Link pro, not that I think this matters.

An example code that reproduces the problem is:

void spi_conf(void){
    GPIO_InitTypeDef GPIO_InitStructure;
    SPI_InitTypeDef  SPI_InitStructure;

    RCC->APB1ENR = 0xffffffff;
    RCC->APB2ENR = 0xffffffff;
    RCC->AHBENR = 0xffffffff;
    RCC->APB1LPENR = 0xffffffff;
    RCC->APB2LPENR = 0xffffffff;
    RCC->AHBLPENR = 0xffffffff;

    //Or alternatively:
//RCC_APB2PeriphClockCmd ( RCC_APB2Periph_SYSCFG, ENABLE);
    //RCC_APB1PeriphClockCmd ( RCC_APB1Periph_SPI3, ENABLE);
    //RCC_AHBPeriphClockCmd ( RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE);

    SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
    SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b;
    SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
    SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
    SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
    SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
    SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
    SPI_InitStructure.SPI_CRCPolynomial = 7;
    SPI_Init(SPI3, &SPI_InitStructure);
    SPI_Cmd(SPI3, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_PinAFConfig(GPIOC,GPIO_Pin_10,GPIO_AF_SPI3);
    GPIO_PinAFConfig(GPIOC,GPIO_Pin_11,GPIO_AF_SPI3);
    GPIO_PinAFConfig(GPIOC,GPIO_Pin_12,GPIO_AF_SPI3);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET) ;
}
And then main.c calls this function followed by
      SPI_I2S_SendData  (SPI3, 0xa5);
      int SPI3val=SPI_I2S_ReceiveData(SPI3);
in a loop. But I see no activity in the HCLK or HMOSI. They do not go high even when I change the CPOL. The oscilloscope is '100MHz' so I would expect at least something. When I tried to poll the BSY, I saw that it takes some iterations until it is cleared, which would indicate that the peripheral is active.

Am I missing some configuration? I use the HSI clock, would I reach this point if something on the _initialize_hardware.c went wrong?

Grateful for any hint



Edit: Attached sample project including its compiled output

Attachments

Outcomes