AnsweredAssumed Answered

SPI Configuration Issue : NO DATA ON MOSI

Question asked by rebeat.pete on Jun 4, 2013
Latest reply on Jun 4, 2013 by waclawek.jan
Hi everyone and thanks in advance for your help,

I'm going a little crazy here. I am trying to configure an SPI2 line, in master mode, to send data from my STM32F407VG to an LCD screen. However, even if I can see the clock with an oscilloscope on SCK port, I can't manage to see any data on my MOSI port. I checked my code several time but I must be missing something. Here is the code : 
#define PIN_CS         GPIO_Pin_10
#define PIN_A0         GPIO_Pin_12
#define PIN_SCL        GPIO_Pin_13
#define PIN_SI         GPIO_Pin_15
#define PIN_Source_CS         GPIO_PinSource10
#define PIN_Source_A0         GPIO_PinSource12
#define PIN_Source_SCL        GPIO_PinSource13
#define PIN_Source_SI         GPIO_PinSource15

#define GPIO_Screen    GPIOB

#define RCC_Screen     RCC_AHB1Periph_GPIOB
The define section where SCL is Clock, SI is Serial Data and CS is slave select.

void RCC_Configuration(void)
    // Enable RCC for the screen
    RCC_AHB1PeriphClockCmd(RCC_Screen, ENABLE);
    // Activation de la clock du peripherique SPI
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
void GPIO_Configuration(void)
    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_50MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
    GPIO_Init(GPIO_Screen, &GPIO_InitStructure);
    // A0 and CHIP_SELECT Pins declaration
    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_50MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIO_Screen, &GPIO_InitStructure);

    //Connection des pins SI et SCL de l'écran aux Alternate Functions
    GPIO_PinAFConfig(GPIO_Screen, PIN_Source_SCL, GPIO_AF_SPI2);
    GPIO_PinAFConfig(GPIO_Screen, PIN_Source_SI, GPIO_AF_SPI2);
The GPIO and RCC initialisation section.

void SPI2_Configuration()
    // ________________INITIALISATION DE LA LIAISON SPI___________________
    // Configure SPI1 in Mode 0 :
    // CPOL = 0 --> clock is low when idle
    // CPHA = 0 --> data is sampled at the first edge
    // Initialisation de la structure du SPI2
    SPI_InitTypeDef SPI_InitStruct;
    SPI_InitStruct.SPI_Direction = SPI_Direction_1Line_Tx; // Reglage d'une ligne de transmission simple, MOSI uniquement
    SPI_InitStruct.SPI_Mode = SPI_Mode_Master;     // Transmission en mode maitre, CS doit etre toujours au niveau bas
    SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b; // Un paquet contient 8 bits
    SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;        // Horloge au niveau bas par défaut
    SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;      // Donnee samplee sur le premier front
    SPI_InitStruct.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Reset; // Reglage du Chip Select en interne et forcage au niveau bas
    SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; // La frequence du SPI est APB2 frequency / 4
    SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;// La donnee est transferee avec le MSB en premier
    SPI_Init(SPI2, &SPI_InitStruct);
    SPI_Cmd(SPI2, ENABLE); // enable SPI2
void SPI2_send(uint8_t data)
    SPI2->DR = data; // write data to be transmitted to the SPI data register
    while( !(SPI2->SR & SPI_I2S_FLAG_TXE) ); // wait until transmit complete
And finally the initialisation of the SPI and it's send function.

I kept in this code the most essential functions, and I can't see why it isn't working. Do you have any suggestion? Thank you VERY much.