Hi there, I got my Maple a couple of days ago and I've jumped straight in, trying to communicate with an ADXL345 which I was having problems getting working with an arduino (I thought it was a voltage translator problem). I've been trying to get it working since the sensor is 3.3v however so far nothing works. I'm always getting a response of 0 unless I put the MISO line into the MOSI line.
Here's the code I'm using:
HardwareSPI Spi(2);
#define RW_MASK 0x80
#define MB_MASK 0x40
#define CB_MASK (RW_MASK|MB_MASK)
#define CS 31
#define MISO 33
#define MOSI 34
#define SCLK 32
#define LED_PIN 13
void writeADXL(byte reg, byte data){
byte temp[2]={((~CB_MASK)®),data};
digitalWrite(CS, LOW);
Spi.send(temp,sizeof(temp));
digitalWrite(CS, HIGH);
SerialUSB.print("Tranferred ");
SerialUSB.print(data, HEX);
SerialUSB.print(" to ");
SerialUSB.println(reg, HEX);
}
byte readADXL(byte reg){
byte temp[2]={(((~CB_MASK)®)|0x80),0xAA};
byte value=0;
digitalWrite(CS, LOW);
value=Spi.send(temp,sizeof(temp));
//value=Spi.recv();
digitalWrite(CS, HIGH);
SerialUSB.print("Reg is ");
SerialUSB.print(reg, HEX);
SerialUSB.print(", data reads ");
SerialUSB.println(value, HEX);
return value;
}
void intAXDL(){
writeADXL(0x2D,0x28);
delay(20);
writeADXL(0x31,0x0F); //0x08 normally
delay(20);
writeADXL(0x38,0x00); //0x88 for next test
delay(20);
}
void setup()
{
// start serial port at 9600 bps:
//SerialUSB.begin(9600);
pinMode(LED_PIN, OUTPUT);
SerialUSB.println("Set mode");
pinMode(CS, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(SCLK, OUTPUT);
pinMode(MISO, INPUT_PULLDOWN);
digitalWrite(CS, HIGH);
Spi.begin(SPI_1_125MHZ, MSBFIRST, 3);
intAXDL();
SerialUSB.println("Initialization finished");
}
void loop()
{
byte value=0;
byte state=HIGH;
value=readADXL(0x00);
SerialUSB.println(value, HEX);
digitalWrite(LED_PIN, state);
delay(500);
state^=HIGH;
}
Note that the above code is ported from when I wrote it for the arduino (The response I got from the arduino code was confusing and no making sense).
I'm now trying to get I2C working to try that and I need a touch of help regarding installing/including the libraries to libmaple and also with the initialisation. What 'speed' is 10kHz? 10000?
Also another question, is it possible to do PWM with output as open drain? I'm looking at driving some servos with a 5v signal (I'm unsure if these servos accept 3.3v signals). Is this possible?