Smartlynx stepper motor code (SPI)

Started by Rx7man, July 16, 2015, 09:06:04 AM

Rx7man

OK, so I got the smartlynx stepper motor controller.. I need some help getting the arduino to talk to it, and setting up the wiring

Here's a link to the documentation
http://www.robotshop.com/media/files/zip/documentation-h-elc-mdr-stp-2.zip
it has a little pseudocode in there, I'm just not sure where to start with it


I've never done anything with SPI before...  I have the connector for the smartlynx side of it, but I'm going to have to hack an end off it and fiddle with the rest of it (if I ever make a board I'll put a dedicated header on it)


In other news I've pretty much got the hardware part of the AFC done.. stepper motor is mounted, I have a few little adjustments to make to it yet, but it's looking OK

'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

If I get time this weekend I'll take a look at it, never made my own arduino library before, but it is SPI so you might be able to take a gander at the canbus library and sort of figure things out.. both are SPI
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

alright, cool... Once I have a little example of how it works I can understand it and modify it to whatever I need
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Rx7man

OK, I got to working on the code, but I have a problem.. they didn't include one of the functions for writing, so I kinda had to guess, and I'm not having any luck with it...

rather than post everything again, I'll post a link to the unhelpful Arduino forums SPI -> L6470 (smartlynx) stepper motor driver
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Rx7man

OK, I got some code back from PhiRobotics.. it's for Atmel Studio, and I can't figure it out..

I've included the file that they sent me, perhaps you can have a gander at it?
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Rx7man

Tearing my hair out with this blasted thing.. just doesn't want to work!
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

#6
Don't hit it with a hammer, I'll try looking at this stuff

What is this in ms vb ?

Hum, saw the regular c and h, they look pretty complete IMHO ? Is communication not working or its not doing stuff ?

Pinouts for the Canbus SPI
digital i/o reference:
AREF = 16
RX = 0

14 GND
13 SCK
12 MISO
11 MOSI
10 CS

INT can goto 2 if you want an interrupt wakeup or something /shrug

https://www.arduino.cc/en/Reference/SPI
Pinout is different maybe the GPIO thing ?
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

Only thing that happens is the FLAG LED comes on after it gets reset.. I can't get any data back from it, and I don't know if the data I'm sending makes it there...

I'm using the ICSP header, so I have MISO, MOSI, SCK, 5V, GND on that, CS, RESET, FLAG, Busy/Sync, STCK I have broken out and can use jumpers to wherever.. currently they're all on PortB (I updated the code where it referenced portJ).
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

#8
Why not use all the portB i/o's and abandon the icsp header ? Can you upload a picture of how you have it all together ?

Sometimes it is the simple stuff. I usually break things out on a bread board. When connecting bare wires, I use a male-male jumper wire and just wrap the wire around the loose male end, instead of trying to stuff it in, cause usually it never connects.
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

I have a sparkfun breadboard that I soldered female headers on to connect to the ICSP header.. I then split my 10 wire ribbon and passed it through the solder holes from the top, and made the connections on the bottom (soldered.. but that only needed 5 of the 10 wires.. so 2 hole spacings away from where I ran the wire through, I put a male header and connected the rest of them to it

I have some good male to female jumpers that I run from that header to whatever IO pin I want
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

Rx7man

OK, I'm back to fiddling with this thing..

Looking at the code.. does MISO need to be a input pullup?.. I'm just trying to figure out why I never get any data back..

For a test.. what would happen if you jumpered MOSI to MISO?... would you get your data back?
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

What is your code ? I should probably comb over the library you have a bit more, are you using any of arduino SPI library ?

ie: SPI reset looks like this in the canbus library

// Reset command
void MCP::reset()
{

  digitalWrite(CS,LOW);
  SPI.transfer(RESET);
  digitalWrite(CS,HIGH);
}



void MCP::begin(int mode, int CANspeed)
{
SPI.begin();//SPI communication begin

reset();//Set MCP into Config mode by soft reset. Note MCP2515 is in Config mode by default at power up.

bitRate(CANspeed);//Set CAN bit rate

setMode(mode);//Set CAN mode

}


I'm not sure about the mosi's as much of the canbus library uses the slave low to high.. etc
TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

OK... I GOT THE COMS WORKING.. and the motor is buzzing..

I moved everything off the ICSP header and moved it to the MEGA pins 50-54  with jumper wires.. seems to have done the trick, will troubleshoot why this changed it later...

working on getting it to actually turn now.. tried flipping my phases backwards.. no dice yet, checking statuses and working from there
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles

hakcenter

TS2009 Deḇarim 8:2
"And you shall remember that יהוה your Elohim led you all the way these forty years in the wilderness, to humble you, prove you, to know what is in your heart, whether you guard His commands or not.

Rx7man

Now if I could only get that motor to run the way it should.. it's *really* weak... it's supposed to be 85 oz-in, and it's a tenth of that if you're lucky... no amount of flipping wires is helping, my power supply delivers 2 amps, which should be sufficient with a decent cap (the voltage is steady at 12.25V anyhow).. I've fiddled with all the config registers on the 6470, setting all the voltages to max, and all the currents to max as well, so I don't know what else there is.. Changing step mode from full step to a finer resolution doesn't improve anything either
'94 dually,  67/67 HE351VE, NV5600, ~600hp
'93 ECLB 47RH, new toy truck, H pump project, 1000hp goal, 300K miles
93 XCLB auto, bone stock, 350K miles
93 XCLB 5spd, bone stock, 100K miles