Tag: SPI

Sending struct via SPI between Arduino Nano and Arduino Mega 2560

In this experiment, Arduino Nano is SPI Master, sending structured data (struct customMessage) via SPI link to Arduino Mega 2560, which is SPI Slave. The struct is wrapped into union allowing byte level access, used both to read and to write data used in SPI transfer. typedef struct customMessage { unsigned int parameterA; unsigned int…

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…