AnsweredAssumed Answered

No SPI clock - STM32F407

Question asked by mckendree.nicholas on Oct 7, 2015
Latest reply on Oct 7, 2015 by Clive One
I am having trouble getting SPI2 to function on my STM32F407 board. My issue is that I am seeing data on the MOSI pin with a logic analyzer but there is no clock activity (it is low). My processor is clocked at 168MHz and APB1 is set 42MHz. Below is the function that I am using to configure the module.

void initOLED_Spi(void)
{
SPI_InitTypeDef OLED_SpiInitStruct;
GPIO_InitTypeDef SpiGPIO_InitStructure;
//CONFIGURE THE GPIO PINS B12, B13, B14, AND B15 FOR SPI
/*  B12 = CS = SSD1306_CS_PIN
 *  B13 = SCK = SSD1306_CLK_PIN
 *  B14 = MISO = SSD1306_MISO_PIN
 *  B15 = MOSI = SSD1306_MOSI_PIN
 */
 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
//Enable the SPI2 Peripherial clock
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
 
//CONFIGURE THE CS LINE
GPIO_StructInit(&SpiGPIO_InitStructure);
SpiGPIO_InitStructure.GPIO_Pin = SSD1306_CS_PIN;
SpiGPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
SpiGPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
SpiGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
SpiGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOB, &SpiGPIO_InitStructure);
GPIO_SetBits(GPIOB, SSD1306_CS_PIN);
 
//CONFIGURE SCK AND MOSI
GPIO_StructInit(&SpiGPIO_InitStructure);
SpiGPIO_InitStructure.GPIO_Pin = (SSD1306_CLK_PIN | SSD1306_MOSI_PIN);
SpiGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
SpiGPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
SpiGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
SpiGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOB, &SpiGPIO_InitStructure);
 
GPIO_StructInit(&SpiGPIO_InitStructure);
SpiGPIO_InitStructure.GPIO_Pin = SSD1306_MISO_PIN;
SpiGPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
//SpiGPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
SpiGPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
SpiGPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init( GPIOB, &SpiGPIO_InitStructure);
 
//SET THE GPIO TO SPI ALTERNATE
GPIO_PinAFConfig(GPIOB, (GPIO_PinSource15 | GPIO_PinSource13 | GPIO_PinSource14), GPIO_AF_SPI2);
 
//SETUP THE PORT
SPI_StructInit( &OLED_SpiInitStruct);
OLED_SpiInitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
OLED_SpiInitStruct.SPI_Mode = SPI_Mode_Master;
OLED_SpiInitStruct.SPI_DataSize = SPI_DataSize_8b;
OLED_SpiInitStruct.SPI_CPOL = SPI_CPOL_High;
OLED_SpiInitStruct.SPI_CPHA = SPI_CPHA_2Edge;
OLED_SpiInitStruct.SPI_NSS  = SPI_NSS_Soft;
OLED_SpiInitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_32;
OLED_SpiInitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
 
SPI_Init( SPI2, &OLED_SpiInitStruct);
SPI_Cmd(SPI2, ENABLE);
}

Then I am using the following code to try and generate data on the SPI port:

GPIO_ResetBits(GPIOB, SSD1306_CS_PIN);
SPI_I2S_SendData(SPI2 , 0xAA);
GPIO_SetBits(GPIOB, SSD1306_CS_PIN);


For what it is worth I am using CooCox and I am using their libraries as I was having issues with the HAL library and Keil / CooCox. 

Thanks!

Outcomes