I've been troubleshooting trying to get data from a Mikroelectronica 3D Hall Click
(https://www.mikroe.com/3d-hall-click) board for 3 days now, and could really use some help or suggestions. This is my first attempt at using SPI and the SPI library. I'm also self taught as far as programming goes, so apologize in advance for any unusual coding.
This board is mounted with a Melexis MLX90333 chip, programmed for SPI communication. Mikroelectronica provides proprietary libraries for C implementations on generic avr microcontrollers, but nothing for Arduino. The board appears to be configured according to what Melexis recommends for SPI application, as described on page 42 of the MLX90333 datasheet
http://www.melexis.com/Asset/MLX90333-Datasheet-DownloadLink-5276.aspx
I'm trying to implement this on an UNO, and have tried both the 10,11,12,13 pins as SS, MOSI, MISO and SCK, as well as the ICSP pins. Here is the code I'm using.
#include <SPI.h>
#include <stdint.h>
uint16_t dataBuffer[8];
void setup() {
Serial.begin(9600);
SPI.begin;
pinMode(SS, OUTPUT);
}
void loop() {
delay(20); //MLX90333 startup takes 16ms
SPI.beginTransaction(SPISettings(7000000, LSBFIRST, SPI_MODE1));
digitalWrite(SS, LOW);
delay(5);
int i;
for (i=0; i<8; i++){
dataBuffer[i] = SPI.transfer(0x00);
delay(20);
}
digitalWrite(SS, HIGH);
SPI.endTransaction();
delay(1500);
deBugArray1(dataBuffer,"Data",8); //print dataBuffer array elements to serial monitor
delay(1000);
}
//****Printing array values************************
void deBugArray1(uint16_t array1[], String varName, int col){ //print 1 dimensional array contents
Serial.println(varName);
int a=0;
for(a==0; a<col; a++){
Serial.print(array1[a],8);
Serial.print(" ,");
delay(100);
}
Serial.println();
}
The MLX90333 datasheet indicates that least significant byte is first, the master clock is set to 7MHz, CPHA=1 and CPOL=0, therefore SPI_MODE1.
The data frame layer is 8 bytes, where the 1st byte is a startbyte, the 2nd and 3rd are the alpha angle of the magnetic field, 4th and 5th are the beta angle, 6th and 7th are error code, and 8th is check sum.
In the code above I am trying to transmit/receive 1 byte at a time and am somewhat guessing that my code is doing that or trying to.
The output I'm getting is either all 0's, or all 377, with no rhyme or reason for either, while moving a magnet about the chip.
i.e. Serial Monitor output
Data
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
Data
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,
Data
377 ,377 ,377 ,377 ,377 ,377 ,377 ,377 ,
etc...
I've tried various combinations of SPI SETTINGS, clock speeds, modes, MSB/LSB, with no real effect.
The LED on the Mikro Click board is lit up, so power is on. I have 2 such boards and am getting the same result with each. I've also set it up on a MEGA2560 with the same results.
If anyone can spot something I'm doing wrong or suggest some troubleshooting way forward I would really appreciate it.