Sorry for the extremely late replay, I had some problems and could not work on this project for a while.
The system changed a bit:
- Arduino Nano;
- 4 Sensors at I²C bus;
- SPI Slave, interrupt driven using pin 2;
- pin 2 connected to SS (pin 10);
But the problem is the same, the arduino keeps freezing during the setup (with the same output)...
My setup() code is:
void setup()
{
pinMode(DEBUG_LED, OUTPUT);
digitalWrite(DEBUG_LED, LOW);
/*
* A huge delay to the Hub
* do it's setup and do not
* mess with the satellites'
* interruptions
*/
delay(1000);
for(bufferPos = 0; bufferPos <10; bufferPos++)
inBuffer[bufferPos] = '\0';
bufferPos = 0;
//Initialize serial port
Serial.begin(9600);
// Serial.begin(9600, SERIAL_8E1);
Serial.println("Serial initialized.");
//Initialize I2C bus
Wire.begin();
Serial.println("I2C initialized.");
/*
* Initialize accelerometer 0
*/
accelerometer0 = ADXL345(0x1D);
if(accelerometer0.EnsureConnected())
{
Serial.println("Connected to ADXL345 0.");
acel0 = true;
}
else
{
Serial.println("Could not connect to ADXL345 0.");
acel0 = false;
}
//Set the range to -4g/+4g with 10 bits resolution
accelerometer0.SetRange(4, false);
//Enable accelerometer mensurements
accelerometer0.EnableMeasurements();
/*
* Initialize accelerometer 1
*/
accelerometer1 = ADXL345(0x53);
if(accelerometer1.EnsureConnected())
{
acel1 = true;
Serial.println("Connected to ADXL345 1.");
}
else
{
acel1 = false;
Serial.println("Could not connect to ADXL345 1.");
}
//Set the range to -4g/+4g with 10 bits resolution
accelerometer1.SetRange(4, false);
//Enable accelerometer mensurements
accelerometer1.EnableMeasurements();
/* Initialize SPI */
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
//pin to interrupt
pinMode(2, INPUT_PULLUP);
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
// now turn on interrupts
SPI.attachInterrupt();
// interrupt for SS falling edge, pin D2
attachInterrupt (0, ss_falling, FALLING);
/* end SPI */
Serial.println("Initialization Done!");
state = IDLE;
digitalWrite(DEBUG_LED, HIGH);
delay(500);
digitalWrite(DEBUG_LED, LOW);
delay(500);
digitalWrite(DEBUG_LED, HIGH);
delay(1000);
digitalWrite(DEBUG_LED, LOW);
delay(1000);
digitalWrite(DEBUG_LED, HIGH);
}
When I start the arduino I receive this serial output:
Serial initialized.
I2C in
As far as I understand the SIP interrupt and external interrupt are only activated in the end of the setup, after most of the debug messages, which means that the state of pins 2 and 10 shouldn't
interfere before the interrupts be activated. However when pin 2 and 10 are connected to the ground or +5V it works, but when it's "floating" it does not.
I tried to usenoInterrupts()/interrupts() and cli()/sei() but they make the whole system stop working....
Does anyone have any idea about what is going on?
PS: I wasn't sure whether I should or not create a new post, as the problem looks the same.