Other Parts Discussed in Thread: DRV8703-Q1, MSP430F2617, DRV8711, MSP430G2553, ENERGIA,
/*
* SPI interface for Motor
*
* This code controls DRV8704 motor driver. DRV8704 is SPI-compatible, and to command it, you send
* 12 data bits and 1 read/write bit.
*
* The circuit
* - SCLK: to SCK(ICSP-3) or digital pin 13
* - SDATI: MOSI(ICSP-4) or digital pin 11
* - SCS: 10
* - SDATO: MISO(ICSP-1) or digital pin 12
*
* created 31 Mar 2017 by Irene Zhang
*/
//include the SPI library
#include <SPI.h>
//pins used for the connection with the chip
//the other pins will be controlled by SPI library
//const int SS = 10;
//DRV8704's register addresses:
//const int CTRL = 0x00;
//const int TORQUE = 0x01;
//const int OFF = 0x02;
//const int BLANK = 0x03;
//const int DECAY = 0x04;
//const int DRIVE = 0x06;
//const int STATUS = 0x07;
//**** Configure the Motor Driver's Settings ****//
void setup(){
//set SS pin as an output
pinMode(SS, OUTPUT);
SPI.begin();
}
void control(int reg, int value){
digitalWrite(SS, LOW);
SPI.transfer(reg);
SPI.transfer(value);
digitalWrite(SS, HIGH);
}
void readData(int reg){
int val;
val = digitalRead(12);
Serial.println(val);
}
void loop(){
control(0, 1);
control(9, 1);
control(8, 1);
control(11,0);
control(10,0);
}