Several AMIS 30543 on Arduino

Hi there,

I work with an Arduino Mega and I would like to control several stepper motors with it using AMIS 30543 driver boars. There is a library which you can download in the Arduino IDE. While this works fine with one driver, I have troubles getting it to work with two or more drivers. I think this is due to wrong SPI interfacing but I’m not sure. Both drivers share the SPI pins on the Arduino and have different DIR,STEP and SS pins. I tried to select them with the SS pin and then use the SPI interface from the library but it doesn’t do. Also I looked into the AMIS30543.h file and trying to get different functions for each motor but that didn’t work out.

So I would like to know if it’s even possible to drive two or more motors with this library and if someone has an idea to get it work?

Thanks for your help I would appreciate it.
Best regards, Noa

Hello.

We do not know of any implicit problems with using two drivers with the library if you are using different slave select pins. Can you post pictures of your connections and a simplified version of your code here so we can look for any problems? When both drivers are connected, does one work and if so, does the second do anything?

-Nathan

Hi there,

the connections are working properly I checked them multiple times and each driver works on its own when it’s the only one connected. With the code below, no driver moves at all and both motors don’t even have power. I use the slave select only for the SPI commands provided with the example, the DIR pin should be independent of the slave select right?

-Noa

#include <SPI.h>
#include <AMIS30543.h>

const uint8_t motor1step = 49; const uint8_t motor1dir = 48; const uint8_t motor1 = 47; int Lichtschranke1 = 46; const uint8_t motor2step = 45; const uint8_t motor2dir = 44; const uint8_t motor2 = 43; int Lichtschranke2 = 42; int ssPin;

AMIS30543 stepper;

void setup() { SPI.begin(); SPI.setDataMode(SPI_MODE0);

// stepper.init pinMode(motor1, OUTPUT); digitalWrite(motor1, HIGH);

pinMode(motor2, OUTPUT); digitalWrite(motor2, HIGH);

// Drive the NXT/STEP and DIR pins low initially.
digitalWrite(motor1step, LOW); pinMode(motor1step, OUTPUT); digitalWrite(motor1dir, LOW); pinMode(motor1dir, OUTPUT);

digitalWrite(motor2step, LOW); pinMode(motor2step, OUTPUT); digitalWrite(motor2dir, LOW); pinMode(motor2dir, OUTPUT);

pinMode(Lichtschranke1, INPUT); pinMode(Lichtschranke2, INPUT);

// Give the driver some time to power up. delay(1);

select(motor1); // Reset the driver to its default settings. stepper.resetSettings();

// Set the current limit. You should change the number here to // an appropriate value for your particular system. stepper.setCurrentMilliamps(500);

// Set the number of microsteps that correspond to one full step. stepper.setStepMode(16);

// Enable the motor outputs. stepper.enableDriver(); deselect(motor1);

select(motor2); stepper.resetSettings(); stepper.setCurrentMilliamps(500); stepper.setStepMode(16); stepper.enableDriver(); deselect(motor2);

Serial.begin(9600); setDirection2(0); setDirection1(0); }

void loop() { if (digitalRead(Lichtschranke2)==LOW){ step2(100); }

if (digitalRead(Lichtschranke1)==LOW){ step1(500); } }

void step1(int velocity) { digitalWrite(motor1step, HIGH); delayMicroseconds(3); digitalWrite(motor1step, LOW); delayMicroseconds(3); delayMicroseconds(velocity); }

void step2(int velocity) { digitalWrite(motor2step, HIGH); delayMicroseconds(3); digitalWrite(motor2step, LOW); delayMicroseconds(3); delayMicroseconds(velocity); }

void setDirection1(bool dir) { delayMicroseconds(1); digitalWrite(motor1dir, dir); delayMicroseconds(1); }

void setDirection2(bool dir) { delayMicroseconds(1); digitalWrite(motor2dir, dir); delayMicroseconds(1); }

void select(int motorselect) { ssPin=motorselect; digitalWrite(motorselect, LOW); }

void deselect(int motorselect) { digitalWrite(motorselect, HIGH); delayMicroseconds(3); }

Hello, Noa.

Each AMIS30543 object from our AMIS-30543 library for Arduino is designed to control just one stepper motor driver; it stores the slave select pin used for that driver and it stores a cached copy of the settings written to the driver. Instead of trying to use one object to control multiple stepper drivers, I recommend that you make two objects. At the top of your program, you would write:

AMIS30543 stepper1;
AMIS30543 stepper2;

Then, at the top of the setup function, you would initialize each of them to use the correct slave select pin:

void setup()
{
  SPI.begin();
  stepper1.init(motor1ss);
  stepper2.init(motor2ss);
  //...
}

Then you would just call functions on the stepper1 and stepper2 objects. You should not call SPI.setDataMode yourself and you should not try to use pinMode and digitalWrite to manipulate the slave select pins.

I suspect that the code you posted is not working because it does not manage the slave select pins correctly. The “SPI Interface” section of the AMIS-30543 datasheet talks about how it is important to drive the slave select pin (CS) high immediately after reading or writing from a register, and the code you posted is only driving it high at the end when you are done configuring the driver. Also, the code does not call init on the AMIS30543 object, so that object will be using some unspecified pin as its slave select pin (probably pin 0), which could cause problems if you try to use that pin for anything else in the same sketch.

I am not sure I understand your question about the DIR and slave select pins being independent. In general, the DIR and slave select pins can have different values, and they are used for different things. However, it is possible to control the direction of the stepper motor using the SPI interface instead of the DIR pin. If you need more information about those pins, let me know.

If you continue to have trouble, please post the code you are using along with a description of how it behaves and a picture that clearly shows how everything is connected.

–David