Coder Social home page Coder Social logo

pn532-esp-idf's People

Contributors

thanhbinh89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

d4rc

pn532-esp-idf's Issues

Could you please add an open-source license?

Hi,
nice work porting the Adafruit library to IDF. As I'm porting a Arduino/PlatformIO project to IDF it could help me a lot. However, your project currently has no license, so it cannot be used by others, see https://choosealicense.com/no-permission/.

Could we use it in our project? Since the original Adafruit library uses a BSD license, maybe you could add this as well? See, https://help.github.com/en/github/building-a-strong-community/adding-a-license-to-a-repository.

Thank you!

Problem on porting from custom SPI to ESP-IDF standard functions

Hi @thanhbinh89!

I'm using your code and it's working wonderfully, thanks for this porting!

As I'm already using different peripherals and already initializing the SPI in the main thread I was thinking to improve the code and add the standard functions provided by idf to communicate with SPI.

Before starting I did some research and found this documentation https://www.nxp.com/docs/en/nxp/application-notes/AN133910.pdf but seems that I'm not too good to understand it completely.

And after, a day of try&catch I didn't yet find how to correctly set the configuration of the SPI.

So the questions:

  • The two functions (pn532_spi_write and pn532_spi_read) were written in that form because they are not compatible with the standard idf functions for SPI or 3 years ago there were no such functions out of the box?

As you have written these base functions, I'm pretty sure that you have really more understanding of me on what configuration is needed here. Is possible that you give me your opinion on that?

This is the code that I have written.
I also try a lot of flags to check if there is something that will change, but no.
The response from pn532_spi_read is always 0x00. So no good.

void pn532_spi_init(pn532_t *obj, spi_host_device_t spiHostDevice, uint8_t ss) {

    gpio_set_direction((gpio_num_t) ss, GPIO_MODE_OUTPUT);
    gpio_set_level((gpio_num_t) ss, 1);

    //Config Frequency and SS GPIO
    spi_device_interface_config_t deviceInterfaceConfig = {
            .mode=0,  //SPI mode 0
            .clock_speed_hz= 2000 * 1000,  // Uusually 1.2 Mhz
            .input_delay_ns = 0,
            .spics_io_num = ss,
            .flags = SPI_DEVICE_BIT_LSBFIRST,
            .queue_size = 1
    };

    spi_device_handle_t spiDeviceHandle;

    //Attach the EPD to the SPI bus
    ESP_ERROR_CHECK(spi_bus_add_device(spiHostDevice, &deviceInterfaceConfig, &spiDeviceHandle));

    obj->spi = spiDeviceHandle;
    obj->_ss = ss;

}


void pn532_spi_write(pn532_t *obj, uint8_t data) {
    spi_transaction_t t;
    memset(&t, 0, sizeof(t));       //Zero out the transaction
    t.length = 8;
    t.tx_buffer = &data;
    t.flags = (SPI_TRANS_CS_KEEP_ACTIVE); // instead of gpio_set_level(obj->_ss, 0); and gpio_set_level(obj->_ss, 1); I'm using spi_device_acquire_bus(obj->spi,portMAX_DELAY); and spi_device_release_bus(obj->spi);.

    ESP_LOGI(TAG, "send data: 0x%02x", data);

    ESP_ERROR_CHECK(spi_device_polling_transmit(obj->spi, &t));

}


uint8_t pn532_spi_read(pn532_t *obj) {

    uint8_t data = 1;
    spi_transaction_t t;
    memset(&t, 0, sizeof(t));       //Zero out the transaction
    t.length = 8;
    t.rxlength = 8;
    t.tx_buffer = NULL;
    t.rx_buffer = &data;
    t.flags = (SPI_TRANS_CS_KEEP_ACTIVE); // instead of gpio_set_level(obj->_ss, 0); and gpio_set_level(obj->_ss, 1); I'm using spi_device_acquire_bus(obj->spi,portMAX_DELAY); and spi_device_release_bus(obj->spi);.

    ESP_ERROR_CHECK(spi_device_polling_transmit(obj->spi, &t));

    ESP_LOGI(TAG, "read data: 0x%02x", data);

    return data;

}

Hope to listen from you soon! :)

Reduce the delay in ticks for standard esp32 config.

diff --git a/components/pn532/pn532.c b/components/pn532/pn532.c
index 82d5165..f20d25a 100644
--- a/components/pn532/pn532.c
+++ b/components/pn532/pn532.c
@@ -1313,7 +1313,7 @@ void pn532_readdata(pn532_t *obj, uint8_t *buff, uint8_t n)
     PN532_DEBUG("Reading:");
     for (uint8_t i = 0; i < n; i++)
     {
-        PN532_DELAY(10);
+        PN532_DELAY(5);
         buff[i] = pn532_spi_read(obj);
     }
     for (int i = 0; i < n; i++)

With 10 ticks it creates communication issues and unable to authenticate to read the blocks. By reducing to 5 ticks it works as expected.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.