Code Below
I am a first-time user of the Nano 33. This same code works fine on Uno/Pro Micro. If I flash it onto the Nano 33, it no longer appears as a com port and doesn't seem to be doing anything. I have to double-click the reset button to get the bootloader to start up. I am unsure how to debug my problem since I am not getting any compiler errors and do not seem to get any life out of the Nano33 with this code. I am guessing it has something to do with SPI.
Any ideas are appreciated. Thanks!
#include <SPI.h>
// Define pin numbers for Chip Select and Reset
#define csPIN 10
#define rstPIN 8
void setup() {
byte statusByte, receivedData;
Serial.begin(9600);
pinMode(rstPIN, OUTPUT);
pinMode(csPIN, OUTPUT);
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE3));
SPI.begin();
digitalWrite(rstPIN, LOW);
delay(1000);
digitalWrite(rstPIN, HIGH);
SPIcycle(0x12, 0x18, statusByte, receivedData);
}
void SPIcycle(int firstbyte, int secondbyte, byte &statusByte, byte &receivedData) {
digitalWrite(csPIN, LOW);
delay(26);
statusByte = SPI.transfer(firstbyte);
receivedData = SPI.transfer(secondbyte);
delay(26);
digitalWrite(csPIN, HIGH);
}
void rxdata() {
byte statusByte, receivedData;
SPIcycle(0x00, 0x02, statusByte, receivedData);
// Print the received status byte and data
Serial.print("RX: ");
Serial.print(statusByte, HEX);
Serial.print(" ");
Serial.println(receivedData, HEX);
}
void loop() {
delay(200);
rxdata();
}