1
\$\begingroup\$

While using HW SPI only for write purpose (only STM32 chip as master sends data through MOSI pin), is it possible to assign the MISO pin to general GPIO? I need it because the trace on PCB is already placed in this way.

In more details: the chip is STM32F103, HW SPI1 on pins PA5 (clock), PA6 (MISO) and PA7 (MOSI). The pin PA6 is traced for GPIO purposes on my PCB and needs to be used as output.

If I assign the MISO pin to GPIO output it still doesn't work. Looks like SPI still tries to use it within it's communication. In the code I use stm32duino within PlatformIO, but would appreciate any solution written in HAL or bare registers as well.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

The key is in SPI_CR1 bits 15 and 14, which, by my reading, you should set to 1 (bidirectional mode) and 1 (output enabled), respectively.

I'm not convinced it's correct (I think it isn't), but here is the MX tool's HAL setup for transmit-only master, which should leave PA6 free:

static void MX_SPI1_Init(void)
{
  /* SPI1 parameter configuration*/
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  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_128;
  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();
  }
}
\$\endgroup\$
1
  • \$\begingroup\$ Thanks you. Looks like what I need. Will be able to check later when I refactor the code to use HAL \$\endgroup\$
    – brigadir
    Commented May 22, 2023 at 0:58
1
\$\begingroup\$

Should be no issue, see screenshot. You can configure the SPI as Transmit Only Master.

Configuration

\$\endgroup\$
1
  • \$\begingroup\$ Yes, that's where the MX-generated configuration code in my answer came from, however the constants generated, at least in my version of the s/w (1.11.0), don't look correct when compared with the technical reference manual settings. \$\endgroup\$ Commented May 22, 2023 at 17:19

Your Answer

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

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