中级
30 分钟

使用HSCDTD008A和PIC32MZ2048EFH100实现精确可靠的方向信息

再也不会迷路:介绍终极电子罗盘

Compass 6 Click with Flip&Click PIC32MZ

已发布 6月 24, 2024

点击板

Compass 6 Click

开发板

Flip&Click PIC32MZ

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFH100

利用我们的电子罗盘技术,放心地探索世界,它提供无与伦比的精度和易用性。

A

A

硬件概览

它是如何工作的?

Compass 6 Click基于ALPS Alpine的HSCDTD008A,这是一款高灵敏度的三轴地磁传感器。它具有集成的驱动电路、信号处理电路和串行接口模块,可以实现低噪声和高分辨率。HSCDTD008A可以测量每个三轴上的磁场强度为±2.4mT,并提供0.15µT/LSB的输出分辨率。此Click board™是实现电子罗盘等应用的理想选择。在操作开始时,通过打开电源将所有内部电路和寄存器设置为默认状态。通过上电

复位,操作模式会自动设置为低功耗待机模式。除了待机模式外,该传感器还具有通过寄存器命令访问的电源控制的主动模式。主动模式有两种状态:强制状态,通过寄存器命令开始测量并输出数据;和正常状态,通过内部计时器触发执行测量并输出数据。Compass 6 Click通过标准的I2C 2-Wire接口与MCU通信,以读取数据和配置设置,支持标准模式操作,时钟频率为100kHz,快速模式最高可达400kHz,Fast Mode 

Plus最高可达1MHz,此外还支持高速模式。它还具有一个额外的准备信号,标记为RDY,并路由到mikroBUS™插座的INT引脚上,当新的测量结果更新时通知主机。此Click board™只能使用3.3V逻辑电压级别运行。在使用具有不同逻辑电平的MCU之前,板上必须执行适当的逻辑电压级别转换。此外,它配备了一个包含功能和示例代码的库,可用作进一步开发的参考。

Compass 6 Click top side image
Compass 6 Click bottom side image

功能概述

开发板

Flip&Click PIC32MZ 是一款紧凑型开发板,设计为一套完整的解决方案,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位 PIC32MZ 微控制器,Microchip 的 PIC32MZ2048EFH100,四个 mikroBUS™ 插槽用于 Click 板™连接,两个 USB 连接器,LED 指示灯,按钮,调试器/程序员连接器,以及两个与 Arduino-UNO 引脚兼容的头部。得益于创

新的制造技术,它允许您快速构建具有独特功能和特性的小工具。Flip&Click PIC32MZ 开发套件的每个部分都包含了使同一板块运行最高效的必要组件。此外,还可以选择 Flip&Click PIC32MZ 的编程方式,使用 chipKIT 引导程序(Arduino 风格的开发环境)或我们的 USB HID 引导程序,使用 mikroC、mikroBasic 和 mikroPascal for PIC32。该套件包括一个通过 USB 类型-C(USB-C)连接器的干净且调

节过的电源供应模块。所有 mikroBUS™ 本身支持的 通信方法都在这块板上,包括已经建立良好的 mikroBUS™ 插槽、用户可配置的按钮和 LED 指示灯。Flip&Click PIC32MZ 开发套件允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

Flip&Click PIC32MZ double image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Data Ready
RD9
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RA2
SCL
I2C Data
RA3
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Compass 6 Click Schematic schematic

一步一步来

项目组装

Flip&Click PIC32MZ front image hardware assembly

从选择您的开发板和Click板™开始。以Flip&Click PIC32MZ作为您的开发板开始。

Flip&Click PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
Flip&Click PIC32MZ MB1 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

该库包含 Compass 6 Click 驱动程序的 API。

关键功能:

  • compass6_get_axes_data - 获取磁轴数据

  • compass6_data_ready - 获取数据准备好引脚状态

  • compass6_generic_read - 读取函数

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief Compass6 Click example
 *
 * # Description
 * This example is a showcase the ability of the device
 * to read 3 axis data of magnetic raw value when data is ready.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of communication modules (I2C, UART) and data 
 * ready pin as input. Then reads identification data and checks 
 * if some of them have wrong value, and configures device for reading.
 *
 * ## Application Task
 * Checks Data ready pin and if asserted high it will read data of all
 * 3 axes(x, y, z) and log data to Terminal.
 *
 * @author Luka Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "compass6.h"

static compass6_t compass6;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    compass6_cfg_t compass6_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    compass6_cfg_setup( &compass6_cfg );
    COMPASS6_MAP_MIKROBUS( compass6_cfg, MIKROBUS_1 );
    err_t init_flag = compass6_init( &compass6, &compass6_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    uint8_t temp_data = 0;
    compass6_generic_read( &compass6, COMPASS6_REG_WHO_I_AM, &temp_data );
    log_printf( &logger, " > Who am I: 0x%.2X\r\n", ( uint16_t )temp_data );
    if ( COMPASS6_WHO_AM_I != temp_data )
    {
        log_error( &logger, " Who am I. " );
    }
    
    compass6_generic_read( &compass6, COMPASS6_REG_INFO_VERSION, &temp_data );
    log_printf( &logger, " > Version: 0x%.2X\r\n", ( uint16_t )temp_data );
    if ( COMPASS6_VERSION != temp_data )
    {
        log_error( &logger, " Version. " );
    }
    
    compass6_generic_read( &compass6, COMPASS6_REG_INFO_ALPS, &temp_data );
    log_printf( &logger, " > ALPS: 0x%.2X\r\n", ( uint16_t )temp_data );
    if ( COMPASS6_ALPS != temp_data )
    {
        log_error( &logger, " ALPS. " );
    }

    compass6_default_cfg ( &compass6 );
    
    log_info( &logger, " Application Task " );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

void application_task ( void ) 
{
    if ( compass6_data_ready( &compass6 ) )
    {      
        compass6_axes_t axes_data;
        compass6_get_axes_data( &compass6, &axes_data );
        log_printf( &logger, " > X: %d\r\n", axes_data.x );
        log_printf( &logger, " > Y: %d\r\n", axes_data.y );
        log_printf( &logger, " > Z: %d\r\n", axes_data.z );
        log_printf( &logger, "*********************\r\n" );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END
/*!
 * @file main.c
 * @brief Compass6 Click example
 *
 * # Description
 * This example is a showcase the ability of the device
 * to read 3 axis data of magnetic raw value when data is ready.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialization of communication modules (I2C, UART) and data 
 * ready pin as input. Then reads identification data and checks 
 * if some of them have wrong value, and configures device for reading.
 *
 * ## Application Task
 * Checks Data ready pin and if asserted high it will read data of all
 * 3 axes(x, y, z) and log data to Terminal.
 *
 * @author Luka Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "compass6.h"

static compass6_t compass6;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    compass6_cfg_t compass6_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    compass6_cfg_setup( &compass6_cfg );
    COMPASS6_MAP_MIKROBUS( compass6_cfg, MIKROBUS_1 );
    err_t init_flag = compass6_init( &compass6, &compass6_cfg );
    if ( I2C_MASTER_ERROR == init_flag ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    uint8_t temp_data = 0;
    compass6_generic_read( &compass6, COMPASS6_REG_WHO_I_AM, &temp_data );
    log_printf( &logger, " > Who am I: 0x%.2X\r\n", ( uint16_t )temp_data );
    if ( COMPASS6_WHO_AM_I != temp_data )
    {
        log_error( &logger, " Who am I. " );
    }
    
    compass6_generic_read( &compass6, COMPASS6_REG_INFO_VERSION, &temp_data );
    log_printf( &logger, " > Version: 0x%.2X\r\n", ( uint16_t )temp_data );
    if ( COMPASS6_VERSION != temp_data )
    {
        log_error( &logger, " Version. " );
    }
    
    compass6_generic_read( &compass6, COMPASS6_REG_INFO_ALPS, &temp_data );
    log_printf( &logger, " > ALPS: 0x%.2X\r\n", ( uint16_t )temp_data );
    if ( COMPASS6_ALPS != temp_data )
    {
        log_error( &logger, " ALPS. " );
    }

    compass6_default_cfg ( &compass6 );
    
    log_info( &logger, " Application Task " );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
}

void application_task ( void ) 
{
    if ( compass6_data_ready( &compass6 ) )
    {      
        compass6_axes_t axes_data;
        compass6_get_axes_data( &compass6, &axes_data );
        log_printf( &logger, " > X: %d\r\n", axes_data.x );
        log_printf( &logger, " > Y: %d\r\n", axes_data.y );
        log_printf( &logger, " > Z: %d\r\n", axes_data.z );
        log_printf( &logger, "*********************\r\n" );
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。