-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simple_SPI.ino
45 lines (41 loc) · 1.15 KB
/
Simple_SPI.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <SPI.h>
#define XSPI_MISO 14
#define XSPI_MOSI 12
#define XSPI_SCLK 13
#define XSPI_SS 15
// Put SCK, MOSI, SS pins into output mode
// Also put SCK, MOSI into LOW state, and SS into HIGH state
// Then put SPI hardware into Master mode and turn SPI on
SPISettings settingsA(1000,MSBFIRST,SPI_MODE0); // 2MHz Minimum Speed Before was 20 MHz
int rx_data[11];
void setup(){
pinMode(XSPI_SS, OUTPUT);
digitalWrite(XSPI_SS, HIGH);
pinMode(XSPI_MOSI, OUTPUT);
digitalWrite(XSPI_SS, LOW);
pinMode(XSPI_SCLK,OUTPUT);
digitalWrite(XSPI_SCLK, LOW);
pinMode(XSPI_MISO,INPUT);
Serial.begin(115200);
SPI.begin();
SPI.transfer(0x10);
for (int i = 0; i < 11; ++i){
rx_data[i] = SPI.transfer(0);
}
}
void loop(){
int val_1, val_2;
Serial.print("Sending command, getting back these bytes: ");
digitalWrite(SS, LOW);
SPI.beginTransaction(settingsA);
val_1 = SPI.transfer(0xAA);
val_2 = SPI.transfer(0x55);
SPI.endTransaction();
digitalWrite(SS,HIGH);
Serial.print(" ");
Serial.print(val_1, HEX);
Serial.print(val_2, HEX);
Serial.println("- Done -");
Serial.println(" ");
delay(100);
}