SPI communication between two STM32 gives different values after reset button pressed
Hi, i'm using SPI to communicate two STM32F446RE
Unfortunately, I get different value after the reset button pressed. Due to some other reasons, these two 446RE use LL and opencm3, but I don't think it is an issue.
The code for master in one of the 446RE (LL):
LL_SPI_InitTypeDef SPI_InitStruct;
LL_GPIO_InitTypeDef GPIO_InitStruct;
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_SPI3);
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
GPIO_InitStruct.Pin = SPI3_SCK_PIN | SPI3_MISO_PIN | SPI3_MOSI_PIN;
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_6;
LL_GPIO_Init(SPI3_PORT, &GPIO_InitStruct);
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_HIGH;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_2EDGE;
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
LL_SPI_Init(SPI3, &SPI_InitStruct);
LL_SPI_Enable(SPI3);And the slave on the other 446RE (opencm3):
rcc_periph_clock_enable(RCC_SPI3);
rcc_periph_clock_enable(RCC_GPIOB);
nvic_enable_irq(NVIC_SPI3_IRQ);
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3 | GPIO4 | GPIO5);
gpio_set_af(GPIOB, GPIO_AF6, GPIO3 | GPIO4 | GPIO5);
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO10);
spi_set_slave_mode(SPI3);
spi_set_baudrate_prescaler(SPI3, SPI_CR1_BR_FPCLK_DIV_8);
spi_set_full_duplex_mode(SPI3);
spi_set_clock_polarity_1(SPI3);
spi_set_clock_phase_1(SPI3);
spi_set_dff_8bit(SPI3);
spi_send_msb_first(SPI3);
spi_enable_software_slave_management(SPI3);
spi_enable_rx_buffer_not_empty_interrupt(SPI3);
spi_enable(SPI3);Both 446RE have the same clock speed , 180MHz, and same pre-scaler.
I send some value for test:
int main(void)
{
all setups.....
while(1)
{
LL_SPI_TransmitData8(SPI3, 20);
}
}and for slave part
volatile int i = 0;
void spi3_isr(void)
{
i = spi_xfer(SPI3, 0);
}and print the value in main.
The results:
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
160
<< after the reset button pressed
40
40
40
40
40
40
40
40
40
40
40
40
40
40
<< after the reset button pressed
130
130
130
130
130
130
130
130
130
130
130
130
130
130
130
130
130
130
<< after reset button pressed
20
20
20
20
20
20
20
20
20
20
20
20
20
20Which is different every time the reset button is pressed, however, during each time, the value just never changes.
Any help or advice will be great, thanks in advance!
