打印
[应用相关]

LIS3DH I2C驱动

[复制链接]
4339|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
1021256354|  楼主 | 2017-4-15 17:01 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
@香主:LIS3DH 的ST官方I2C驱动链接发我一下,谢谢!!!!!
沙发
yujielun| | 2017-4-15 23:26 | 只看该作者
板凳
yujielun| | 2017-4-15 23:30 | 只看该作者
地板
yiy| | 2017-4-16 14:08 | 只看该作者
en.stsw-mems006.zip (12.66 KB)



使用特权

评论回复
5
yiy| | 2017-4-16 14:09 | 只看该作者
/******************** (C) COPYRIGHT 2012 STMicroelectronics ********************
* File Name          : example_main.c
* Author             : MSH Application Team
* Author             : Abhishek Anand,Fabio Tota
* Revision           : $Revision: 1.5 $
* Date               : $Date: 16/06/2011 12:19:08 $
* Description        : Example main file for MKI109V1 board
* HISTORY:
* Date        | Modification                                | Author
* 16/06/2011  | Initial Revision                            | Fabio Tota
* 11/06/2012  |        Support for multiple drivers in the same program |        Abhishek Anand

********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* THIS SOFTWARE IS SPECIFICALLY DESIGNED FOR EXCLUSIVE USE WITH ST PARTS.
*
*******************************************************************************/


/* Includes ------------------------------------------------------------------*/
//include files for MKI109V1 board
#include "stm32f10x.h"
#include "usb_lib.h"
#include "usb_desc.h"
#include "hw_config.h"
#include "usb_pwr.h"
#include "led.h"
#include "button.h"
#include "adc_mems.h"
#include "string.h"
#include "spi_mems.h"
#include <stdio.h>

//include MEMS driver
#include "lis3dh_driver.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint8_t response;
uint8_t USBbuffer[64];

/* Extern variables ----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

//define for example1 or example2
//#define __EXAMPLE1__H
#define __EXAMPLE2__H

/*******************************************************************************
* Function Name  : main.
* Description    : Main routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
int main(void)
{
  uint8_t buffer[26];
  uint8_t position=0, old_position=0;
  AxesRaw_t data;
  //Initialize your hardware here
  
  //function for MKI109V1 board
  InitHardware();
  SPI_Mems_Init();
  
  EKSTM32_LEDOff(LED1);
  EKSTM32_LEDOff(LED2);
  EKSTM32_LEDOff(LED3);   

  //wait until the USB is ready (MKI109V1 board)
  while(bDeviceState != CONFIGURED);

  //Inizialize MEMS Sensor
  //set ODR (turn ON device)
  response = LIS3DH_SetODR(LIS3DH_ODR_100Hz);
  if(response==1){
        sprintf((char*)buffer,"\n\rSET_ODR_OK    \n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }
  //set PowerMode
  response = LIS3DH_SetMode(LIS3DH_NORMAL);
  if(response==1){
        sprintf((char*)buffer,"SET_MODE_OK     \n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }
  //set Fullscale
  response = LIS3DH_SetFullScale(LIS3DH_FULLSCALE_2);
  if(response==1){
        sprintf((char*)buffer,"SET_FULLSCALE_OK\n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }
  //set axis Enable
  response = LIS3DH_SetAxis(LIS3DH_X_ENABLE | LIS3DH_Y_ENABLE | LIS3DH_Z_ENABLE);
  if(response==1){
        sprintf((char*)buffer,"SET_AXIS_OK     \n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }

  
/*********************/  
/******Example 1******/
#ifdef __EXAMPLE1__H
  while(1){
  //get Acceleration Raw data  
  response = LIS3DH_GetAccAxesRaw(&data);
  if(response==1){
    //print data values
    //function for MKI109V1 board
    EKSTM32_LEDToggle(LED1);
    sprintf((char*)buffer, "X=%6d Y=%6d Z=%6d \r\n", data.AXIS_X, data.AXIS_Y, data.AXIS_Z);
    USB_SIL_Write(EP1_IN, buffer, 29);
    SetEPTxValid(ENDP1);  
    old_position = position;
  }
}
#endif /* __EXAMPLE1__H  */


/*********************/
/******Example 2******/
#ifdef __EXAMPLE2__H
//configure Mems Sensor
//set Interrupt Threshold
response = LIS3DH_SetInt1Threshold(20);
if(response==1){
        sprintf((char*)buffer,"SET_THRESHOLD_OK\n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }
//set Interrupt configuration (all enabled)
response = LIS3DH_SetIntConfiguration(LIS3DH_INT1_ZHIE_ENABLE | LIS3DH_INT1_ZLIE_ENABLE |
                                                                           LIS3DH_INT1_YHIE_ENABLE | LIS3DH_INT1_YLIE_ENABLE |
                                                                           LIS3DH_INT1_XHIE_ENABLE | LIS3DH_INT1_XLIE_ENABLE );
if(response==1){
        sprintf((char*)buffer,"SET_INT_CONF_OK \n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }
//set Interrupt Mode
response = LIS3DH_SetIntMode(LIS3DH_INT_MODE_6D_POSITION);
if(response==1){
        sprintf((char*)buffer,"SET_INT_MODE    \n\r\0");
        USB_SIL_Write(EP1_IN, buffer, 19);
        SetEPTxValid(ENDP1);
  }

while(1){
  //get 6D Position
  response = LIS3DH_Get6DPosition(&position);
  if((response==1) && (old_position!=position)){
    EKSTM32_LEDToggle(LED1);
    switch (position){
    case LIS3DH_UP_SX:   sprintf((char*)buffer,"\n\rposition = UP_SX  \n\r\0");   break;
    case LIS3DH_UP_DX:   sprintf((char*)buffer,"\n\rposition = UP_DX  \n\r\0");   break;
    case LIS3DH_DW_SX:   sprintf((char*)buffer,"\n\rposition = DW_SX  \n\r\0");   break;              
    case LIS3DH_DW_DX:   sprintf((char*)buffer,"\n\rposition = DW_DX  \n\r\0");   break;
    case LIS3DH_TOP:     sprintf((char*)buffer,"\n\rposition = TOP    \n\r\0");   break;
    case LIS3DH_BOTTOM:  sprintf((char*)buffer,"\n\rposition = BOTTOM \n\r\0");   break;
    default:      sprintf((char*)buffer,"\n\rposition = unknown\n\r\0");   break;
    }
  
  //function for MKI109V1 board   
  USB_SIL_Write(EP1_IN, buffer, 23);
  SetEPTxValid(ENDP1);  
  old_position = position;
  }
}
#endif /*__EXAMPLE2__H */

} // end main


#ifdef USE_FULL_ASSERT


//function for MKI109V1 board
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {}
}
#endif

/******************* (C) COPYRIGHT 2012 STMicroelectronics *****END OF FILE****/

使用特权

评论回复
6
232321122| | 2017-4-16 17:15 | 只看该作者
怎么不使用mpu6050?

使用特权

评论回复
7
232321122| | 2017-4-16 17:16 | 只看该作者
记得有个F030开发板带有这个例程参考。

使用特权

评论回复
8
1021256354|  楼主 | 2017-4-17 09:21 | 只看该作者
232321122 发表于 2017-4-16 17:16
记得有个F030开发板带有这个例程参考。

有链接么?谢谢

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

148

主题

642

帖子

3

粉丝