ADXL362 SPI setup clashing with bluetooth

Hello,

I'm using an ADXL362 accelerometer and it works great until I try to use it with a Bluetooth (HC-06) serial connection. The SPI setup protocol for it makes the bluetooth go crazy, sometimes flashing slowly as if in AT command mode, and sometimes (very rarely) actually working. I've tried the Bluetooth both with hardware and softwareserial connection, and on a Sparkfun Pro Micro and SAMD21 mini. All of the connections are working fine, as when I switch to printing an analogue channel over bluetooth or the ADXL362 via USB serial ports it works perfectly.

I'm hoping there is a trick to getting it to work. If anyone could provide any help that would be appreciated. The code is below:

#include <SPI.h>
#include <ADXL362.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(8, 9); // RX, TX

ADXL362 xl;

int16_t XValue, YValue, ZValue, Temperature;

long interval = 2500;
long previousMillis = 0;

void setup(){

mySerial.begin(115200);

// This setup section below is what is causing the issue

xl.begin(10);                   // Setup SPI protocol, issue device soft reset
xl.setNoise(ADXL362_ULTRALOWNOISE); 
xl.setODR(ADXL362_RATE_400); 
xl.beginMeasure();              // Switch ADXL362 to measure mode  
}

void loop(){

unsigned long currentMillis = micros();

  if(currentMillis - previousMillis > interval) {
  previousMillis = currentMillis;   
 
  xl.readXYZTData(XValue, YValue, ZValue, Temperature);  
 
  mySerial.print(XValue);	 
  mySerial.print(" ");
  mySerial.print(YValue);	 
  mySerial.print(" ");
  mySerial.println(ZValue);	
}
}

Unfortunately the problem you are having is with SoftwareSerial and it's non-judicial control of interrupts. SS is well known for it's unwillingness to play with others. A solution is to move your Tx/Rx pins to an unused port, in this case any of the analog pins. Then hack the SS library and comment out the sections where it grabs conrol of the interrupt vectors on PORTB and PORTD.

Alternately, there are other soft UART libraries available that do not have these issues, but will only work on specified pins.

Third - you can always write your own soft UART routine, you can even get the base code from Atmel/Microchip.

DKWatson:
Unfortunately the problem you are having is with SoftwareSerial .....

Thanks for the feedback, but the issue happens with hardware serial as well (tried on both the Pro Micro and Samd21 mini hardware uart). It seems to be an issue for the HC module, I've connected a Bluesmirf and it runs fine.

With or without SoftwareSerial?

DKWatson:
With or without SoftwareSerial?

Tried both with the bluesmirf and it works fine.