AnsweredAssumed Answered

How to calculate and set the SPI speed ?

Question asked by prieur.jean on Dec 19, 2013
Latest reply on Mar 12, 2014 by prieur.jean
Hello everybody,

I communicate with a popular screen, the DOGM128 (ST7565R LCD Controller) with my STM32F4 uC.

Sometimes, when I power on my board, the screen have troubles to be initialized (it remains white, whatever I do).

I think it's due to the SPI speed, that I can't estimate. The max SPI clock speed of the screen controller is 20MHz.

This is my SPI screen init :

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitTypeDef  GPIO_InitStructure;
 
// CLOCK and MOSI Pins declaration
GPIO_InitStructure.GPIO_Pin = PIN_SCL|PIN_SI;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
 
// CS pin
GPIO_InitStructure.GPIO_Pin = PIN_CS|PIN_A0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);

// SI & SCL = Alternate Functions
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);   
 

SPI_InitTypeDef SPI_InitStruct;
SPI_I2S_DeInit(SPI2);
SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;
SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStruct.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStruct);
SPI_Cmd(SPI2, ENABLE);

With SPI_BaudRatePrescaler_2 : The screen works almost everytime
With SPI_BaudRatePrescaler_4 : The screen works half the time
With SPI_BaudRatePrescaler_8 : The screen never works

So how can I increase the SPI speed, in order to try to solve my problem ?

Outcomes