Hi Everyone,
I am a complete novice with Arduino, so apologies for any ignorance on my behalf. Basically, I need to create an SPI communication protocol with an RM 3100 magnetometer testing board (3-axis magnetometer). I have attached the user manual, and I'll try to be as detailed/specific as I can. I have followed the example SPI code given on pages 27-30 of that manual, which sets a cycle count, and then does a continuous or a single measurement. I am using an Arduino Nano, which is hooked to the RM 3100 SPI pins. I have double checked to make sure I haven't put the wires in the wrong place! The code I have is:
#include <SPI.h>
const int DRDY = 8;
const int CS = 10;
uint8_t data;
void setup() {
Serial.begin(115200);
// put your setup code here, to run once:
pinMode(DRDY, INPUT);
pinMode(CS, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
}
void loop() {
digitalWrite(CS,HIGH); //set cycle count register
digitalWrite(CS,LOW);
SPI.transfer(0x04);
SPI.transfer(0x00);
SPI.transfer(0x64);
SPI.transfer(0x00);
SPI.transfer(0x64);
SPI.transfer(0x00);
SPI.transfer(0x64);
digitalWrite(CS,HIGH); //end of set cycle counter
delay(100);
// digitalWrite(CS,LOW); //CMM MODE start
// SPI.transfer(0x01);
// SPI.transfer(0x79);
// digitalWrite(CS,HIGH);
digitalWrite(CS,LOW); //Single measurement MODE start
SPI.transfer(0x00);
SPI.transfer(0x70);
digitalWrite(CS,HIGH);
while(1)
{
measure();
}
}
void measure() {
digitalWrite(CS,LOW);
data=SPI.transfer(0xA4);
Serial.println(data);
digitalWrite(CS,HIGH);
delay(1000);
}
When I run this code, on either continuous or single measurement, I get a 3-bit value (usually 192, it occasionally drops below that) that prints out every 1000 ms (the delay I have set). What I expect to get here, according to the manual, is 3-bytes of data for X, followed by 3-bytes for Y and 3-bytes for Z, but that isn't what I get and I can't work out how to go about debugging this. This exact question was asked a few years ago (SPI COMMUNICATION ON ARDUINO PLEASE HELP - Networking, Protocols, and Devices - Arduino Forum) but I can't use the advice given there to change what numbers are being read.
Any help would be appreciated, and please let me know if there's any more information that might be helpful.