0
\$\begingroup\$

Two boards: arduino nano and stmvldiscovery. Boards are connected by spi interface. Arduino is master device. Stm32vldiscovery is slave device. In the txBuf (transmit buffer) both board have the same data - uint8_t array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10).

Both board send same data. Logic analyzer captured wrong data from stm32vldiscovery. I don't know why...

Both board have spi settings: arduino: msbfirst, freq = 1Mhz, spi_mode_0, 8 bit data; stm32: msbfirst, cpol = 0, cpha = 0, motorola frame format, same freq;

I tried set hardware/software NSS control for stm32. It haves same result. Same result I had with two boards - stm32f4-discovery and stm32vldiscovery. stm32vldiscovery was slave device same.

Why? What's wrong?

Yellow is arduino. Green is stm32. enter image description here

stm32 code:

#include "main.h"
SPI_HandleTypeDef hspi1;

uint8_t txBuff[10];
uint8_t rxBuff[10];

void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);

int main(void)
{

  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_SPI1_Init();

  for(int i = 0; i < 10; i++)
  {
    txBuff[i] = i+1;
    rxBuff[i] = 0;
  }

  while (1)
  {
    HAL_SPI_TransmitRecieve(&hspi1, txBuff, rxBuff, 10, 10000);
  }

}
...
static void MX_SPI1_Init(void)
{
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_SLAVE;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi1.Init.NSS = SPI_NSS_SOFT;
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 10;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    Error_Handler();
  }
}

Arduino code:

#include <SPI.h>


void setup()
{
    SPI.begin();
}

void loop()
{
    delay(5000);
    SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
    byte arr[10];
    for (int i = 0; i < 10; i++)
        arr[i] = i + 1;

    digitalWrite(SS, LOW);

    for (int i = 0; i < 10; i++)
        SPI.transfer(arr[i]);

    digitalWrite(SS, HIGH);
    SPI.endTransaction();
}
\$\endgroup\$
3
  • 1
    \$\begingroup\$ As for any debugging question, you must include code sufficient to demonstrate the problem. \$\endgroup\$ May 15, 2019 at 17:36
  • \$\begingroup\$ Looks like you have your STM32 configured for a different SPI mode to the Arduino. \$\endgroup\$
    – brhans
    May 15, 2019 at 17:43
  • \$\begingroup\$ brhan, maybe, but why two stm32 with same configuration have same problems? \$\endgroup\$
    – Noisy88
    May 15, 2019 at 17:50

1 Answer 1

0
\$\begingroup\$

Today I replaced stm32vldiscovery board to stm32f4-discovery and it works fine! I think problem was in stm32vldiscovery board. Stm32vldiscovery board works badly in this mode. I can't find nothing other reasons. enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.