hi guys i am new in this forum my question is the next :
i have a flymaple that i am trying connect to a quadrature counter LS7366R the code for do this is available in arduino. the communication is spi; between the maple and the counter but i not sure how work the SPI library in maple
ARDUINO CODE
#include <SPI.h>
//#include <Arduino.h>
#define CLR B00000000
#define RD B01000000
#define WR B10000000
#define LOAD B11000000
#define MDR0 B00001000
#define MDR1 B00010000
#define DTR B00011000
#define CNTR B00100000
#define OTR B00101000
#define STR B00110000
// filter factor 1
// async index
// no index
// free-running
// 4x quadrature
#define MDR0_CONF B00000011
// no flag
// enabled
// 32 bits
#define MDR1_CONF B00000000
void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(SS, OUTPUT);
digitalWrite(SS, LOW);
SPI.transfer(WR | MDR0);
SPI.transfer(MDR0_CONF);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(WR | MDR1);
SPI.transfer(MDR1_CONF);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(CLR | CNTR);
digitalWrite(SS, HIGH);
}
long count = 0;
void loop() {
digitalWrite(SS, LOW);
byte b = SPI.transfer((byte) RD | CNTR);
count = SPI.transfer(0x00);
count <<= 8;
count |= SPI.transfer(0x00);
count <<= 8;
count |= SPI.transfer(0x00);
count <<= 8;
count |= SPI.transfer(0x00);
count = count*0.351;
digitalWrite(SS, HIGH);
Serial.print(count);
Serial.println();
}
//////////////////////////////////////////////////////////////////////
i suppose that is the way to do in flymaple board but not working
#include <spi.h>
#define CLR 0x00
#define RD 0x40
#define WR 0x80
#define LOAD 0xC0
#define MDR0 0x08
#define MDR1 0x10
#define DTR 0x18
#define CNTR 0x20
#define OTR 0x28
#define STR 0x30
// filter factor 1
// async index
// no index
// free-running
// 4x quadrature
#define MDR0_CONF 0x03
// no flag
// enabled
// 32 bits
#define MDR1_CONF 0x00
HardwareSPI spi(2);
void setup() {
spi.begin(SPI_18MHZ, MSBFIRST, 0);
SerialUSB.begin();
pinMode(D31, OUTPUT);
digitalWrite(D31, LOW);
spi.transfer(WR | MDR0);
spi.transfer(MDR0_CONF);
digitalWrite(D31, HIGH);
digitalWrite(D31, LOW);
spi.transfer(WR | MDR1);
spi.transfer(MDR1_CONF);
digitalWrite(D31, HIGH);
digitalWrite(D31, LOW);
spi.transfer(CLR | CNTR);
digitalWrite(D31, HIGH);
}
long count = 0;
void loop() {
digitalWrite(D31, LOW);
byte b = spi.transfer( RD | CNTR);
count = spi.transfer(0x00);
count <<= 8;
count |= spi.transfer(0x00);
count <<= 8;
count |= spi.transfer(0x00);
count <<= 8;
count |= spi.transfer(0x00);
count = count*0.351;
digitalWrite(D31, HIGH);
SerialUSB.print(count);
SerialUSB.println();
}
please please help