cancel
Showing results for 
Search instead for 
Did you mean: 

LPS25H SPI driver for steval-mki062v2

andyeh88
Associate
Posted on January 08, 2015 at 16:43

Hi all,

I have to connect the LPS25H sensor with the steval-mki062v2 board through the onboard 10-pin connector J8 and use the SPI1 for communication; I want to use the same iNEMO firmware provided with the board except for the onboard pressure sensor data, wich have to be replaced with the external sensor one. I wrote the library for the spi communication but nothing works. With the oscilloscope I don't see any signal from the connector except for the power. My code below: ''HAL_LPS25H.h''

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HAL_LPS25H_H
#define __HAL_LPS25H_H
/* Includes ------------------------------------------------------------------*/
#include ''stm32f10x.h''
#include ''iNEMO_conf.h''
/* LPS25H SPI defines */
#define PRESS_SPI SPI1
#define PRESS_RCC_Periph_SPI RCC_APB2Periph_SPI1
#define PRESS_SPI_Port GPIOA
#define PRESS_SPI_CS_Pin GPIO_Pin_4
#define PRESS_SPI_SCK_Pin GPIO_Pin_5
#define PRESS_SPI_MISO_Pin GPIO_Pin_6
#define PRESS_SPI_MOSI_Pin GPIO_Pin_7
#define PRESS_RCC_Port_SPI RCC_APB2Periph_GPIOA

''LPS25H_SPI.h''

/* Define to prevent recursive inclusion */
#ifndef __LPS25H_SPI_H
#define __LPS25H_SPI_H
/* Includes */
#include ''stm32f10x.h''
#include ''HAL_LPS25H.h''
/* LPS25H registers defines */
#define LPS25_ID 0xBD
#define LPS25H_WHO_AM_I_ADDR 0x0F
#define LPS25H_CTRL_REG1_ADDR 0x20
#define LPS25H_CTRL_REG2_ADDR 0x21
#define LPS25H_CTRL_REG3_ADDR 0x22
#define LPS25H_CTRL_REG4_ADDR 0x23
#define LPS25H_STATUS_REG_ADDR 0x27
#define LPS25H_PRESS_OUT_XL_ADDR 0x28
#define LPS25H_PRESS_OUT_L_ADDR 0x29
#define LPS25H_PRESS_OUT_H_ADDR 0x2A
#define LPS25H_TEMP_OUT_L_ADDR 0x2B
#define LPS25H_TEMP_OUT_H_ADDR 0x2C
#define LPS25H_REF_P_XL_ADDR 0x08
#define LPS25H_REF_P_L_ADDR 0x09
#define LPS25H_REF_P_H_ADDR 0x0A
#define LPS25H_THS_P_L_ADDR 0x30
#define LPS25H_THS_P_H_ADDR 0x31
#define LPS25H_INT_CONFIG_ADDR 0x24
#define LPS25H_INT_SOURCE_ADDR 0x25
/* LPS25H constants defines */
#define P_Sensitivity 4096 /*!< 
Pressure
Sensitivity [LSb/mbar] */
#define T_Sensitivity 480 /*!< Temperature Sensitivity LSb/C */
#define P_Conversion 46//0.0024414 /*!< (1/P_Sensitivity)x10 => Pressure_Data x P_conversion = Pressure in mbar/10 */
#define T_Conversion 0.02083 /*!<(1/T_Sensitivity)x10 => Temperature_Data x T_Conversion = Temperature in °C/10*/
#define P_0 105 /*!<Pressure value in dmbar at zero level */
#define H_p 7290 /*!< Constant (expressed in meter) for
altitude-pressure conversion according to the formula:
z[m]=H_p * ln(P_0/P)*/

#endif /* __LPS25H_I2C_H */

''LPS25H_SPI.c''

/* Includes ------------------------------------------------------------------*/
#include ''LPS25H_SPI.h''
#include ''HAL_LPS25H.h''
#include ''math.h''
/**
* \brief Initializes the SPI peripheral used to drive the LPS25H
* \param None
* \retval None
*/
void LPS25H_SPI_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable SPI and GPIO clocks */
RCC_APB2PeriphClockCmd(PRESS_RCC_Periph_SPI, ENABLE);
RCC_APB2PeriphClockCmd(PRESS_RCC_Port_SPI, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* Configure SPI pins: SCK MISO and MOSI */
GPIO_InitStructure.GPIO_Pin = PRESS_SPI_SCK_Pin | PRESS_SPI_MOSI_Pin; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(PRESS_SPI_Port, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = PRESS_SPI_MISO_Pin | PRESS_SPI_CS_Pin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(PRESS_SPI_Port, &GPIO_InitStructure);
/* SPI configuration */
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Hard;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
/* Apply SPI configuration after enabling it */
SPI_Init(PRESS_SPI, &SPI_InitStructure);
/* SPI Peripheral Enable */
SPI_Cmd(PRESS_SPI, ENABLE);
//SPI_NSSInternalSoftwareConfig(SPI1, SPI_NSSInternalSoft_Set);
SPI_SSOutputCmd(SPI1, ENABLE);
}

#lps25h-spi-inemo-steval-mki062v2
0 REPLIES 0