Direct register access on STM32 F302R8

Hi im verry new to the world of micro controllers so sorry my questions are very basic.

im looking to connect to a rotary encoder for a motor driver but it has an SSI interface. ive writen a script that interprets SSI on a raspberry pi but in need to move it over to the STM F302R8 board. the script uses "bit banging" pins high and low for error checking and ensuring i'm reading the correct signal. using digital write is to slow (1 micro second)

i was wondering if anyone had a sort of guide to direct register access to help me understand it better and point me towards how to do it.

Also is there an equivalent process for reading pins?

Thanks for any help.

Hello and welcome.

I'm confused by you saying your question is very basic, it is not the kind of question I'd call basic, more like advanced.

Read the data sheet for the processor. The registers have names, those names will correspond to variable names when you write code, so if you want to write 0x01 to the TTR (I made that up) register you just use:

TTR = 0x01;

As to what the registers do and how you get them to do it the data sheet will tell you.

I've never done this, but as I understand it might be possible to 'abuse' SPI for this purpose (with the additional of some fairly trivial hardware). See here: https://www.posital.com/media/posital_media/documents/AbsoluteEncoders_Context_Technology_SSI_AppNote.pdf

Assuming that you are in the Arduino IDE and use pinMode() to set the pins to the appropriate direction, you should be able to to access the "direct port registers" with code like:

  GPIOA->ODR |= 0x20;   // set bit using logic to Output Data Register
  GPIOA->ODR &= ~0x20;        // clear bit using logic

  GPIOA->BSRR = 0x20;   // Set bit atomically via set/reset register
  GPIOA->BRR = 0x20;    // clear bit atomically via reset register.

  bool pin5 = !!(GPIOA->IDR & (1<<5));  // read pin via input data register.

(You'll have to translate "Arduino pin numbers" to STM32 Port/Bit manually, as appropriate for your board, I guess.)

There is an educational company that has a bunch of classes centered around programming the the ST ARM microcontrollers. They have some "freebies" that are ... not bad at all, especially in that they provide extensive references to the datasheets for each line of code. Worth giving them your info and putting up with some subsequent advertisements for their for-pay classes, IMO...

(Those are actually for STM32F4xx, but should be equally applicable to STM32F3xx)

1 Like

You may wish asking over on STM32duino.com if you decide to continue with Arduino. STM has a fully supported ArduinoIDE core, see GitHub:
GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino

This repo adds the support of STM32 MCU in Arduino IDE.
This porting is based on:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.