If the sketch includes an Adafruit_FRAM_SPI object with global scope, the sketch compiles and loads, but a drive letter is not assigned. If I create the object within ‘setup’ it is successful.
The following works:
#include <SPI.h>
#include “Adafruit_FRAM_SPI.h”
bool ledState = false;
uint8_t FRAM_CS = D7;
uint8_t addrSizeInBytes = 3; //Default to address size of three bytes
void setup() {
//Set user LED: Red OFF; Green OFF; Blue ON
pinMode(16, OUTPUT); digitalWrite(16, HIGH);
pinMode(17, OUTPUT); digitalWrite(17, HIGH);
pinMode(25, OUTPUT); digitalWrite(25, LOW);
Serial.begin(9600);
while (!Serial) {}
Serial.println(“starting”);
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS, &SPI); // use hardware SPI
if (fram.begin(addrSizeInBytes)) {
Serial.println(“Found SPI FRAM”);
} else {
Serial.println(“No SPI FRAM found … check your connections\r\n”);
}
}
void loop() {
delay(1000);
digitalWrite(25, ledState ? HIGH : LOW);
ledState = !ledState;
}
(The normal output is:
starting
hardware SPI
Flash Size = 0x40000
Found SPI FRAM
)
But if I move the line creating the object so that the object has global scope it does not work:
ledState = false;
uint8_t FRAM_CS = D7;
uint8_t addrSizeInBytes = 3; //Default to address size of three bytes
Adafruit_FRAM_SPI fram = Adafruit_FRAM_SPI(FRAM_CS, &SPI); // use hardware SPI
void setup() {
//Set user LED: Red OFF; Green OFF; Blue ON
pinMode(16, OUTPUT); digitalWrite(16, HIGH);
pinMode(17, OUTPUT); digitalWrite(17, HIGH);
pinMode(25, OUTPUT); digitalWrite(25, LOW);
Serial.begin(9600);
while (!Serial) {}
Serial.println(“starting”);
if (fram.begin(addrSizeInBytes)) {
Serial.println(“Found SPI FRAM”);
} else {
Serial.println(“No SPI FRAM found … check your connections\r\n”);
}
}
void loop() {
delay(1000);
digitalWrite(25, ledState ? HIGH : LOW);
ledState = !ledState;
}
Upon downloading I get the following::
sketch uses 61352 bytes (2%) of program storage space. Maximum is 2093056 bytes.
Global variables use 11444 bytes (4%) of dynamic memory, leaving 250700 bytes for local variables. Maximum is 262144 bytes.
Resetting COM8
Caught exception during reset!
Converting to uf2, output size: 136704, start address: 0x2000
Flashing G: (RPI-RP2)
Wrote 136704 bytes to G:/NEW.UF2
If I then try to start the Serial monitor I get the following:
Error opening serial port ‘COM8’. (Port not found)
I then must hold the ‘B’ switch down while powering up to do anything further with the XIAO.
An object that only works in ‘setup’ is not vey useful…I need global scope: