Hey guys, I am still having issues with reading both sensors. I am pretty certain the issue lies within my code because when I check the MISO and MOSI lines of both sensors with an Oscilloscope I get voltage change as the a magnet is brought near. Also, I'm pretty sure I am just reading zeros for the second sensor, because when I apply a magnet to one sensor I will see in the serial monitor a series of non-zeros then a series of zeros then non-zeros then zeros and on and on. This leads me to my next issue, how do I get the two sensors reading to display side by side in the serial monitor?
The Serial protocol ckt that I am using is on page 42 of the following data sheet link:
https://www.melexis.com/-/media/files/.../datasheets/mlx90333-datasheet-melexis.pdf
The method in which I order the SPI system is displayed in the following picture where I used the already labeled slave select pin (pin 17)as my first slave select and pin 2 as my second Slave select pin:
My current code:
#include <SPI.h>
#include <stdint.h>
//*******Arduino MICRO SPI pins********
#define SS1 2
byte dataBuffer[8];
void setup() {
Serial.begin(9600);
SPI.begin;
pinMode(SS1, OUTPUT);
}
void loop() {
delay(20); //MLX90333 startup takes 16ms
SPI.beginTransaction(SPISettings(160000, MSBFIRST, SPI_MODE1)); //320000 is about max
delay(5);
int j;
for (j=0; j<10; j++){
digitalWrite(SS, LOW);
delay(20); //Short delay necessary here
int i;
for (i=0; i<8; i++){
dataBuffer[i] = SPI.transfer(255); // Must transfer 1's, 0's don't work
}
digitalWrite(SS, HIGH);
SPI.endTransaction();
Serial.print(dataBuffer[2],8); //Print 3rd byte, MSB for Alpha
Serial.print(" ,");
Serial.print(dataBuffer[4],8); //Print 5th byte, MSB for Beta
Serial.println(" ,");
}
for (j=0; j<10; j++){
digitalWrite(SS1, LOW);
delay(20); //Short delay necessary here
int i;
for (i=0; i<8; i++){
dataBuffer[i] = SPI.transfer(255); // Must transfer 1's, 0's don't work
}
digitalWrite(SS1, HIGH);
SPI.endTransaction();
Serial.print(dataBuffer[2],8); //Print 3rd byte, MSB for Alpha
Serial.print(" ,");
Serial.print(dataBuffer[4],8); //Print 5th byte, MSB for Beta
Serial.println(" ,");
}
}
If anyone can help me with any of this I would greatly appreciate it!
Thanks!