RFM12B on STM32 (STM32L476-Discovery board) – Part 1

In last post I managed to get two RFM12B module to communicate with MSP430. In this post I will make receiver using STM32L476-Discovery board.

Before You start this tutorial you need to know you need two of these boards or some other board which will be controlling the other RFM12B.

As usual we start by running CubeMX, select New project and start by selecting our microcontroller:

In the search box enter STM32L476VG, click on part in the list and click Start Project.

Once the project opens we need to configure a couple of peripherals:

  • SWD debug
  • clock
  • LCD driver
  • SPI1 – for RFM12B module communication
  • red and green LED

To configure DEBUG we need to select Serial Wire inside SYS peripheral:

We will be using external 32768Hz crystal oscillator (I intend to use this as a part of bigger project with low power). We need to select Crystal/Ceramic Resonator for LSE under RCC:

For LCD we need to select 1/4 duty cycle and select 24 segments (SEG35 to SEG22, SEG17, SEG15 to SEG12, SEG9, SEG8 , SEG5 to SEG3):

We also need to configure LCD hardware. Go to Configuration tab and click on LCD and set all values as screenshot below:

For SPI I used SPI1, since it is conveniently at the border of discovery board. We need to configure it as Full-Duplex Master:

We also need to configure SPI hardware. Click on SPI1 on Configuration tab and enter values as below:

For RFM12B we also need two more pins:

Pin PE12 and Pin PE10. We need to click on PE12 and select GPIO_Output:

We do same for PE10 but this time we select GPIO_Input.

We also need to label each pin of SPI. We right click on pin and select Enter User Label:

For PE12 we enter SPI1_nSEL:

and press Enter. We do this for ALL SPI1 pins, even the ones already labeled, otherwise we will get errors in SW4STM32.

We also need to set pull-up resistor for SPI1_nIRQ. We go to Configuration in CubeMX and click on GPIO:

We need to click on row with PE10 and select Pull-up under GPIO Pull-up/Pull-down selection and click OK:

We also need to configure outputs for LEDs:

We need to set PB2 and PE8 as GPIO_Outputs. And we need to label PB2 as RED_LED and PE8 as GREEN_LED.

Now we are ready for creating project. We click on menu Project -> Settings… -> enter name for our project and select SW4STM32 as our toolchain:

This time (and probably in future as well) I choose to have .c/.h pair of initialization for each peripheral. We select this under Code Generator inside Project setting in CubeMX:

 

Now we click Ok and select Project -> Generate Code:

After it finishes generating code it presents us with popup window whre we select Open Project:

This opens project inside SW4STM32 and here I will end this part and I will continue next time.

 

Thanks for reading!

Slemi