42 lines
911 B
C
42 lines
911 B
C
//
|
|
// 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);
|
|
}
|