Intermediate
30 min
0

Capture motion data in three dimensions with BMA456 and STM32F302VC

Learn how accelerometers revolutionize our world

Accel 11 Click with Fusion for STM32 v8

Published Oct 05, 2023

Click board™

Accel 11 Click

Development board

Fusion for STM32 v8

Compiler

NECTO Studio

MCU

STM32F302VC

By detecting gravitational forces, accelerometers aid in determining an object's orientation with respect to Earth's gravitational field, providing valuable information for navigation and alignment applications

A

A

Hardware Overview

How does it work?

Accel 11 Click is based on the BMA456, a digital triaxial acceleration sensor from Bosch Sensortec. This sensor has many features ideally suited for wearables, handheld, and IoT applications, offering a good balance between the performance and the power consumption. One of its key features is its extremely low power consumption, which makes it perfectly suited for such applications. There are several power modes that the BMA456 device can use. While in Low Power mode, the device consumes the least power, but access to some features is restricted. More information can be found within the BMA456 datasheet. The BMA456 sensor can measure acceleration within ranges of ±2 g, ±4 g, ±8, and ±16 g. It can output the measurement data using the Output Data Rate (ODR) from 0.78Hz (Low Power mode) up to 1600Hz (Performance mode). A high-precision analog front end facilitates highly sensitive MEMS, featuring a 16-bit A/D Converter. It allows very high output accuracy, even during low amplitude changes. This makes the sensor particularly sensitive and accurate with movements that

generate relatively low acceleration signals. However, using a highly sensitive MEMS makes the BMA456 prone to damage caused by extremely high g-forces (10,000g for less than 200µs). Acceleration data is available in 16-bit format from the data registers and the internal FIFO buffer of 1kb. The FIFO buffer can be used for more complex calculations or timed readings, reducing the traffic on the communication interface. The interrupt engine facilitates the FIFO buffer, triggering an interrupt for two FIFO events: the watermark event and the FIFO buffer full event. FIFO buffer allows optimization within the firmware that runs on the host MCU. Besides the acceleration MEMS and complementary analog front-end circuit, the BMA456 sensor has an integrated temperature sensor. It is updated every 1.2s and sampled to an 8-bit value (complement of 2’s format). Interrupts can be triggered for many different events. Some basic events include the data-ready interrupt event and aforementioned FIFO events, while so-called feature engines can trigger an interrupt for any of the detected

motion/movement events, including step detection/counter, activity recognition, tilt on the wrist, tap/double tap, any/no motion, and error event interrupt. The extensive interrupt engine can use two programmable interrupt pins. Depending on settings in appropriate registers, these pins can be assigned with any interrupt source and can be either LOW or HIGH on interrupt. These two pins are routed to the INT and AN pin of the mikroBUS™ and are labeled IT1 and IT2, respectively. Accel 11 click offers two communication interfaces. It can be used with either I2C or SPI. The onboard SMD jumpers labeled COMM SEL allow switching between the two interfaces. Note that all the jumpers must be positioned in the I2C or SPI position. When the I2C interface is selected, an additional SMD jumper labeled ADDR SEL becomes available, determining the least significant bit of the BMA456 I2C address. The Click board™ should be interfaced only with MCUs that use logic levels of 3.3V.

Accel 11 Click top side image
Accel 11 Click bottom side image

Features overview

Development board

Fusion for STM32 v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports a wide range of microcontrollers, such as different 32-bit ARM® Cortex®-M based MCUs from STMicroelectronics, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer over WiFi. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, Fusion for STM32 v8 provides a fluid and immersive working experience, allowing

access anywhere and under any circumstances at any time. Each part of the Fusion for STM32 v8 development board contains the components necessary for the most efficient operation of the same board. An advanced integrated CODEGRIP programmer/debugger module offers many valuable programming/debugging options, including support for JTAG, SWD, and SWO Trace (Single Wire Output)), and seamless integration with the Mikroe software environment. Besides, it also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB HOST/DEVICE, CAN (on the MCU card, if supported), and Ethernet is also included. In addition, it also has the well-established mikroBUS™ standard, a standardized socket for the MCU card (SiBRAIN standard), and two display options for the TFT board line of products and character-based LCD. Fusion for STM32 v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Fusion for STM32 v8 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Type

8th Generation

Architecture

ARM Cortex-M4

MCU Memory (KB)

256

Silicon Vendor

STMicroelectronics

Pin count

100

RAM (Bytes)

40960

Used MCU Pins

mikroBUS™ mapper

Interrupt 1
PC0
AN
NC
NC
RST
SPI Chip Select
PE8
CS
SPI Clock
PA5
SCK
SPI Data OUT
PA6
MISO
SPI Data IN
PA7
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt 2
PE13
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PA9
SCL
I2C Data
PA10
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

Accel 11 Click Schematic schematic

Step by step

Project assembly

Fusion for PIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Fusion for STM32 v8 as your development board.

Fusion for PIC v8 front image hardware assembly
Buck 22 Click front image hardware assembly
SiBRAIN for PIC32MZ1024EFK144 front image hardware assembly
v8 SiBRAIN MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for Accel 11 Click driver.

Key functions:

  • accel11_get_axis_data - This function reads accel axis

  • accel11_test_comunication - This function test comunication

  • accel11_power_on_procedure - This function for power on chip

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * \file 
 * \brief Accel11 Click example
 * 
 * # Description
 * This demo application reads X / Y / Z axis acceleration data.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initialization device.
 * 
 * ## Application Task  
 * Reads X / Y / Z axis acceleration data and it logs to USBUART every 1500ms.
 * 
 * \author MikroE Team
 *
 */

// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "accel11.h"

// ------------------------------------------------------------------ VARIABLES

static accel11_t accel11;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    uint8_t tmp;
    log_cfg_t log_cfg;
    accel11_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    accel11_cfg_setup( &cfg );
    ACCEL11_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    accel11_init( &accel11, &cfg );

    tmp = accel11_test_comunication( &accel11 );
    if ( tmp == ACCEL11_TEST_COMUNICATION_OK )
    {
        log_printf( &logger, " Comunication OK !!!\r\n" );
    }
    else
    {
        log_printf( &logger, " Comunication ERROR !!!\r\n" );
        for ( ; ; );
    }
    accel11_default_cfg( &accel11 );
}

void application_task ( void )
{
    int16_t x_axis;
    int16_t y_axis;
    int16_t z_axis;

    x_axis = accel11_get_axis_data( &accel11, ACCEL11_ACCEL_X_AXIS );
    log_printf( &logger, " X axis : %d\r\n", x_axis );

    y_axis = accel11_get_axis_data( &accel11, ACCEL11_ACCEL_Y_AXIS );
    log_printf( &logger, " Y axis : %d\r\n", y_axis );

    z_axis = accel11_get_axis_data( &accel11, ACCEL11_ACCEL_Z_AXIS );
    log_printf( &logger, " Z axis : %d\r\n", z_axis );

    log_printf( &logger, "---------------------------------\r\n" );
    Delay_ms( 1500 );
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources