Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LSM9DS1_project by
AS5145.cpp
00001 #include"AS5145.h" 00002 00003 SPI spi(PB_15,PB_14,PB_13); 00004 SPI spi2(PC_12,PC_11,PC_10); 00005 DigitalOut CS(PB_1); 00006 DigitalOut CS2(PA_13); 00007 00008 int position[2] = {0,0}; 00009 int position_old[2] = {0,0}; 00010 short low_byte = 0x00; 00011 short high_byte = 0x00; 00012 00013 bool AS5145_begin(void) 00014 { 00015 spi.format(8,3); 00016 spi.frequency(1000000); 00017 CS = 1; 00018 spi2.format(8,3); 00019 spi2.frequency(1000000); 00020 CS2 = 1; 00021 return true; 00022 } 00023 void ReadValue(void) 00024 { 00025 CS = 0; 00026 low_byte = spi.write(0x00); 00027 high_byte = spi.write(0x00); 00028 wait_us(1); 00029 CS = 1; 00030 position[0] = (low_byte << 8 | high_byte) >> 3; 00031 CS2 = 0; 00032 low_byte = spi2.write(0x00); 00033 high_byte = spi2.write(0x00); 00034 wait_us(1); 00035 CS2 = 1; 00036 position[1] = (low_byte << 8 | high_byte) >> 3; 00037 if(position[0] > 4096) 00038 position[0] = position_old[0]; 00039 position_old[0] = position[0]; 00040 if(position[1] > 4096) 00041 position[1] = position_old[1]; 00042 position_old[1] = position[1]; 00043 }
Generated on Mon Jul 18 2022 14:39:17 by
