cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-L4P5ZG to NRF52-DK SPI not working, but works with NUCLEO-F446RE.

AKuma.33
Associate II

Hi,

I am trying to use Nucleo-l4p5 as SPI Master and NRF52 as slave.

Issue : nrf is reading wrong and partial data and when I am connecting GND of both boards, it stops working.

Solutions tried so far:

  1. I have tried the same code with Nculeo-F446RE and NRF52-DK:
    1. It is sending wrong and partial data, GND not common between boards.
    2. It works as expected with GND common.
  2. I have tried Nucleo-l4p5(Master) to Nucleo-l4p5(Slave), with GND connected. It works as expected.
  3. I have tried powering One board with another, but again freezing issue.
  4. I have tried lowering the master clock.

// ST master code
  while (1)
  {
 
	  if (count%2 == 1)
	  {
	  	  memset(buffer1, buffer1, 6);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_RESET);
		  HAL_Delay(10);
		  HAL_SPI_Transmit(&hspi3, &buffer1, 6, 100);
		  HAL_Delay(10);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_SET);
	  }
	  else
	  {
		  memset(buffer1, buffer1, 6);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_RESET);
		  HAL_Delay(10);
		  HAL_SPI_Transmit(&hspi3, &buffer1, 6, 100);
		  HAL_Delay(10);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_SET);
	  }
	  count++;
	  HAL_Delay(1000);

Clock is configured for PCLK1(60) and PCLK2(120)

This is the configuration:

static void MX_SPI3_Init(void)
{
 
  /* USER CODE BEGIN SPI3_Init 0 */
 
  /* USER CODE END SPI3_Init 0 */
 
  /* USER CODE BEGIN SPI3_Init 1 */
 
  /* USER CODE END SPI3_Init 1 */
  /* SPI3 parameter configuration*/
  hspi3.Instance = SPI3;
  hspi3.Init.Mode = SPI_MODE_MASTER;
  hspi3.Init.Direction = SPI_DIRECTION_2LINES;
  hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi3.Init.NSS = SPI_NSS_SOFT;
  hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi3.Init.CRCPolynomial = 7;
  hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  if (HAL_SPI_Init(&hspi3) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN SPI3_Init 2 */
 
  /* USER CODE END SPI3_Init 2 */
 
}

3 REPLIES 3
TDK
Guru

GND needs to be common between the boards so they both have the same reference voltage.

What data do you receive and what data are you expecting instead?

> memset(buffer1, buffer1, 6);

What is this supposed to do?

If you feel a post has answered your question, please click "Accept as Solution".
AKuma.33
Associate II

Sorry for the typo, this is what I am sending:

  while (1)
  {
 
	  if (count%2 == 1)
	  {
	  	  memset(buffer1, 68, 6);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_RESET);
		  HAL_Delay(10);
		  HAL_SPI_Transmit(&hspi3, &buffer1, 6, 100);
		  HAL_Delay(10);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_SET);
	  }
	  else
	  {
		  memset(buffer1, 65, 6);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_RESET);
		  HAL_Delay(10);
		  HAL_SPI_Transmit(&hspi3, &buffer1, 6, 100);
		  HAL_Delay(10);
		  HAL_GPIO_WritePin(cs_port, cs_pin, GPIO_PIN_SET);
	  }
	  count++;
	  HAL_Delay(1000);
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }

This is what I get at Receiving side:

<info> app:  Transfer completed. Received: DDD
<info> app:  Transfer completed. Received: ADD
<info> app:  Transfer completed. Received: AAA
<info> app:  Transfer completed. Received: AAAAA
<info> app:  Transfer completed. Received: AAAAAA
<info> app:  Transfer completed. Received: DDAAAA
<info> app:  Transfer completed. Received: DDDDDA

The issue is I am not able to check operation while GND common, as I stop getting data at all.

Do 144-pin Nucleo boards have Isolated supplies or something?

TDK
Guru

If connecting GND breaks things, there is a hardware issue somewhere. Since the SPI signal is low a 0V and high at 3.3V, you need to ensure both parties have the save 0V reference. I do not believe any Nucleo boards have isolated supplies. Easy enough to check with a multimeter.

How do you know the issue isn't on the slave side? Can you put a logic analyzer on the lines to inspect data coming out?

I would wager your (new) code is correct and the issue is elsewhere.

If you feel a post has answered your question, please click "Accept as Solution".