This is a sub-question from my other active thread. I am putting it here so it would be more likely to be noticed.
How do I set the SPI clock rate on a T4.0?
If you look at the attached sketch, in the main loop you will see one section that is commented out, and another "active" section.
The active section sets the SPI clock to 4MHz (according to my scope). If I comment this out and uncomment the other section I get a different clock rate. Approximately 1MHz, even though I am using the same SPISettings() parameters.
I am suspecting that the problems described in my other thread is caused by the 4MHz clock rate being too much for the slave device.
How do I set the SPI clock rate on a T4.0?
If you look at the attached sketch, in the main loop you will see one section that is commented out, and another "active" section.
The active section sets the SPI clock to 4MHz (according to my scope). If I comment this out and uncomment the other section I get a different clock rate. Approximately 1MHz, even though I am using the same SPISettings() parameters.
I am suspecting that the problems described in my other thread is caused by the 4MHz clock rate being too much for the slave device.
Code:
#include <SparkFunAutoDriver.h>
#include <SparkFundSPINConstants.h>
#include <SPI.h>
// Create our AutoDriver instances. The parameters are the position in the chain of
// boards (with board 0 being located at the end of the chain, farthest from the
// controlling processor), CS pin, and reset pin.
#define motorCS 10
#define motorReset 31
#define motorBusy 32
#define NUM_BOARDS 1
AutoDriver DECmotor(0, motorCS, motorReset);
#define SPISPEED 500000
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(motorCS, OUTPUT);
digitalWrite(motorCS, HIGH); // tied low is also OK.
pinMode(motorBusy, INPUT_PULLUP);
pinMode(motorReset, OUTPUT);
pinMode(11, INPUT_PULLUP);
digitalWrite(motorReset, LOW);
delay(100); // LOW at least 4 clock cycles of onboard clock. 100 microseconds is enough
digitalWrite(motorReset, HIGH); // now reset to default values
delay(500);
SPI.begin(); //start the spi-bus
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3));
DECmotor.SPIPortConnect(&SPI);
}
void loop() {
/* digitalWrite(motorCS,LOW);
delayMicroseconds(1);
SPI.transfer(0x38); //get the config register value
delayMicroseconds(1);
digitalWrite(motorCS,HIGH);
delayMicroseconds(5);
digitalWrite(motorCS,LOW);
delayMicroseconds(1);
int param = SPI.transfer(0x00);
delayMicroseconds(1);
digitalWrite(motorCS, HIGH);
delayMicroseconds(5);
param <<= 8;
digitalWrite(motorCS,LOW);
delayMicroseconds(1);
param |= SPI.transfer(0x00);
delayMicroseconds(1);
digitalWrite(motorCS,HIGH);
Serial.print("Config: ");Serial.println(param,HEX);
delay(20);
*/
int param = DECmotor.getParam(CONFIG);
delay(10);
Serial.print("Config: ");Serial.println(param,HEX);
delay(10);
}