cancel
Showing results for 
Search instead for 
Did you mean: 

SPI Configuration Issue : NO DATA ON MOSI

michaelmichael9137
Associate II
Posted on June 04, 2013 at 16:41

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 mycode several time but I must be missing something. Here is the code :

//PINS SCREEN
#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

//GPIO SCREEN
#define GPIO_Screen GPIOB

//RCC SCREEN

#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_I2S_DeInit(SPI2);
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. #spi2-stm32f4-mosi
1 REPLY 1
Posted on June 04, 2013 at 19:10

I don't use the ''library'', but I suspect that you should be initializing the various ''init structs'' before using them.

JW