This commit is contained in:
2026-02-23 21:13:00 +08:00
commit b38ced9428
141 changed files with 168944 additions and 0 deletions

8
TLE5012B/CMakeLists.txt Normal file
View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.22)
# Register library to the system
add_library(TLE5012B INTERFACE)
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_LIST_DIR}/*.c")
target_sources(TLE5012B INTERFACE ${SOURCES})
target_include_directories(TLE5012B INTERFACE
include
)

41
TLE5012B/TLE5012B.c Normal file
View File

@@ -0,0 +1,41 @@
//
// Created by Wind on 2025/5/18.
//
#include "TLE5012B.h"
#include "main.h"
#include "spi.h"
#include "arm_math.h"
uint16_t SPIx_ReadWriteByte(uint16_t byte)
{
uint16_t read_value = 0;
HAL_SPI_Transmit( &hspi3, (uint8_t *)(&byte), sizeof(byte)/sizeof(uint16_t), 0xff );
HAL_SPI_Transmit( &hspi3, (uint8_t *)(&read_value), sizeof(read_value)/sizeof(uint16_t), 0xff );
return read_value;
}
double ReadAngle(void)
{
return ( ReadValue(READ_ANGLE_VALUE) * 360.0 / 0x10000 );
}
float ReadAngle_Rad(void)
{
return ( (float)ReadValue(READ_ANGLE_VALUE) * 2.0f*PI / 0x10000 );
}
uint16_t ReadSpeed(void)
{
return ReadValue(READ_SPEED_VALUE);
}
uint16_t ReadValue(uint16_t u16RegValue)
{
uint16_t u16Data;
HAL_SPI_Transmit( &hspi3, (uint8_t *)(&u16RegValue), 1, 0xffff );
HAL_SPI_Receive( &hspi3,(uint8_t *)(&u16Data), 1, 0xffff );
return((u16Data & 0x7FFF )<<1);
}

View File

@@ -0,0 +1,46 @@
//
// Created by Wind on 2025/5/18.
//
#ifndef FOC_TLE5012B_H
#define FOC_TLE5012B_H
#include "main.h"
#ifdef __cplusplus
extern "C"{
#endif
//#define SPI_CS_ENABLE HAL_GPIO_WritePin( TLE_CS_GPIO_Port, TLE_CS_Pin, GPIO_PIN_RESET)
//#define SPI_CS_DISABLE HAL_GPIO_WritePin( TLE_CS_GPIO_Port, TLE_CS_Pin, GPIO_PIN_SET)
/* SPI command for TLE5012 */
#define READ_STATUS 0x8001
#define READ_ANGLE_VALUE 0x8021
#define READ_SPEED_VALUE 0x8031
#define WRITE_MOD1_VALUE 0x5060 //0_1010_0_000110_0001
#define MOD1_VALUE 0x0001
#define WRITE_MOD2_VALUE 0x5080 //0_1010_0_001000_0001
#define MOD2_VALUE 0x0801
#define WRITE_MOD3_VALUE 0x5091 //0_1010_0_001001_0001
#define MOD3_VALUE 0x0000
#define WRITE_MOD4_VALUE 0x50E0 //0_1010_0_001110_0001
#define MOD4_VALUE 0x0098
#define WRITE_IFAB_VALUE 0x50B1
#define IFAB_VALUE 0x000D
/* Functionality mode */
#define REFERESH_ANGLE 0
void SPI_SendData16(uint16_t SendData);
uint16_t SPI_ReadData16(void);
double ReadAngle(void);
float ReadAngle_Rad(void);
uint16_t ReadSpeed(void);
uint16_t ReadValue(uint16_t u16Value);
uint16_t SPIx_ReadWriteByte(uint16_t byte);
uint16_t TlE5012W_Reg(uint16_t Reg_CMD, uint16_t Reg_Data);
#ifdef __cplusplus
};
#endif
#endif //FOC_TLE5012B_H