Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to perform error checking? #28

Closed
clayfreeman opened this issue Jun 22, 2016 · 1 comment
Closed

How to perform error checking? #28

clayfreeman opened this issue Jun 22, 2016 · 1 comment
Assignees
Labels
enhancement An enhancement to the library's function is proposed
Milestone

Comments

@clayfreeman
Copy link

I was wondering if it were possible to detect the following:

  1. If the SPI chip is wired and initialized correctly.
  2. If SPIFlash::begin() was called and completed successfully.

I'm modifying a FAT library that uses this library as a backend and it would be useful to know whether the chip and class have been initialized appropriately before calling read/write operations.

@Marzogh Marzogh self-assigned this Jul 4, 2016
@Marzogh Marzogh added this to the v2.4.0 milestone Jul 4, 2016
@Marzogh Marzogh added the enhancement An enhancement to the library's function is proposed label Jul 4, 2016
@Marzogh
Copy link
Owner

Marzogh commented Jul 6, 2016

You should be able to do this with the current v2.4.0-w.i.p branch. Call the *****.error() function after any other function call and it will return an 8-bit error code generated by that function. (Ref: Wiki page on error codes)

To check if the chip is initialized correctly I'd recommend calling it after begin(). The begin() function runs a chip ID subroutine which can determine if the chip initialises correctly. The simplest way to check for that would be to do something along the lines of this:

#include<SPIFlash.h>
#include<SPI.h>

void setup() {
    flash.begin();
    if (error()) {
        Serial.print("Error generated: ");
        Serial.println(error());
        break;
    }

    /* The rest of your code goes here */
}

void loop() {

    /* The rest of your code goes here */

}

@Marzogh Marzogh closed this as completed Jul 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the library's function is proposed
Projects
None yet
Development

No branches or pull requests

2 participants