STM32F1 - Using master SPI on bare metal


I've been trying to port some of my AVR code to drive a simple SPI LCD to ARM as a learning exercise (I'm very new to ARM in general). For this I just need to use SPI in master mode.

I looked in the <a href="http://www.st.com/resource/en/datasheet/stm32f103c8.pdf" rel="nofollow">datasheet</a> for my device (STM32F103C8) and found that the SPI1 pins I need, SCK and MOSI are mapped as alternative functions of PA5 and PA7, respectively, along with other peripherals (pg.29). My understanding is that in order to use the SPI function on these pins, I need to make sure that anything else mapped to the same pin is disabled. When looking at the defaults for the peripheral clock control register, however, it looks like the other features are already disabled.

I looked at the SPI section in the <a href="http://www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf" rel="nofollow">reference manual</a>, including section <em>25.3.3 - Configuring the SPI in master mode</em>. First I enabled the SPI1 master clock in APB2ENR and followed the steps in this section to configure SPI1 to my needs. I also changed the settings for PA5/7 to set their mode to "Alternate Function Output push-pull" (9.1.4). Finally, I enabled SPI1 by setting CR1_SPE.

From my reading, I had thought that by loading a value into the SPI1 data register after configuring SPI as above, the data would be shifted out. However, after writing the data, the TXE flag in the SPI status register never becomes set, indicating that the data I wrote into it is just sat there.

At this point, I'm assuming that there is something else I've failed to configure correctly. For example, I'm not 100% sure about what to do with the PA5/7 pins. I've tried to understand what I can from the datasheets, but I'm not getting anywhere. Is there anything else that needs to be done before it'll work?


I'm almost certain that you did not set SSM and SSI bits in SPIx->CR1 register. SPI in these chips is pretty simple, for the polled transfers you need to set SSM, SSI, SPE, MSTR, correct format (LSBFIRST, CPOL, CPHA) and proper baudrate (BR) in SPIx->CR1 and you're good to go.


  • Undefined reference to main when using Real-Time For the Masses
  • iOS CoreBluetooth reconnecting device with UUID
  • Ignoring standard and boost libraries while debugging with GDB
  • How to send RGB signal to BLE device using iPhone application?
  • CoreBluetooth: Attempt to write to device
  • Using BLE between devices with React Native
  • Postgresql: Invalid regular expression: invalid backreference number
  • To use other table as a WHERE criteria in SQL
  • How can I launch the Alarms App through a Universal Windows App
  • Fibonacci Computation Time
  • VHDL - iSIM output uninitialised, doesn't change states
  • Scroll down whole browser window
  • StackExchange API - Deserialize Date in JSON Response
  • Gatttool non-interactive mode --char-write
  • How to make a post call to a Web Api Action?
  • F# NativePtr.stackalloc Unexpected Stack Overflow
  • Detecting both left and right mouse movement and no movement
  • How can I allow tags through rails 4 sanitize?
  • Simple test app deploys to Heroku but won't run
  • Does argparse support multiple exclusive arguments?
  • Does Context/Scoping of a SQLAlchemy Session Require Non-Automatic Object/Attribute Expiration?
  • How to generate an asynchronous reset verilog always blocks with chisel
  • How to check if DIV element is disabled using jquery
  • DependencyObject.AssociatedObject is always null
  • IE11 textarea loses focus if another textarea is disabled
  • Curried UDF - Pyspark
  • Excel distinct count with conditions
  • How can I reset dropdown data if modal closed on vue component?
  • jersey/tomcat Description The origin server did not find a current representation for the target res
  • Magento get URL before current
  • How do I remove all but some records based on a threshold?
  • How to getText() from the input field of an angularjs Application
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Installing iPhone App to iPhone
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • The plugin 'org.apache.maven.plugins:maven-jboss-as-plugin' does not exist or no valid ver
  • QLineEdit password safety
  • Nant, Vault & Windows Integrated Authentication
  • Bug in WPF DataGrid
  • jQuery tmpl and DataLink beta
  • How can I estimate amount of memory left with calling System.gc()?
  • apache spark aggregate function using min value