Seeed-Studio / PN532

NFC library using PN532 to read/write card and communicate with android
431 stars 176 forks source link

Support for Arduino M0/M0 Pro #34

Closed markelkins closed 5 years ago

markelkins commented 8 years ago

I am using the NFC Shield V2.0 with an Arduino M0 Pro. The library code will not compile and gives the following error:

/Applications/Arduino.app/Contents/Java/libraries/PN532_SPI/PN532_SPI.cpp: In member function 'virtual void PN532_SPI::begin()':
/Applications/Arduino.app/Contents/Java/libraries/PN532_SPI/PN532_SPI.cpp:25:27: error: 'SPI_CLOCK_DIV8' was not declared in this scope
 _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz)

I was able to correct the issue by replacing the following code found at PN532_SPI.cpp line 24:

#ifndef __SAM3X8E__
    _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz)
#else 
    /** DUE spi library does not support SPI_CLOCK_DIV8 macro */
    _spi->setClockDivider(42);             // set clock 2MHz(max: 5MHz)
#endif

with:

#if defined __SAM3X8E__
    /** DUE spi library does not support SPI_CLOCK_DIV8 macro */
    _spi->setClockDivider(42);             // set clock 2MHz(max: 5MHz)
#elif defined __SAMD21G18A__
    /** M0 spi library does not support SPI_CLOCK_DIV8 macro */
    _spi->setClockDivider(24);             // set clock 2MHz(max: 5MHz)
#else 
    _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz)
#endif

I verified the change with several of the examples provided with this library. I would have pushed the change myself, but I don't have permission to push to this project. Hope you find the fix helpful.

xiongyihui commented 8 years ago

Thanks. You can use pull request to push the change. It is a very cool feature of github.