MMC5603NJ地磁传感器(指南针示例)

本文介绍了使用MMC5603NJ地磁传感器实现指南针功能的详细过程,包括原理图、开发平台(keil 5.29 和 RTL8762DK)的选择,以及编码实现的三个关键文件(mmc5603nj.h、mmc5603nj.c和main.c)。作者分享了运行结果,并期望能为其他开发者提供帮助。
摘要由CSDN通过智能技术生成

目录

概述

一、原理图

二、平台

三、编码

四、运行结果​

五、总结


概述

        最近项目上的需要,增加指南针功能,通过网上搜索得知,这个传感器的资料比较少,在此写了一个Demo,希望能帮助到需要的攻城狮们,一起学习一起探讨,加油 加油 加油!

一、原理图

二、平台

1、keil 5.29

2、RTL8762DK(瑞昱 蓝牙芯片)

三、编码

1、mmc5603nj.h文件


/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MMC5603NJ_H__
#define __MMC5603NJ_H__
#include "stdint.h"

#define MMC5603_7BITI2C_ADDRESS		0x30

#define MMC5603_REG_DATA			0x00
#define MMC5603_REG_XL				0x00
#define MMC5603_REG_XH				0x01
#define MMC5603_REG_YL				0x02
#define MMC5603_REG_YH				0x03
#define MMC5603_REG_ZL				0x04
#define MMC5603_REG_ZH				0x05

#define MMC5603_REG_STATUS1			0x18
#define MMC5603_REG_STATUS0			0x19

#define MMC5603_REG_ODR				0x1A
#define MMC5603_REG_CTRL0			0x1B
#define MMC5603_REG_CTRL1			0x1C
#define MMC5603_REG_CTRL2			0x1D

#define MMC5603_REG_X_THD			0x1E
#define MMC5603_REG_Y_THD			0x1F
#define MMC5603_REG_Z_THD			0x20

#define MMC5603_REG_ST_X_VAL		0x27
#define MMC5603_REG_ST_Y_VAL		0x28
#define MMC5603_REG_ST_Z_VAL		0x29

#define MMC5603_REG_PRODUCTID1		0x39

/* Bit definition for control register ODR 0x1A */
#define MMC5603_CMD_ODR_1HZ			0x01
#define MMC5603_CMD_ODR_5HZ			0x05
#define MMC5603_CMD_ODR_10HZ		0x0A
#define MMC5603_CMD_ODR_50HZ		0x32
#define MMC5603_CMD_ODR_100HZ		0x64
#define MMC5603_CMD_ODR_200HZ		0xC8
#define MMC5603_CMD_ODR_255HZ		0xFF

/* Bit definition for control register 0 0x1B */
#define MMC5603_CMD_TMM				0x01
#define MMC5603_CMD_TMT         	0x02
#define MMC5603_CMD_START_MDT		0x04
#define MMC5603_CMD_SET				0x08
#define MMC5603_CMD_RESET			0x10
#define MMC5603_CMD_AUTO_SR_EN		0x20
#define MMC5603_CMD_AUTO_ST_EN		0x40
#define MMC5603_CMD_CMM_FREQ_EN		0x80

/* Bit definition for control register 1 0x1C */
#define MMC5603_CMD_BW00			0x00
#define MMC5603_CMD_BW01			0x01
#define MMC5603_CMD_BW10			0x02
#define MMC5603_CMD_BW11			0x03
#define MMC5603_CMD_ST_ENP			0x20
#define MMC5603_CMD_ST_ENM			0x40
#define MMC5603_CMD_SW_RST			0x80

/* Bit definition for control register 2 0x1D */
#define MMC5603_CMD_PART_SET1		0x00
#define MMC5603_CMD_PART_SET25		0x01
#define MMC5603_CMD_PART_SET75		0x02
#define MMC5603_CMD_PART_SET100		0x03
#define MMC5603_CMD_PART_SET250		0x04
#define MMC5603_CMD_PART_SET500		0x05
#define MMC5603_CMD_PART_SET1000	0x06
#define MMC5603_CMD_PART_SET2000	0x07
#define MMC5603_CMD_EN_PART_SET		0x08
#define MMC5603_CMD_CMM_EN			0x10
#define MMC5603_CMD_INT_MDT_EN		0x20
#define MMC5603_CMD_INT_MD_EN		0x40
#define MMC5603_CMD_HPOWER			0x80

#define MMC5603_PRODUCT_ID			0x10
#define MMC5603_MM_DONE_INT			0x01
#define MMC5603_MT_DONE_INT			0x02
#define MMC5603_MDT_FLAG_INT		0x04
#define MMC5603_ST_FAIL_INT			0x08
#define MMC5603_OTP_READ_DONE		0x10
#define MMC5603_SAT_SENSOR			0x20
#define MMC5603_MM_DONE				0x40
#define MMC5603_MT_DONE				0x80

// 16-bit mode, null field output (32768)
#define	MMC5603_16BIT_OFFSET		32768
#define	MMC5603_16BIT_SENSITIVITY	1024





void MMC5603_Enable(void);
uint8_t mmc5603nj_bpm_algo_handler(void);

#endif /* __MMC5603NJ_IIC__H__ */

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

2、mmc5603nj.c文件


/*********************************************************************************************************
*               Copyright(c) 2018, Realtek Semiconductor Corporation. All rights reserved.
**********************************************************************************************************
* @file     mmc5603nj.c
* @brief
* @details
* @author
* @date
* @version  v0.1
*********************************************************************************************************
*/

#include "trace.h"
#include "rtl876x_spi.h"
#include "rtl876x_i2c.h"
#include "rtl876x_rcc.h"
#include "rtl876x_gpio.h"
#include "rtl876x_nvic.h"
#include "board.h"
#include "string.h"
#include "hub_task.h"
#include "os_sched.h"
#include "os_timer.h"
#include "SEGGER_RTT.h"
#include "rtl876x_tim.h"
#include "mmc5603nj.h"
#include "math.h"


#define GEOMAGNETISM_LOG_EN	(true)	
#if (GEOMA
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ch_champion

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值