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

In previous post we configured and created base for our project. In this post we will start receiving data.

Our project is imported in SW4STM32 and is in the list of already made projects (note I named it wrong):

We need driver files for LCD from CubeMX repository. First we need to create inc and src folders for them. We need to click on Drivers folder inside our project Select New and Folder:

And iside we need to create src and inc folders:

We need to go to C:\Users\…\STM32Cube\Repository\STM32Cube_FW_L4_V1.11.0\Drivers\BSP\STM32L476G-Discovery. From here we copy:

  • to src folder:
    • stm32l476g_discovery.c
    • stm32l476g_discovery_glass_lcd.c
  • to inc folder:
    • stm32l476g_discovery.h
    • stm32l476g_discovery_glass_lcd.h

We also need to right click on project and select Properties. Here we need to go to C/C++ General -> Paths and Symbols -> Includes, select GNU C and add two paths:

  • Drivers/BSP/inc
  • Drivers/BSP/src

If you have multicore processor in your system you can select another setting for faster compiling. Go to C/C++ Build, select Behavior and enable parallel build. Here you best select Use optimal jobs and it will use each processor core to compile one file in parallel, it doesn’t speed up process if you select more parallel jobs than you have processor cores:

Now click OK.

To be able to compile and use this tutorial you will need two files, main.c and rfm12b_slemi.h. Yo can get them here compressed with 7zip.

Copy rfm12b_slemi.h into inc folder in root of the project and copy contents of this main.c into main.c in your project:

Now we are ready to compile and upload code into our microcontroller. This is the receiver code for microcontroller. I have transmitter from previous project with MSP430. If you want to have this project to be transmitter you need to comment out receiver part and uncomment the rest of code:

Also on line 110 comment out rf12_write_cmd(RF_RX_ON):

Don’t forget that FIFOReset();, it took me three days to figure out, why less that half the data came through!!!

Also inside RFM12B_slemi.h you need to change line 50 inside rf12_init function to RF_TX_ON:

This will make this board transmitter.

This tutorial is actually more of overview of my project, since it involves other hardware to be able to do it. What you need to use from here is SPI initialization and to see how the function HAL_SPI_TransmitReceive need to be called that it communicates with RFM12B.

Thank You for reading!

Slemi

 

P.S.: If you found this helpful, I would appreciate clicking on Ad on the right side to give me a little “motivation”. 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *