Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The SPI communication will need to be further configured. To configure it go to the .ioc file, find SPI1 in the Connectivity menu on the left:

...

The data size is the length of each message in bits, to make communication easier, set this to 8 bits.In the ADC datasheet there is information on controlling the ADC from the microcontroller in Sections Then, configure the parameters:

  • Data Size

  • First Bit

  • Clock Polarity

  • Clock Phase

To do so, do the following:

  1. Understand what each parameter does/means

  2. Look in the ADC datasheet under sections 5.0 and 6.1

...

Specifically check the following configuration parameters:

  • Clock polarity

  • If the ADC sends Most or Least significant bit first (MSB/LSB)

...

  1. to learn how the ADC communicates

  2. Draw conclusions and set appropriate values

Also, it is good to note that the MCU can run much faster than the ADC , so adding a prescaler and outpace it. Add a Prescaler of 16 or greater in the configuration of SPI1 will reduce the speed it needs to operate atto keep the baud rate reasonable for the ADC.

The Hal library automatically generates the base code required to run the configuration you set when you save the .ioc file. You do want the IDE to generate code for you.

...

  • Before main:

    • A place to declare constants, additional function prototypes, global variables

  • Inside main outside the while(1) loop:

    • A place for any setup or functions you want to run once before the loop

  • Inside the while loop:

    • Code that will be run repeatedly and often contains the main system behavior

    • Please add the following line here at the end of the user code section to ensure the MCU doesn’t overload the ADC:

      • HAL_Delay(10);

  • After main:

    • Where you write functions that match any function prototypes you have added

...

To find the functions you will use to send and read messages from the ADC, either find the stm32f0xx_hal_spi.h file in the Drivers->STM32F0xx_HAL_Driver->Inc directory and read the function prototypes at the bottom or visit the HAL User ManualFunction APIs and look for the SPI input and output functions (IO Operations).SPI starts from p450). Also, Google is a good learning resource, as there are so many people who give examples of how to use SPI to communicate between hardware.

It is good to note that this ADC requires full duplex mode SPI communication, meaning that information will be sent to the ADC and read from it at the same time. You will need to use the SPI function that can both send and receive data.

...

Don’t forget that the ADC requires specific behavior for the CS line that is connected to the GPIO pin you set. Information for controlling a GPIO pin can be found in the HAL User ManualFunction APIs (GPIO starts from p196).

Converting ADC value to PWM signal

...

For the Firmware team we follow a naming and code style guide to make our code more uniform and readable

...

Errors will be shown at the bottom of the screen. This will not catch behavior issues, just will catch compiler errors. The behavior will be checked by a firmware team member and later you may be able to come to the bay and run your code on the physical board.Once you believe your code is working and you get no errors or warnings you are ready to open a pull request to the “embedded-bootcamp” repo that you cloned the project from and message the #bootcamp Discord channel to ask someone to review it

Submission

Because this is the firmware subteam the code we write can control physical hardware. To submit this bootcamp you will be asked to have your code reviewed by a member of the team and when they are satisfied with it you can book a time to come into the WARG bay to test and debug your code on the physical setup.

To submit your work for review, create a pull request of your fork against the UWARG/embedded-bootcamp repository. Name your pull request Bootcamp: YOURNAME. Tell the responsible team lead that you've completed the bootcamp in the #Bootcamp Discord channel and they will have someone review your submission. You may be asked to revise some things.

General Hints

  • Look at the HAL_TIM_ and __HAL_TIM_ functions to access the timer. The HAL User Manual HAL Function APIs will be particularly useful here.

  • For SPI communication look at the SPI IO operation function in the HAL User Manual HAL Function APIs.

  • The electrical schematic is useful for determining which pins should be configured to which peripheral.

  • Don’t be shy to learn from Google or shoot your question in discord if any of the resource provided in this bootcamp document are not helping you.