分享到:
|
-
/******************** (C) COPYRIGHT 2015 STMicroelectronics ********************
-
* File Name : I2C/Master_Polling/main.c
-
* Author : RF Application Team
-
* Version : V1.0.0
-
* Date : September-2015
-
* Description : Code demostrating the I2C master functionality
-
********************************************************************************
-
* 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.
-
*******************************************************************************/
-
-
-
/* Includes ------------------------------------------------------------------*/
-
#include "BlueNRG_x_device.h"
-
#include <stdio.h>
-
#include <string.h>
-
#include "BlueNRG1_conf.h"
-
#include "SDK_EVAL_Config.h"
-
#include "lsm6dsl_reg.h"
-
-
/** @addtogroup BlueNRG1_StdPeriph_Examples BlueNRG1 Standard Peripheral Examples
-
* @{
-
*/
-
-
/** @addtogroup I2C_Examples I2C Examples
-
* @{
-
*/
-
-
/** @addtogroup I2C_Master I2C Master
-
* @{
-
*/
-
-
/* Private typedef -----------------------------------------------------------*/
-
typedef enum {
-
I2C_OP_FAILED = 0,
-
I2C_OP_SUCCEED
-
}
-
I2C_AppOpStatus;
-
-
/* Private define ------------------------------------------------------------*/
-
#define TOGGLE_DL1 '1'
-
#define TOGGLE_DL2 '2'
-
#define TOGGLE_DL3 '3'
-
-
/* I2C Device address */
-
#define DEV_ADDRESS 0xBE
-
-
/* I2C clock frequency */
-
#define SDK_EVAL_I2C_CLK_SPEED (10000)
-
-
#define TX_BUF_DIM 1000
-
#define MAX_BUF_SIZE 256
-
-
/* Private macro -------------------------------------------------------------*/
-
/* Private variables ---------------------------------------------------------*/
-
/* Private function prototypes -----------------------------------------------*/
-
-
-
-
static axis3bit16_t data_raw_acceleration;
-
static axis3bit16_t data_raw_angular_rate;
-
static axis1bit16_t data_raw_temperature;
-
static float acceleration_mg[3];
-
static float angular_rate_mdps[3];
-
static float temperature_degC;
-
static uint8_t whoamI, rst;
-
static char tx_buffer[TX_BUF_DIM];
-
lsm6dsl_ctx_t dev_ctx;
-
/* Private functions ---------------------------------------------------------*/
-
static int32_t platform_write(void *handle, uint8_t Reg, uint8_t *Bufp,
-
uint16_t len)
-
{
-
SdkEvalI2CWrite(Bufp, LSM6DSL_I2C_ADD_L >> 1, Reg, len);
-
return 0;
-
}
-
-
static int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp,
-
uint16_t len)
-
{
-
SdkEvalI2CRead(Bufp, LSM6DSL_I2C_ADD_L >> 1, Reg, len);
-
return 0;
-
}
-
-
/* Main Example --------------------------------------------------------------*/
-
void example_main(void)
-
{
-
/*
-
* Initialize mems driver interface
-
*/
-
dev_ctx.write_reg = platform_write;
-
dev_ctx.read_reg = platform_read;
-
-
SdkEvalI2CInit(10000);
-
printf("i2c init");
-
/*
-
* Check device ID
-
*/
-
whoamI = 0;
-
lsm6dsl_device_id_get(&dev_ctx, &whoamI);
-
-
printf("%d",whoamI);
-
if ( whoamI != LSM6DSL_ID )
-
while(1); /*manage here device not found */
-
/*
-
* Restore default configuration
-
*/
-
lsm6dsl_reset_set(&dev_ctx, PROPERTY_ENABLE);
-
do {
-
lsm6dsl_reset_get(&dev_ctx, &rst);
-
} while (rst);
-
/*
-
* Enable Block Data Update
-
*/
-
lsm6dsl_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
-
/*
-
* Set Output Data Rate
-
*/
-
lsm6dsl_xl_data_rate_set(&dev_ctx, LSM6DSL_XL_ODR_12Hz5);
-
lsm6dsl_gy_data_rate_set(&dev_ctx, LSM6DSL_GY_ODR_12Hz5);
-
/*
-
* Set full scale
-
*/
-
lsm6dsl_xl_full_scale_set(&dev_ctx, LSM6DSL_2g);
-
lsm6dsl_gy_full_scale_set(&dev_ctx, LSM6DSL_2000dps);
-
-
/*
-
* Configure filtering chain(No aux interface)
-
*/
-
/* Accelerometer - analog filter */
-
lsm6dsl_xl_filter_analog_set(&dev_ctx, LSM6DSL_XL_ANA_BW_400Hz);
-
-
/* Accelerometer - LPF1 path ( LPF2 not used )*/
-
//lsm6dsl_xl_lp1_bandwidth_set(&dev_ctx, LSM6DSL_XL_LP1_ODR_DIV_4);
-
-
/* Accelerometer - LPF1 + LPF2 path */
-
lsm6dsl_xl_lp2_bandwidth_set(&dev_ctx, LSM6DSL_XL_LOW_NOISE_LP_ODR_DIV_100);
-
-
/* Accelerometer - High Pass / Slope path */
-
//lsm6dsl_xl_reference_mode_set(&dev_ctx, PROPERTY_DISABLE);
-
//lsm6dsl_xl_hp_bandwidth_set(&dev_ctx, LSM6DSL_XL_HP_ODR_DIV_100);
-
-
/* Gyroscope - filtering chain */
-
lsm6dsl_gy_band_pass_set(&dev_ctx, LSM6DSL_HP_260mHz_LP1_STRONG);
-
-
/*
-
* Read samples in polling mode (no int)
-
*/
-
while(1)
-
{
-
/*
-
* Read output only if new value is available
-
*/
-
lsm6dsl_reg_t reg;
-
lsm6dsl_status_reg_get(&dev_ctx, ®.status_reg);
-
-
if (reg.status_reg.xlda)
-
{
-
/* Read magnetic field data */
-
memset(data_raw_acceleration.u8bit, 0x00, 3*sizeof(int16_t));
-
lsm6dsl_acceleration_raw_get(&dev_ctx, data_raw_acceleration.u8bit);
-
acceleration_mg[0] = LSM6DSL_FROM_FS_2g_TO_mg( data_raw_acceleration.i16bit[0]);
-
acceleration_mg[1] = LSM6DSL_FROM_FS_2g_TO_mg( data_raw_acceleration.i16bit[1]);
-
acceleration_mg[2] = LSM6DSL_FROM_FS_2g_TO_mg( data_raw_acceleration.i16bit[2]);
-
-
sprintf((char*)tx_buffer, "Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n",
-
acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
-
printf( tx_buffer);
-
}
-
if (reg.status_reg.gda)
-
{
-
/* Read magnetic field data */
-
memset(data_raw_angular_rate.u8bit, 0x00, 3*sizeof(int16_t));
-
lsm6dsl_angular_rate_raw_get(&dev_ctx, data_raw_angular_rate.u8bit);
-
angular_rate_mdps[0] = LSM6DSL_FROM_FS_2000dps_TO_mdps(data_raw_angular_rate.i16bit[0]);
-
angular_rate_mdps[1] = LSM6DSL_FROM_FS_2000dps_TO_mdps(data_raw_angular_rate.i16bit[1]);
-
angular_rate_mdps[2] = LSM6DSL_FROM_FS_2000dps_TO_mdps(data_raw_angular_rate.i16bit[2]);
-
-
sprintf((char*)tx_buffer, "Angular rate [mdps]:%4.2f\t%4.2f\t%4.2f\r\n",
-
angular_rate_mdps[0], angular_rate_mdps[1], angular_rate_mdps[2]);
-
printf( tx_buffer);
-
}
-
if (reg.status_reg.tda)
-
{
-
/* Read temperature data */
-
memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t));
-
lsm6dsl_temperature_raw_get(&dev_ctx, data_raw_temperature.u8bit);
-
temperature_degC = LSM6DSL_FROM_LSB_TO_degC( data_raw_temperature.i16bit );
-
-
sprintf((char*)tx_buffer, "Temperature [degC]:%6.2f\r\n", temperature_degC );
-
printf( tx_buffer);
-
}
-
}
-
}
-
/**
-
* [url=home.php?mod=space&uid=159083]@brief[/url] Main program code
-
* @param None
-
* @retval None
-
*/
-
int main(void)
-
{
-
/* System initialization function */
-
SystemInit();
-
-
/* Identify BlueNRG1 platform */
-
SdkEvalIdentification();
-
-
/* UART initialization */
-
SdkEvalComUartInit(UART_BAUDRATE);
-
-
/* Infinite loop for process command */
-
example_main();
-
}
-
-
-
#ifdef USE_FULL_ASSERT
-
-
/**
-
* @brief Reports the name of the source file and the source line number
-
* where the assert_param error has occurred.
-
* @param file: pointer to the source file name
-
* @param line: assert_param error line source number
-
*/
-
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 2015 STMicroelectronics *****END OF FILE****/
(0 )
(0 )


发表回复
块
导
航
举报
请选择举报类别
- 广告垃圾
- 违规内容
- 恶意灌水
- 重复发帖