Doing SPI.Write from class constructor will brick Arduino Pro Micro

I had a small class to manage digpots (MPC410-10), and it all worked well. Until I’ve introduced write call in class constructor (now commented out).

void DigPotUnitClass::Write(byte value) {

digitalWrite(ChipSelectPin, LOW);
SPI.transfer(B00010001); // This tells the chip to set the pot
SPI.transfer(value); // This tells it the pot position
digitalWrite(ChipSelectPin, HIGH);

DigPotUnitClass::DigPotUnitClass(byte chipSelectPin) {

ChipSelectPin = chipSelectPin;
pinMode(ChipSelectPin, OUTPUT);

Just by making instance in project root scope (.ino):

DigPotUnitClass dp_master_amp = DigPotUnitClass(PIN_MASTER_AMP);

the board seems “bricked” (USB port not visible any more). To bring the board back I had to burn bootloader, using another Arduino Uno as ISP.

Don’t know if this is specific to Arduino Pro Micro, or any other Arduino would behave the same. But it was a hell of a bug to figure out.

Burning the bootloader using Arduino Uno as ISP programmator


Spread the love