Hi all,
Pretty new to the arduino nano, even more new with respect to the SPI library and how it should function. It is my understanding that the first argument of the SPISettings() function should be the maximum data transfer rate, but for whatever reason when I change the value nothing seems to change on the scope.
My setup:
SPI 4-wire connected to a BMA456 accelerometer (datasheet: https://www.mouser.com/datasheet/2/783/BST-BMA456-DS000-1509567.pdf)
Here is my code:
#include <SPI.h>
// Define the digital pin for the SPI Interface.
const int slaveSelectPin1 = 10;
byte readByte = 0x80;
byte writeByte = 0x00;
byte chipAddress = 0x00;
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
// Initialize Serial Communication for debugging
Serial.begin(9600);
while (!Serial);
// Pause so I can open the serial monitor
delay(1000);
// Cycle the slave select pin so the accelerometer switches to SPI mode
pinMode(slaveSelectPin1, OUTPUT);
digitalWrite(slaveSelectPin1, LOW);
digitalWrite(slaveSelectPin1, HIGH);
//
}
void loop() {
double pauseTime = 1000;
SPI.begin(); // init SPI
SPI.beginTransaction(SPISettings(1000000, LSBFIRST, SPI_MODE0)); //set parameters
digitalWrite(slaveSelectPin1, LOW);
delay(1000);
// Send the Chip ID address as command
Serial.print("Transmit: 0x");
Serial.println(readByte | chipAddress, HEX);
byte test = SPI.transfer(readByte | chipAddress); // Send command
Serial.print("Received: 0x");
Serial.println(test, HEX);
delay(pauseTime);
// Transmit one dummy command
Serial.println("Dummy");
test = SPI.transfer(0x00); // Wait one dummy
Serial.println(test, HEX);
delay(pauseTime);
// Now receive the correct value
Serial.println("Read Actual");
test = SPI.transfer(0x00); // Read byte // Should be correct value
Serial.println(test, HEX);
delay(pauseTime);
// Set the CSB pin to high
digitalWrite(slaveSelectPin1, HIGH);
// End transaction
SPI.endTransaction();
SPI.end();
// Wait a bit before the next loop
delay(10000);
}
The attached 1_MHz.jpg is the "screenshot" of my oscilloscope showing the output for this setup.
If I change the argument of the SPISettings() function to be 100,000 (i.e. 100 kHz) and re-upload, the resulting output does not seem to change. The 100kHz.jpg is the oscilloscope reading of that change.
I would really appreciate a second pair of eyes on this in the hopes that I'm just doing something really dumb.
In the mean time I will give it a try on an Uno (R3) to see if I get different clock speeds and report back.
Thanks in advance!

