Skip to content

need help about use SPI in interrupt mode. arduino hanged. #1

@lxbzmy

Description

@lxbzmy

I wang use int.0 to chatch data line rising ,and recieve spi data from wizfi210.

I tested this program in loop query mode.It works very good.

But when I chang it to use int0 , and programe hang.T-T.It hanged after spi data send finish.

I can not found where is problem.
This is part of programe

pinMode(WIFI_CS_PIN, OUTPUT);
pinMode(2, INPUT);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.begin();

wifi chip sync success ful. and

attachInterrupt(0, toSerial, CHANGE);

then :

void loop() {

wdt_reset();
static char tmp;
static unsigned long ms = millis();
//use this to detect serial is live
if (millis() - ms > 5000) {
    Serial.print(".");
    ms = millis();
}

while (Serial.available()) {
    //encs;
    tmp = Serial.read();
    *p++ = tmp;
    if (tmp == '\r') {
        int l = strlen(buf);
        Serial.print(">");
        Serial.print(l);

        for (int i = 0; i < l; i++) {
            wifi_write(buf[i]);
        }
        //get response

        Serial.print('<');
        //clean cache to receive next cmd.
        p = buf;
        memset(buf, '\0', 33);

    }
}
while (digitalRead(WIFI_DATA_PIN)) {
    tmp = wifi_read_byte();
    if ((tmp != SPI_IDLE_CHAR) && (tmp != SPI_INVALID_CHAR_ALL_ZERO)
            && (tmp != SPI_INVALID_CHAR_ALL_ONE)) {
        Serial.print(char(tmp));
    }
}
//decs;

}
void toSerial() {
//detachInterrupt(0);
Serial.print("int0");
/char Msgbuf[68];
memset(Msgbuf, '\0', sizeof(Msgbuf));
Check_OK((byte
) Msgbuf, 2000);*/
while (digitalRead(WIFI_DATA_PIN)) {

    tmp = wifi_read_byte();
    if ((tmp != SPI_IDLE_CHAR) && (tmp != SPI_INVALID_CHAR_ALL_ZERO)
            && (tmp != SPI_INVALID_CHAR_ALL_ONE)) {

        Serial.print(char(tmp));
    }
}
Serial.print(".");
//attachInterrupt(0, toSerial, CHANGE);

}

hang as soon as i send AT&V command

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions