I successfully developed a system based on a MKR1000. Everything works at 3.3V and it uses interruptions (through attachInterrupt on pin 0). The USB port is only used for power supply, no communication.
I then wanted to transfer everything on an Uno Rev3. I used the 3.3V supply pin and I changed in the sketch the interruption pin to 2 (as only pins 2 and 3 are valid for that purpose on the Uno). The behavior I obtain is then really strange. I tried 3 configurations:
A. as is, it doesn't work. It seems the Uno misses/expects an extra interruption.
B. if I activate my debug mode, where the status of the different steps is sent through Serial.print, it works well. It adds the constraints to plug the Arduino to a computer for communication and to use the Serial monitor to get everything running. I don't want that...
C. if I modify the sketch to expect one interruption less, it avoids the error seen in configuration A but the outputs of my system are wrong. So it doesn't work either...
I tried another Uno Rev3 without success. I precise that I don't use any other features of the MKR1000 like WiFi, only the SPI communication.
Besides the interrupt pins, are there other differences between the MKR1000 and the Uno? e.g. in the management of interruptions or SPI communication? Why does it work in configuration B and not in A?
Thank you for your answers.
It don't think it comes from a current issue from the 3.3V pin, otherwise, it won't work either in my configuration B.
Please find the Arduino sketch with this message. My configuration B runs when the debug constant is set to true. The Arduino commands 8 LEDs through a LED driver (TLC5923) based on interruptions it receives from a camera on pin 0 (DigitalTrigger). When done, it sends back a signal on pin 5 (DigitalOutOK) for the camera to move on.
Hope this helps... Arduino_Sketch.ino (2.8 KB)
Hello,
As requested, I've uploaded a picture with the schematic of the system. Please also find the Arduino sketch right below. Thanks again for your time!
// The LED driver communicates using SPI, so include the library:
#include <SPI.h>
// pins used for the connection with the LED driver
const int DigitalTrigger = 0 // Listened to for interruptions
const int Mode = 1; // For the LED driver
const int XLatch = 2; // For the LED driver
const int Blank = 3; // For the LED driver
const int XErr = 4; // For the LED driver
const int DigitalOutOK = 5; // To send out a confirmation
volatile int counter = 0;
volatile int firstcounter = 0;
int iLED = 0;
const bool debug = false;
void setup() {
int result = 0;
if (debug) {
Serial.begin(9600);
while(!Serial) {} // Wait
Serial.println("Setup starting...");
}
pinMode(Mode, OUTPUT);
pinMode(XLatch, OUTPUT);
pinMode(Blank, OUTPUT);
pinMode(DigitalOutOK, OUTPUT);
pinMode(XErr, INPUT);
digitalWrite(DigitalOutOK, LOW);
// MODE LOW -> On/Off mode
digitalWrite(Mode, LOW);
// BLANK HIGH -> Off mode
digitalWrite(Blank, HIGH);
// XLatch LOW
digitalWrite(XLatch, LOW);
// initialize SPI:
SPI.begin();
SPI.beginTransaction(SPISettings(30000000, MSBFIRST, SPI_MODE0));
delay(100);
// Switch on the first and last LEDs (standby)
result = SPI.transfer16(0x0081); // result for 0 or another constant to try
digitalWrite(XLatch, HIGH);
digitalWrite(XLatch, LOW);
// BLANK LOW -> On mode
digitalWrite(Blank, LOW);
if (debug) {Serial.println("Setup done!");}
attachInterrupt(digitalPinToInterrupt(DigitalTrigger), interrupt_call, RISING);
}
void interrupt_call() {
firstcounter++;
if(firstcounter>1){counter++;} // firstcounter sees the first interruption to be ignored
if (debug) {Serial.print("Interruption ");Serial.print(firstcounter);Serial.print("! counter = ");Serial.print(counter);Serial.print(" & iLED = ");Serial.println(iLED);}
}
void loop() {
int LEDcode = 1;
int result = 0;
// Blink each of the first 8 LEDs one after the other
if(counter>iLED){
if (debug) {Serial.print("NEXT LED: counter = ");Serial.print(counter);Serial.print(" & iLED = ");Serial.println(iLED);}
result = LEDcode << iLED;
result = SPI.transfer16(result);
// XLatch HIGH
digitalWrite(XLatch, HIGH);
// XLatch LOW
digitalWrite(XLatch, LOW);
digitalWrite(DigitalOutOK, HIGH);
if (debug) {Serial.println("DigitalOutOK HIGH");}
iLED++;
digitalWrite(DigitalOutOK, LOW);
if (debug) {Serial.println("DigitalOutOK LOW");}
if(iLED==8){
iLED = 0;
counter = 0;
firstcounter = 0;
delay(500); // Let some time to complete on the camera side before returning to constant illumination for the live view
result = SPI.transfer16(0x0081);
digitalWrite(XLatch, HIGH);
digitalWrite(XLatch, LOW);
}
}
}