Hi all,
I'm trying to run a stepper motor with the accelStepper library, a TMC2209 drive and an Adafruit Grand central M4 (samd51).
But with my code, as soon as I use "driver.", my "readSerialPortPc()" fonction no longer works.
As soon as I comment out all the "driver.", my "readSerialPortPc()" function starts working again.
#include <Arduino.h> // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function
#include <AccelStepper.h>
#include "SdFat.h"
#include "Adafruit_SPIFlash.h"
#include <TMCStepper.h>
char nomFichier[30] = "test_uart_v2b_GCM4";
char modeleCPU [30] = "Grand central M4";
//Lets put TX on D4 (SERCOM2.0) and RX on D3 (SERCOM2.1)
Uart Serial2 (&sercom2, 3, 4, SERCOM_RX_PAD_1, UART_TX_PAD_0);
#define EN_PIN 7// Enable
#define DIR_PIN 6// Direction
#define STEP_PIN 5// Step
#define SERIAL_PORT Serial2
#define R_SENSE 0.11f // Match to your driver
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
//TMC2209Stepper driver(&Serial2x, R_SENSE, DRIVER_ADDRESS);
TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);
AccelStepper stepper = AccelStepper(stepper.DRIVER, STEP_PIN, DIR_PIN);
boolean etat_Enable = false;
boolean stepperRun = false;
boolean reverseDir = false;
boolean serialAOn = false;
long tempsDepart = 0;
long tempsEcoule = 0;
uint16_t nbMicroSteps = 4;
uint16_t valeurCurrent = 400;
uint16_t msread = 0;
void SERCOM2_Handler()
{
Serial2.IrqHandler();
}
void setup() {
Serial.begin(115200);
SERIAL_PORT.begin(115200);
// Assign pins 3 & 4 SERCOM functionality
pinPeripheral(3, PIO_SERCOM_ALT);
pinPeripheral(4, PIO_SERCOM_ALT);
//driver.begin(); // Initiate pins and registeries
//driver.toff(5); // Enables driver in software
//driver.rms_current(valeurCurrent); // Set stepper current to 600mA. The command is the same as command TMC2130.setCurrent(600, 0.11, 0.5);
//driver.microsteps(nbMicroSteps);
//driver.pwm_autoscale(1);
stepper.setMaxSpeed(2000); // 100mm/s @ 80 steps/mm
stepper.setAcceleration(20000); // 2000mm/s^2
stepper.setEnablePin(EN_PIN);
stepper.setPinsInverted(false, false, true);
stepper.disableOutputs();
etat_Enable = false;
}
void loop() {
readSerialPortPc ();
}
void enableDrive(boolean sortieOuPas){
etat_Enable = true;
stepper.enableOutputs();
if(sortieOuPas){
Serial.println("Enable à ON");
}
}
void disableDrive(boolean sortieOuPas){
etat_Enable = false;
stepper.disableOutputs();
if(sortieOuPas){
Serial.println("Enable à OFF");
}
}
void readSerialPortPc (){
int tempo, i,s;
int gyros=0;
while (Serial.available() > 0) {
int index=Serial.read(); // lire un premier caractère
// filtrer : il doit etre une lettre minuscule ou majuscule
if(index >= 'A' && index <= 'z'){
int valeur = Serial.parseInt();
// controle eventuel de la valeur
// traitement
switch(index){
case 'i':
Serial.print(nomFichier);Serial.print(" et CPU : ");Serial.println(modeleCPU);
Serial.println("");
break;
} // switch
} //if
} // if
} // fonction