iSensor-SPI-Buffer  1.15
Firmware for the iSensor-SPI-Buffer board to enable full throughput buffered data capture on Analog Devices IMUs
Functions | Variables
imu.c File Reference

Implementation for iSensor-SPI-Buffer IMU interfacing module. More...

#include "reg.h"
#include "imu.h"
#include "main.h"
#include "timer.h"
#include "stm32f3xx_hal.h"
Include dependency graph for imu.c:

Functions

static void ApplySclkDivider (uint32_t preScalerSetting)
 Applies baud rate divider setting to master SPI port (to IMU) More...
 
static void InitImuSpiTimer ()
 Inits TIM4 for use as a IMU spi period timer. More...
 
static void InitImuCsTimer ()
 Inits TIM3 for use in PWM mode to drive CS. More...
 
static void ConfigureImuCsTimer (uint32_t period)
 Sets the TIM3 period for use in PWM mode to drive CS. More...
 
static void ConfigureImuSpiTimer (uint32_t period)
 Configures the period on TIM4. More...
 
void IMU_SPI_Init ()
 SPI1 Initialization Function (master SPI port to IMU) More...
 
void IMU_Reset ()
 Hardware reset connected IMU. More...
 
void IMU_Disable_SPI_DMA ()
 Disable IMU burst data stream. More...
 
void IMU_Start_Burst (uint8_t *bufEntry)
 Start an IMU burst data capture (using DMA) More...
 
uint16_t IMU_SPI_Transfer (uint32_t MOSI)
 Basic IMU SPI data transfer function (protocol agnostic). More...
 
uint16_t IMU_Read_Register (uint8_t RegAddr)
 Reads 16 bit value from the IMU. More...
 
uint16_t IMU_Write_Register (uint8_t RegAddr, uint8_t RegValue)
 Writes an 8 bit value to the IMU. More...
 
void IMU_Update_SPI_Config ()
 Processes any changes to IMU_SPI_CONFIG reg and applies. More...
 

Variables

static uint32_t imuStallTimeUs = 25
 
static TIM_HandleTypeDef htim3
 
static TIM_HandleTypeDef htim4
 

Detailed Description

Implementation for iSensor-SPI-Buffer IMU interfacing module.

Copyright (c) Analog Devices Inc, 2020 All Rights Reserved.

Date
3/18/2020
Author
A. Nolan (alex..nosp@m.nola.nosp@m.n@ana.nosp@m.log..nosp@m.com)

Function Documentation

◆ ApplySclkDivider()

static void ApplySclkDivider ( uint32_t  preScalerSetting)
static

Applies baud rate divider setting to master SPI port (to IMU)

Parameters
preScalerSettingThe SCLK pre-scaler setting to apply.
Returns
void

◆ ConfigureImuCsTimer()

static void ConfigureImuCsTimer ( uint32_t  period)
static

Sets the TIM3 period for use in PWM mode to drive CS.

Returns
void
Parameters
periodTimer ticks period for TIM3. This corresponds to the CS low pulse width

TIM3 will be disabled (CS high) by this function. It should not be called while a data capture is in progress. This function must be called whenever the IMU SPI interface settings are updated, either at startup or on demand by the user.

◆ ConfigureImuSpiTimer()

static void ConfigureImuSpiTimer ( uint32_t  period)
static

Configures the period on TIM4.

Parameters
periodThe timer period (in 72MHz ticks)
Returns
void

This function must be called whenever the IMU SPI interface settings are updated, either at startup or on demand by the user.

◆ IMU_Disable_SPI_DMA()

void IMU_Disable_SPI_DMA ( )

Disable IMU burst data stream.

Returns
void

◆ IMU_Read_Register()

uint16_t IMU_Read_Register ( uint8_t  RegAddr)

Reads 16 bit value from the IMU.

Parameters
RegAddrThe IMU register address to read
Returns
The 16 bit register data read from the IMU

This function produces two SPI transfers to the IMU. One to send the initial read request, and a second to get back the read result data.

A stall time is inserted between the two words, as well as after the last word. This is needed when accessing the IMU over USB - don't want to read requests to be immediately back to back.

Here is the call graph for this function:

◆ IMU_Reset()

void IMU_Reset ( )

Hardware reset connected IMU.

Returns
void

Reset pin is pulled low for 1ms, then brought high

Here is the call graph for this function:

◆ IMU_SPI_Init()

void IMU_SPI_Init ( )

SPI1 Initialization Function (master SPI port to IMU)

Returns
void
Here is the call graph for this function:
Here is the caller graph for this function:

◆ IMU_SPI_Transfer()

uint16_t IMU_SPI_Transfer ( uint32_t  MOSI)

Basic IMU SPI data transfer function (protocol agnostic).

Parameters
MOSIThe 16 bit MOSI data to transmit to the IMU
Returns
The 16 bit MISO data received during the transmission

This function wraps the SPI master HAL layer into something easily usable. All SPI pass through functionality is built on this call.

Here is the caller graph for this function:

◆ IMU_Start_Burst()

void IMU_Start_Burst ( uint8_t *  bufEntry)

Start an IMU burst data capture (using DMA)

Parameters
bufEntryPointer to the buffer entry to recieve data into
Returns
void

This function configures the IMU SPI port for a bi-directional DMA transfer. CS is manually controlled by leaving TIM3 (CS timer) disabled, and manually setting the count register to 0.

◆ IMU_Update_SPI_Config()

void IMU_Update_SPI_Config ( )

Processes any changes to IMU_SPI_CONFIG reg and applies.

Returns
void

Sets the stall time (in microseconds) based on lower byte of the IMU_SPI_CONFIG register. Sets the SPI clock frequency divider based on the upper 8 bits. See register documentation for details of what target SCLK frequencies are achievable.

Here is the caller graph for this function:

◆ IMU_Write_Register()

uint16_t IMU_Write_Register ( uint8_t  RegAddr,
uint8_t  RegValue 
)

Writes an 8 bit value to the IMU.

Parameters
RegAddrThe IMU register address to write
RegValueThe 8 bit value to write
Returns
The MISO data clocked out from the IMU during the transaction

This function produces only a single SPI transaction to the IMU

Here is the call graph for this function:

◆ InitImuCsTimer()

static void InitImuCsTimer ( )
static

Inits TIM3 for use in PWM mode to drive CS.

Returns
void

TIM4 is used to drive SPI buffered data acquisition from the IMU. One timer interrupt is generated per SPI word clocked out from the DUT. TIM4 runs at a full 72MHz. With a 16-bit resolution and a time base of 72MHz, TIM4 will roll over every 910us The worst case spi period allowed is 255us stall + (17 bits / 140KHz) -> 376us

Here is the caller graph for this function:

◆ InitImuSpiTimer()

static void InitImuSpiTimer ( )
static

Inits TIM4 for use as a IMU spi period timer.

Returns
void

TIM4 is used to drive SPI buffered data acquisition from the IMU. One timer interrupt is generated per SPI word clocked out from the DUT. TIM4 runs at a full 72MHz. With a 16-bit resolution and a time base of 72MHz, TIM4 will roll over every 910us The worst case spi period allowed is 255us stall + (17 bits / 140KHz) -> 376us

Here is the caller graph for this function:

Variable Documentation

◆ htim3

TIM_HandleTypeDef htim3
static

TIM3 HAL handle

◆ htim4

TIM_HandleTypeDef htim4
static

TIM4 HAL handle

◆ imuStallTimeUs

uint32_t imuStallTimeUs = 25
static

track stall time (microseconds)