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.
Revision 2:09ae6c1aab1a, committed 2020-02-20
- Comitter:
- imanomadao
- Date:
- Thu Feb 20 10:11:44 2020 +0000
- Parent:
- 1:6cd6cd00aabe
- Commit message:
- added_getstatus_method
Changed in this revision
| L6470.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/L6470.h Thu Feb 20 03:48:07 2020 +0000
+++ b/L6470.h Thu Feb 20 10:11:44 2020 +0000
@@ -31,44 +31,45 @@
#define STATUS 0x19
//L6470 Commands
-#define NOP 0x000
-#define SetParam 0x0<<5 // ( | PARAM )
-#define GetParam 0x01<<5 // ( | PARAM )
-#define Run_Forward 0x50
-#define Run_Back 0x51
+#define NOP 0x000
+#define SetParam 0x0<<5 // ( | PARAM )
+#define GetParam 0x01<<5 // ( | PARAM )
+#define Run_Forward 0x50
+#define Run_Back 0x51
#define Step_Clock_Forward 0x58
-#define Step_Clock_Back 0x59
-#define Move_Forward 0x40
-#define Move_Back 0x41
-#define GoTo 0x60
-#define GoTo_DIR_Forward 0x68
-#define GoTo_DIR_Back 0x69
+#define Step_Clock_Back 0x59
+#define Move_Forward 0x40
+#define Move_Back 0x41
+#define GoTo 0x60
+#define GoTo_DIR_Forward 0x68
+#define GoTo_DIR_Back 0x69
//#define GoUntill
//#define ReleseSW
-#define GoHome 0x70
-#define GoMark 0x78
-#define ResetPos 0xD8
-#define ResetDevice 0xC0
-#define SoftStop 0xB0
-#define HardStop 0xB8
-#define SoftHiZ 0xA0
-#define HardHiz 0xA8
-#define GetStatus 0xD8
+#define GoHome 0x70
+#define GoMark 0x78
+#define ResetPos 0xD8
+#define ResetDevice 0xC0
+#define SoftStop 0xB0
+#define HardStop 0xB8
+#define SoftHiZ 0xA0
+#define HardHiz 0xA8
+#define GetStatus 0xD8
class L6470
{
- SPI _spi;
- DigitalOut _cs;
+ SPI spi;
+ DigitalOut cs;
public:
- L6470(PinName mosi, PinName miso, PinName sclk, PinName cs):_spi(mosi, miso, sclk),_cs(cs)
+ L6470(PinName mosi, PinName miso, PinName sclk, PinName cs):spi(mosi, miso, sclk),cs(cs)
{
- _spi.format(8,2);
- _spi.frequency(4960000);
+ spi.format(8,2);
+ spi.frequency(4960000);
}
+
//~L6470();
@@ -81,73 +82,73 @@
//_spi.frequency(4960000);
// nopを送ることで残留している命令を排除
- _cs = 1;
- _spi.write(0x00);
- _spi.write(0x00);
- _spi.write(0x00);
- _spi.write(0x00);
- _cs = 0;
+ cs = 1;
+ spi.write(0x00);
+ spi.write(0x00);
+ spi.write(0x00);
+ spi.write(0x00);
+ cs = 0;
//リセット
- _cs = 1;
- _spi.write(0xC0);
- _cs = 0;
+ cs = 1;
+ spi.write(0xC0);
+ cs = 0;
// MAX_SPEED設定。
- _cs = 1;
- _spi.write(0x07);
+ cs = 1;
+ spi.write(0x07);
// 最大回転スピード値(10bit) 初期値は 0x41
- _spi.write(0x00);
- _spi.write(0x23);
- _cs = 0;
+ spi.write(0x00);
+ spi.write(0x23);
+ cs = 0;
// KVAL_HOLD設定。
/// レジスタアドレス。
- _cs = 1;
- _spi.write(0x09);
- _spi.write(0xFF);
- _cs = 0;
+ cs = 1;
+ spi.write(0x09);
+ spi.write(0xFF);
+ cs = 0;
// KVAL_spiUN設定。
/// レジスタアドレス。
- _cs = 1;
- _spi.write(0x0A);
- _spi.write(0xFF);
- _cs = 0;
+ cs = 1;
+ spi.write(0x0A);
+ spi.write(0xFF);
+ cs = 0;
// KVAL_ACC設定。
- _cs = 1;
- _spi.write(0x0B);
- _spi.write(0xFF);
- _cs = 0;
+ cs = 1;
+ spi.write(0x0B);
+ spi.write(0xFF);
+ cs = 0;
// KVAL_DEC設定。
/// レジスタアドレス。
- _cs= 1;
- _spi.write(0x0C);
- _spi.write(0x40);
- _cs = 0;
+ cs= 1;
+ spi.write(0x0C);
+ spi.write(0x40);
+ cs = 0;
// OCD_TH設定。
/// レジスタアドレス。
- _cs = 1;
- _spi.write(0x13);
- _spi.write(0x0F);
- _cs = 0;
+ cs = 1;
+ spi.write(0x13);
+ spi.write(0x0F);
+ cs = 0;
// STALL_TH設定。
/// レジスタアドレス。
- _cs = 1;
- _spi.write(0x14);
- _spi.write(0x7F);
- _cs = 0;
+ cs = 1;
+ spi.write(0x14);
+ spi.write(0x7F);
+ cs = 0;
};
//void writeByte(uint8_t);
void writeByte(uint8_t data)
{
- _cs = 1;
- _spi.write(data);
- _cs = 0;
+ cs = 1;
+ spi.write(data);
+ cs = 0;
}
void writeBytes(uint8_t add, int bytes, uint32_t value)
@@ -158,33 +159,33 @@
value = value >> 8;
}
if(bytes == 3){
- _cs = 1;
- _spi.write(add);
- _spi.write(data[2]);
- _spi.write(data[1]);
- _spi.write(data[0]);
- _cs = 0;
+ cs = 1;
+ spi.write(add);
+ spi.write(data[2]);
+ spi.write(data[1]);
+ spi.write(data[0]);
+ cs = 0;
}
else if ( bytes == 2 ) {
- _cs = 1;
- _spi.write( add );
- _spi.write( data[1] ) ;
- _spi.write( data[0] ) ;
- _cs = 0;
+ cs = 1;
+ spi.write( add );
+ spi.write( data[1] ) ;
+ spi.write( data[0] ) ;
+ cs = 0;
}
else if ( bytes == 1 ) {
- _cs = 1;
- _spi.write( add );
- _spi.write( data[0] ) ;
- _cs = 0;
+ cs = 1;
+ spi.write( add );
+ spi.write( data[0] ) ;
+ cs = 0;
}
}
//void writeBytes(uint8_t, int, uint32_t);
- void L6470_run(uint32_t speed)
+ void L6470_run(long speed)
{
uint8_t dir;
- uint32_t spd;
+ long spd;
uint8_t spd_h;
uint8_t spd_m;
uint8_t spd_l;
@@ -202,20 +203,27 @@
}
// 送信バイトデータ生成。
- spd_h = (uint8_t)((0x000F0000 & spd) >> 16);
- spd_m = (uint8_t)((0x0000FF00 & spd) >> 8);
- spd_l = (uint8_t)(0x000000FF & spd);
+ spd_h = (uint8_t)((0x000F0000 & (uint32_t)spd) >> 16);
+ spd_m = (uint8_t)((0x0000FF00 & (uint32_t)spd) >> 8);
+ spd_l = (uint8_t)(0x000000FF & (uint32_t)spd);
// コマンド(レジスタアドレス)送信。
- _cs = 1;
- _spi.write(dir);
- _spi.write(spd_h);
- _spi.write(spd_m);
- _spi.write(spd_l);
- _cs = 0;
+ cs = 1;
+ spi.write(dir);
+ spi.write(spd_h);
+ spi.write(spd_m);
+ spi.write(spd_l);
+ cs = 0;
}
//void L6470_run(uint32_t);
+ int getstatus(uint8_t data)
+ {
+ cs = 1;
+ int s = spi.write(data);
+ cs = 0;
+ return s;
+ }
};