Skip to main content
Mike Thomas
Associate
August 28, 2018
Question

Issue to use SPI1 with port B GPIOs

  • August 28, 2018
  • 1 reply
  • 537 views

Hello All,

What is the secret to enabling SPI1 on PortB GPIO? Attached code below works fine on GPIOA bits PA5 and PA7

Any ideas?

Thanks in advance,

Mike

Lifting the example straight from the reference manual....

// Configure PortA bits 5 and 7 for alternate function (spi)

GPIOA->MODER  |= 0x00008800; // PortA bits 5 and 7

GPIOA->OSPEEDR |= 0x0000cc00;

SPI1->CR1 = SPI_CR1_MSTR | SPI_CR1_BR; /* (1) */

SPI1->CR2 = SPI_CR2_SSOE | SPI_CR2_RXNEIE | SPI_CR2_FRXTH | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0; /* (2) */

SPI1->CR1 |= SPI_CR1_SPE; /* (3) */

This works perfectly.

However, using PB3 and PB5, configured similarly...

// Configure PortB bits 3, and 5 for alternate function (spi)

GPIOB->MODER  |= 0x00000880;

GPIOB->OSPEEDR |= 0x00000cc0; 

... I get no clock and no data. It appears the SCK line is hi-z.

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
August 28, 2018

Did you enable the GPIOB clock?

If you inspect the registers in the debugger what do you see?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..