andrea1984
Member
Hello,
I've a custom protocol (similar to SPI) to decode, made with 3 lines:
- ENABLE, High when data is valid
- CLOCK, at 6 Mhz
- DATA
I've attached 2 interrupts on ENABLE and CLOCK input, for acquiring DATA only when CLOCK and ENABLE are HIGH.
Seems that CLOCK line is too fast, and the interrupt on this pin is never activated.
I tried slowing down the CLOCK line to 100 kHz and it works, but I need 6 MHz.
Is there any workaround?
I've a custom protocol (similar to SPI) to decode, made with 3 lines:
- ENABLE, High when data is valid
- CLOCK, at 6 Mhz
- DATA
I've attached 2 interrupts on ENABLE and CLOCK input, for acquiring DATA only when CLOCK and ENABLE are HIGH.
Seems that CLOCK line is too fast, and the interrupt on this pin is never activated.
I tried slowing down the CLOCK line to 100 kHz and it works, but I need 6 MHz.
Is there any workaround?
Code:
const int ledPin = 13;
const int dataPin = 0;
const int clkPin = 1;
const int gatePin = 2;
char currByte;
int idxBit = 0;
#define DATALEN 35000
char dataBuff[DATALEN];
int dataIdx = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(dataPin, INPUT);
pinMode(clkPin, INPUT_PULLUP);
pinMode(gatePin, INPUT_PULLUP);
memset(dataBuff, 0, DATALEN);
Serial.begin(20000000);
Serial.println("START LOGGER v1.0");
attachInterrupt(digitalPinToInterrupt(gatePin), GateChanged, CHANGE);
}
void GateChanged() {
int val = digitalRead(gatePin);
if (val == 1) {
// Begin acquisition
currByte = 0;
idxBit = 0;
dataIdx = 0;
attachInterrupt(digitalPinToInterrupt(clkPin), DataArrived, RISING);
} else {
// End acquisition
detachInterrupt(digitalPinToInterrupt(clkPin));
}
}
void DataArrived() {
int val = digitalRead(dataPin);
if (val == 1) {
currByte = currByte | (val << idxBit);
}
idxBit++;
if (idxBit == 8) {
//Store byte
dataBuff[dataIdx++] = currByte;
idxBit = 0;
currByte = 0;
}
}
void loop() {
if (dataIdx > 0) {
Serial.print("Data [");
Serial.print(dataIdx);
Serial.print("] = ");
for (int i = 0; i < dataIdx; i++) {
Serial.print(dataBuff[i], HEX);
Serial.print(" ");
}
Serial.println("");
dataIdx = 0;
delay(2000);
}
delay(10);
}