A library for the AMS AS5045 magnetic encoder using the SPI interface
AS5045Controller.cpp
- Committer:
- Generic
- Date:
- 2016-09-16
- Revision:
- 2:02ea2289edb2
- Parent:
- 1:2b21453e2c03
File content as of revision 2:02ea2289edb2:
#include "AS5045Controller.hpp" AS5045Controller::AS5045Controller(PinName CS) : _spi(NC,D12, D13), _cs(CS) { _spi.format(9,2); _spi.frequency(500000); _cs = 1; } int AS5045Controller::GetInt() { _cs = 0; int upper = _spi.write(0x00); int lower = _spi.write(0x00); _cs = 1; return ((upper << 3)+(lower >> 6)); } float AS5045Controller::GetFloat() { float value = (float)GetInt(); return value*0.08789; }