| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

Classes | Typedefs | Functions | Variables
SPI_Master_w_Sensor_main.c File Reference

This code provides an example how to configure and to use the SPI master and communicate with the inertial sensor LSM6DS3. More...

`#include "BlueNRG1.h"`
`#include <stdio.h>`
`#include "BlueNRG1_conf.h"`
`#include "BlueNRG1_it.h"`
`#include "SDK_EVAL_Config.h"`
`#include "LSM6DS3.h"`
`#include "LSM6DS3_hal.h"`

Go to the source code of this file.

## Classes

struct | AxesAccRaw_TypeDef

## Typedefs

typedef struct AxesAccRaw_TypeDef | AxesGyrRaw_TypeDef

## Functions

int | main (void)
| Main program. More...

## Variables

volatile FlagStatus | GpioIrqFlag

## Detailed Description

This code provides an example how to configure and to use the SPI master and communicate with the inertial sensor LSM6DS3.

# ATOLLIC project

To use the project with ATOLLIC TrueSTUDIO for ARM, please follow the instructions below:

1. Open the ATOLLIC TrueSTUDIO for ARM and select File->Import... Project menu.
2. Select Existing Projects into Workspace.
3. Select the ATOLLIC project
4. Select desired configuration to build from Project->Manage Configurations
5. Select Project->Rebuild Project. This will recompile and link the entire application
6. To download the binary image, please connect STLink to JTAG connector in your board (if available).
7. Select Project->Download to download the related binary image.
8. Alternatively, open the BlueNRG1 GUI, put the board in bootloader mode and download the built binary image.

# KEIL project

To use the project with KEIL uVision 5 for ARM, please follow the instructions below:

1. Open the KEIL uVision 5 for ARM and select Project->Open Project menu.
2. Open the KEIL project `...\Project\BlueNRG1_Periph_Examples\SPI\Master_Polling\MDK-ARM\Master_Polling.uvprojx`
3. Select desired configuration to build
4. Select Project->Rebuild all target files. This will recompile and link the entire application
5. To download the binary image, please connect STLink to JTAG connector in your board (if available).
6. Select Project->Download to download the related binary image.
7. Alternatively, open the BlueNRG1 GUI, put the board in bootloader mode and download the built binary image.

# IAR project

To use the project with IAR Embedded Workbench for ARM, please follow the instructions below:

1. Open the Embedded Workbench for ARM and select File->Open->Workspace menu.
2. Open the IAR project `...\Project\BlueNRG1_Periph_Examples\SPI\Master_Polling\EWARM\Master_Polling.eww`
3. Select desired configuration to build
4. Select Project->Rebuild All. This will recompile and link the entire application
5. To download the binary image, please connect STLink to JTAG connector in your board (if available).
6. Select Project->Download and Debug to download the related binary image.
7. Alternatively, open the BlueNRG1 GUI, put the board in bootloader mode and download the built binary image.

## Project configurations

- `Dma` - The SPI is used through the DMA channel SPI TX and SPI RX
- `Interrupt` - The SPI is used through the SPI interrupt service routine
- `Polling` - The SPI is used in polling mode on status registers

# Boards supported

- `STEVAL-IDB007V1`

# Power configuration settings

STEVAL-IDB007V1
Jumper name |  | Description
JP1 | JP2 |
ON 1-2 | ON 2-3 | USB supply power
ON 2-3 | ON 1-2 | The supply voltage must be provided through battery pins.
ON 1-2 |  | USB supply power to STM32L1, JP2 pin 2 external power to BlueNRG1

# Jumper settings

STEVAL-IDB007V1
Jumper name | Description
JP1 | 1-2: to provide power from USB (JP2:2-3). 2-3: to provide power from battery holder (JP2:1-2)
JP2 | 1-2: to provide power from battery holder (JP1:2-3). 2-3: to provide power from USB (JP1:1-2). Pin2 to VDD to provide external power supply to BlueNRG-1 (JP1: 1-2)
JP3 | pin 1 and 2 UART RX and TX of MCU. pin 3 GND.
JP4 | Fitted: to provide VBLUE to BlueNRG1. It can be used also for current measurement.
JP5 | Fitted : TEST pin to VBLUE. Not fitted: TEST pin to GND

# Pin settings

| Interrupt | Dma | Polling
PIN name | STEVAL-IDB007V1 | STEVAL-IDB007V1 | STEVAL-IDB007V1
ADC1 | Not Used | Not Used | Not Used
ADC2 | Not Used | Not Used | Not Used
IO0 | SPI clock pin | SPI clock pin | SPI clock pin
IO1 | SPI chip select pin | SPI chip select pin | SPI chip select pin
IO11 | UART RX pin | UART RX pin | UART RX pin
IO12 | Interrupt from INT1 LSM6DS3 | Interrupt from INT1 LSM6DS3 | Interrupt from INT1 LSM6DS3
IO13 | Not Used | Not Used | Not Used
IO14 | Not Used | Not Used | Not Used
IO2 | SPI MOSI pin | SPI MOSI pin | SPI MOSI pin
IO3 | SPI MISO pin | SPI MISO pin | SPI MISO pin
IO4 | Not Used | Not Used | Not Used
IO5 | Not Used | Not Used | Not Used
IO6 | Not Used | Not Used | Not Used
IO7 | Not Used | Not Used | Not Used
IO8 | UART TX pin | UART TX pin | UART TX pin
TEST1 | Not Used | Not Used | Not Used

# Serial I/O

The application will listen for keys typed and it will send back in the serial port. In other words everything typed in serial port will be send back.

Parameter name | Value | Unit
Baudrate | 115200 [default] | bit/sec
Data bits | 8 | bit
Parity | None | bit
Stop bits | 1 | bit

# LEDs description

| Interrupt | Dma | Polling
LED name | STEVAL-IDB007V1 | STEVAL-IDB007V1 | STEVAL-IDB007V1
DL1 | Not Used | Not Used | Not Used
DL2 | Not Used | Not Used | Not Used
DL3 | Not Used | Not Used | Not Used
DL4 | Power | Power | Power

# Buttons description

| Interrupt | Dma | Polling
BUTTON name | STEVAL-IDB007V1 | STEVAL-IDB007V1 | STEVAL-IDB007V1
PUSH1 | Not Used | Not Used | Not Used
PUSH2 | Not Used | Not Used | Not Used
RESET | Reset BlueNRG1 | Reset BlueNRG1 | Reset BlueNRG1

# Usage

The SPI is a master or slave interface for synchronous serial communication with peripheral devices that have either Motorola SPI, National Semiconductor Micro-Wire or Texas Instruments Synchronous Serial Interfaces.

The SPI performs serial-to-parallel conversion on data received from a peripheral device on the SPI_IN pin, and parallel-to-serial conversion on data written by CPU for transmission on the SPI_OUT pin. The transmit and receive paths are buffered with internal FIFO memories allowing up to 16x 32-bit values to be stored independently in both transmit and receive modes. FIFOs may be burst-loaded or emptied by the system processor, from one to eight words per transfer. Each 32-bit word from the system fills one entry in FIFO.

This example provides a simple application where the SPI communication is controlled by polling of the SPI status register content, interrupts or DMA (3 different configurations).

In this example, the SPI is used to communicate with the SPI interface of the LSM6DS3 inertial sensor. Each time the IRQ from sensor occurs, the accelerometer and gyroscope output data are read and printed through UART (USB-to-SERIAL must be connected to the PC).

The SPI is configured in the master mode. The SPI clock frequency is set to 100 kHz. The data is transferred in the Motorola format, data frame size is 8 bits, with clock low when inactive (CPOL=0) and data valid on clock trailing edge (CPHA = 1).

Definition in file SPI_Master_w_Sensor_main.c.