初学者
10 分钟

使用TMAG5253和STM32L496AG实现精确的旋转和线性位置检测

线性霍尔效应传感器对磁通密度作出比例响应

LIN Hall 2 Click with Discovery kit with STM32L496AG MCU

已发布 7月 22, 2025

点击板

LIN Hall 2 Click

开发板

Discovery kit with STM32L496AG MCU

编译器

NECTO Studio

微控制器单元

STM32L496AG

检测磁铁的直线运动或确定旋转应用的旋转位置。

A

A

硬件概览

它是如何工作的?

LIN Hall 2 Click 基于 TMAG5253,这是一款德州仪器的低功耗线性霍尔效应传感器。该设备使用比率架构来消除来自 VCC 容差的错误,因为外部模数转换器(ADC)使用相同的 VCC 作为其参考。此外,该设备具有用于 NdFeB 和铁氧体的磁温度补偿,以抵消

在宽温度范围内的磁灵敏度漂移。它完全集成了信号调节、温度补偿电路、机械应力消除和输出驱动器。TMAG5253 对垂直于传感器顶部的磁场分量敏感。它还具有双极性灵敏度,南北磁极会产生独特的输出电压。LIN Hall 2 Click 使用主机 MCU 的模数值。

EN 引脚允许在需要时将设备置于超低功耗(nA)模式。此 Click board™ 只能在 3.3V 逻辑电压级别下运行。板必须在使用不同逻辑级别的 MCU 之前进行适当的逻辑电压级别转换。另外,它配有包含功能和示例代码的库,可作为进一步开发的参考。

LIN Hall 2 Click hardware overview image

功能概述

开发板

32L496GDISCOVERY Discovery 套件是一款功能全面的演示和开发平台,专为搭载 Arm® Cortex®-M4 内核的 STM32L496AG 微控制器设计。该套件适用于需要在高性能、先进图形处理和超低功耗之间取得平衡的应用,支持无缝原型开发,适用于各种嵌入式解决方案。STM32L496AG 采用创新的节能架构,集成

了扩展 RAM 和 Chrom-ART 图形加速器,在提升图形性能的同时保持低功耗,使其特别适用于音频处理、图形用户界面和实时数据采集等对能效要求较高的应用。为了简化开发流程,该开发板配备了板载 ST-LINK/V2-1 调试器/编程器,提供即插即用的调试和编程体验,使用户无需额外硬件即可轻松加载、调

试和测试应用程序。凭借低功耗特性、增强的内存能力以及内置调试工具,32L496GDISCOVERY 套件是开发先进嵌入式系统、实现高效能解决方案的理想选择。

Discovery kit with STM32L496AG MCU double side image

微控制器概述 

MCU卡片 / MCU

STM32L496AG Image

建筑

ARM Cortex-M4

MCU 内存 (KB)

1024

硅供应商

STMicroelectronics

引脚数

169

RAM (字节)

327680

使用的MCU引脚

mikroBUS™映射器

Analog Output
PA4
AN
Chip Enable
PB2
RST
ID COMM
PG11
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LIN Hall 2 Click Schematic schematic

一步一步来

项目组装

Discovery kit with STM32H750XB MCU front image hardware assembly

从选择您的开发板和Click板™开始。以Discovery kit with STM32L496AG MCU作为您的开发板开始。

Discovery kit with STM32H750XB MCU front image hardware assembly
Thermo 21 Click front image hardware assembly
Prog-cut hardware assembly
Board mapper by product7 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
Discovery kit with STM32H750XB MCU NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

软件支持

库描述

该库包含 LIN Hall 2 Click 驱动程序的 API。

关键功能:

  • linhall2_read_an_pin_voltage - IN Hall 2 读取 AN 引脚电压电平功能。

  • linhal2_set_en_pin - LIN Hall 2 设置 EN 引脚状态功能。

  • linhal2_get_flux_density - LIN Hall 2 读取磁通密度功能。

开源

代码示例

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

/*!
 * @file main.c
 * @brief LIN Hall 2 Click Example.
 *
 * # Description
 * This is an example which demonstrates the use of LIN Hall 2 Click board by measuring 
 * magnetic field density and showing it in mT as well as detecting the orientation of the magnet.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * The initialization of ADC module and log UART.
 *
 * ## Application Task
 * The demo application reads the Magnetic field density and showing it in mT 
 * as well as the orientation of the magnet.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "linhall2.h"

static linhall2_t linhall2;   /**< LIN Hall 2 Click driver object. */
static log_t logger;          /**< Logger object. */

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    linhall2_cfg_t linhall2_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.
    linhall2_cfg_setup( &linhall2_cfg );
    LINHALL2_MAP_MIKROBUS( linhall2_cfg, MIKROBUS_1 );
    if ( ADC_ERROR == linhall2_init( &linhall2, &linhall2_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    linhal2_set_en_pin( &linhall2, LINHALL2_ENABLE_DEVICE );
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float mag_flux = 0;
    if ( LINHALL2_OK == linhal2_get_flux_density ( &linhall2, &mag_flux ) ) 
    {
        log_printf( &logger, " Magnetic flux density: %.3f[mT]\r\n", mag_flux );
        if ( 0 < mag_flux )
        {
            log_printf( &logger, " Magnetic field oriented South \r\n\n" );
        }
        else
        {
            log_printf( &logger, " Magnetic field oriented North \r\n\n" );
        }
        Delay_ms ( 1000 );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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