cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F767 and SPI communication without DMA

Pilous Droip
Senior
Posted on May 30, 2018 at 08:34

Hello friends,

I try SPI communication, and I have a problem. I only send data.... But how to receive it?

Connection is:

1. one master - one slave

2. Full duplex

Initialize:

LL_SPI_InitTypeDef SPI_InitStruct;

LL_GPIO_InitTypeDef GPIO_InitStruct;

LL_SPI_Disable(SPI1);

LL_AHB1_GRP1_EnableClockLL_AHB1_GRP1_PERIPH_GPIOA);

LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);

/* SPI2 GPIO Configuration */

GPIO_InitStruct.Pin = LL_GPIO_PIN_5;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

GPIO_InitStruct.Alternate = LL_GPIO_AF_5;

LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = LL_GPIO_PIN_7;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

GPIO_InitStruct.Alternate = LL_GPIO_AF_5;

LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = LL_GPIO_PIN_6;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

GPIO_InitStruct.Alternate = LL_GPIO_AF_5;

LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = LL_GPIO_PIN_4;

GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;

GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;

GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;

GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

GPIO_InitStruct.Alternate = LL_GPIO_AF_5;

LL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* SPI1 parameter configuration*/

SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;

SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;

SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;

SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH;

SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;

SPI_InitStruct.NSS = LL_SPI_NSS_HARD_OUTPUT;

SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV64;

SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;

SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;

SPI_InitStruct.CRCPoly = 7;

LL_SPI_Init(SPI1, &SPI_InitStruct);

LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);

LL_SPI_EnableNSSPulseMgt(SPI1);

LL_SPI_SetRxFIFOThreshold(SPI1, LL_SPI_RX_FIFO_TH_QUARTER);

/* Configure SPI1 transfer interrupts */

/* Enable RXNE Interrupt */

LL_SPI_EnableIT_RXNE(SPI1);

LL_SPI_Enable(SPI1);

And function to write/read....

int32_t read_from_reg(SPI_TypeDef *SPI, uint8_t data, uint8_t *SPI_Data_receive)

{

LL_SPI_TransmitData8(SPI, data);

while (!LL_SPI_IsActiveFlag_TXE(SPI));

while (!LL_SPI_IsActiveFlag_RXNE(SPI));

while (LL_SPI_IsActiveFlag_BSY(SPI));

*SPI_Data_receive = LL_SPI_ReceiveData8(SPI);

return 0;

}

And I sent one byte and I don't receive anything. Any idea, how to receive some data from register?

#nucleo-f767zi #stm32f7-spi

Note: this post was migrated and contained many threaded conversations, some content may be missing.
20 REPLIES 20
Linas L
Senior II

Hey. If it has 4 words fifo, how can i send only one or two data packets ? :(