Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Adafruit NFC shield


  • Please log in to reply
95 replies to this topic

#1 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 11 July 2012 - 06:59 AM

Hi all. I´m trying to get into the NFC world. I have an Adafruit NFC shield for arduino with the NXP PN532 controller. This is the shield: https://www.adafruit.com/products/789 I´m trying to communicate with the nfc controller by I2C(the default), but I don´t have any success.........Is somebody working with this????

#2 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 16 July 2012 - 09:39 AM

Hello again. I´m trying to comunicate this shield with Netduino but I don´t have any success.First I tried with I2C(the default) but nothing, then with UART(after soldering SLE0 and SEL1 pins on the shield, like says on the manual)and nothing, and finally I´m trying with SPI(again after soldering pins)as a developers suggestion, becouse they recomend strongly to work with SPI. They say that they don´t work with Netduino and that they can´t help me with my problems. I think that it is interesting to work with NFC and Netduino, so if someone could help me it would be great!! Witch SPI_MODE I have to choose to work with Netduino(I mean in the last field of the SPI.Configuration Method)????

#3 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 July 2012 - 09:48 AM

Interesting shield, too bad it's a bit expensive to order for me to just write a driver :) Have you got it working on an Arduino? If so, with a logics analyser it's possible to immitate it's signal.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#4 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 16 July 2012 - 10:24 AM

Hi!! No, sorry but I don´t have it working in an Arduino :( . I always work with Netduino.....I bought it for 36€ in a French online shop :) . The Adafruit stuff has developed some libraries for Arduino that are in: http://code.google.c.../downloads/list You don´t think that its possible to comunicate with the PN532 by Netduino´s SPI????????

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 July 2012 - 11:27 AM

You don´t think that its possible to comunicate with the PN532 by Netduino´s SPI????????

I haven't said that ;)
I can't do much with the source at this moment, but... The usermanual (http://www.adafruit....ets/pn532um.pdf) page 25 is very useful:

The mode used for the clock is Mode 0:
Data is always sampled on the first clock edge of SCK
SCK is active high.
The data order used is LSB first.


I think it's possible to interface with the chip. Not sure if someone done it before though.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 16 July 2012 - 12:07 PM

Yes, I used this information on the user manual to try to comunicate with it, but for sure, I´m doing something wrong. To init the SPI device in my program, I configured it like this: SPI PN532_NFC = new SPI(new SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 200, SPI.SPI_module.SPI1)); Then I asign like Output a Netduino´s pin and I conect this port to the ss pin of the Adafruit shield. Then to start, I put this port down and I try to do a PN532_NFC.WriteRead action. But I have all 0xFF bytes as response.......

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 July 2012 - 12:29 PM

Yes, I used this information on the user manual to try to comunicate with it, but for sure, I´m doing something wrong. To init the SPI device in my program, I configured it like this:

SPI PN532_NFC = new SPI(new SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 200, SPI.SPI_module.SPI1));

Then I asign like Output a Netduino´s pin and I conect this port to the ss pin of the Adafruit shield. Then to start, I put this port down and I try to do a PN532_NFC.WriteRead action. But I have all 0xFF bytes as response.......

So, you haven't defined the chip select port, and the active state should be high. I'd suggest using this one:
SPI.Configuration config = new SPI.Configuration(
                ChipSelect_Port: Pins.GPIO_PIN_D10, 
                ChipSelect_ActiveState: true,
                ChipSelect_SetupTime: 0,
                ChipSelect_HoldTime: 0,
                Clock_IdleState: false,
                Clock_Edge: true,
                Clock_RateKHz: 200,
                SPI_mod: SPI_Devices.SPI1
            );
            SPI PN532_NFC = new SPI(config);

Not sure about the pin, you have to see which pin must be used, but GPIO_NONE won't work I believe.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 16 July 2012 - 12:44 PM

looking at the schematic you would want to use pin D10 as your CS line, after that is done you should be able to get SPI working, then just port the arduino driver to .net...

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 July 2012 - 12:46 PM

looking at the schematic you would want to use pin D10 as your CS line, after that is done you should be able to get SPI working, then just port the arduino driver to .net...

Good find, changed my code above :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 16 July 2012 - 01:35 PM

Hey guys!! It seems that I´ve got some kind of response!! Finally conecting The SS pin on the shield to D10 of Netduino and with my first option(GPIO_NONE in the configuration field), I´ve got 3 bytes of data as response: 0xFF 0xFF 0xFE. I think that this is the PN532´s Ready message, I have to check on the manual but finally it looks like we have the solution. Today I can´t spend more time with this but tomorrow I will continue with it and I will go on posting what happens. Maybe we will have another interesting shield to work with!! How can I easily transport a c++ library to .NET???? Or I have to translate it from c++ to c# step by step??

#11 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 July 2012 - 01:37 PM

Hey guys!!

It seems that I´ve got some kind of response!!

That's great!

GPIO_NONE in the configuration field

It looks like it works by doing so, and it can work, but if you combine it with other devices on the same SPI bus, you'll get into troubles. The "SS" stands for "Slave Select" and selects which device on the SPI bus is active.

How can I easily transport a c++ library to .NET???? Or I have to translate it from c++ to c# step by step??

Depends, I would do it step by step, it's not an easy process though!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#12 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 16 July 2012 - 01:53 PM

That's great!


It looks like it works by doing so, and it can work, but if you combine it with other devices on the same SPI bus, you'll get into troubles. The "SS" stands for "Slave Select" and selects which device on the SPI bus is active.

Depends, I would do it step by step, it's not an easy process though!


Yes, I know the problems that I could have if I use another devices in the same bus, but in this moment I don´t mind :lol: . In this moment I´m only getting familiar to it, so it would be the only device on the bus.

And about transporting the library...........jejejejej I knew that it is a hard work to do it step by step, so that´s the reason why I was asking for another method jajajajaj :P

#13 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 16 July 2012 - 02:56 PM

It should be relatively easy to implement the device spec from the datasheet once you have the SPI comms sorted. You generally find that its easy enough to encapsulate each function in the datasheet as a method and send an appropriate byte array to the device. I generally find the c/c++ arduino drivers are good for checking logic against, but generally not much use other than a basic guideline. i.e. bitwise math can be lifted from the arduino code, but SPI comms stuff less so (as it tends to be bit banged anyways) Nak.

#14 tlmiii01

tlmiii01

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 July 2012 - 04:29 PM

Hey guys!!

It seems that I´ve got some kind of response!! Finally conecting The SS pin on the shield to D10 of Netduino and with my first option(GPIO_NONE in the configuration field), I´ve got 3 bytes of data as response: 0xFF 0xFF 0xFE. I think that this is the PN532´s Ready message, I have to check on the manual but finally it looks like we have the solution. Today I can´t spend more time with this but tomorrow I will continue with it and I will go on posting what happens.

Maybe we will have another interesting shield to work with!!

How can I easily transport a c++ library to .NET???? Or I have to translate it from c++ to c# step by step??


Do you have a line in your code setting D10 to the right state prior to performing the Read/Write? If you are setting the SPI configuration to GPIO_NONE, you would need to control the SS pin manually.

Could you post some of your test code?

Thomas

#15 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 17 July 2012 - 06:49 AM

Bad news!!

I only earned a response from PN532 once. Know it doesn´t seem to hear nothing that I send for it.......

I control the SS pin manuali with the D10 pin of the Netduino. I show you the code, its very simple, only to see its response(In the response I spect a byte with the ready bit on it, the LSB bit of the byte if I´m not wrong):

int i;
            byte[] buffer_write=new byte[10];
            byte[] buffer_read = new byte[15];

            OutputPort NSS = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D10, true);
            

            SPI PN532_NFC = new SPI(new SPI.Configuration(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_NONE, true, 0, 0, false, true, 200, SPI.SPI_module.SPI1));
            

            buffer_write[0] = 0x00;
            buffer_write[1] = 0x00;
            buffer_write[2] = 0xFF;
            buffer_write[3] = 0x02;
            buffer_write[4] = 0x02;
            buffer_write[5] = 0xD4;
            buffer_write[6] = 0x02;
            buffer_write[7] = 0xD6;
            buffer_write[8] = 0x00;
            buffer_write[9] = 0x00;

            while (true)
            {
                NSS.Write(false);
                PN532_NFC.WriteRead(buffer_write, buffer_read);
                NSS.Write(true);
                
                for(i=0;i<buffer_read.Length;i++)
                {
                    Debug.Print(buffer_read[i].ToString());
                }
                Thread.Sleep(3000);
            }
        }

I send a frame of bytes asking for the firmware version of the chip.

#16 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 19 July 2012 - 02:03 PM

Hi!! I´m so blocked with this issue. I think that what´s happening really, is that I´m not writing anything in the bus. Reading the manual it says that when the PN532 chip writes something in the bus gets down its IRQ Pin that its accessible in the shield. I´m reading this port like an interrupt to see if the chip gives any type of response, but nothing. Whatever I write in the bus I don´t have any Interrupt signal. What could be happening? I´m doing something wrong in the write action??

#17 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 19 July 2012 - 03:22 PM

Sounds like the CS toggle issue :( essentially a lot of SPI devices need the CS to toggle from high to low (or vice versa) after every byte is sent, the way the netduino SPI is configured is that it will stay low for the duration of the buffer write. (see the attached image non latching spi) what you need is for it to look like the attached image latching SPI.

Unfortunately you either have to implement additional hardware as Mario demonstrates here or modify the firmware to toggle the CS pin after each byte is sent.

The third option is to not try and write out whole arrays at once so rather than your current implementation, instead try to read and write single bytes and build the response up into a circular buffer, you may need to spam 0x00 at the device to clock out the full response. The big draw back with this approach is that it is quite slow.

Nak.

Attached Files



#18 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 19 July 2012 - 03:36 PM

Ignore me, it looks like the device doesn't want a CS that toggles!

Just read through the code adafruit provide
https://github.com/a...fruit_PN532.cpp

seems to want to keep cs low for duration of writing and i dont see any indication that they toggle.

I would suggest porting all of the commands they have in the header file to c# byte arrays and trying to follow the the flow of their code :)

Nak.

#19 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 20 July 2012 - 07:03 AM

Hi nakchak !! Thank you for your answers!! I didn´t find this code from github before, so thank you!!. So, I have a hard work to do as I spected.........About the chip set issue I remenber that I read it in the manual and saw some time/signal diagramas that confirms the low signal for CS in all the Write action if I´m not wrong. So I will start with the translation from c++ to c# as soon as possible and I will tell you all how it goes, becouse I think that I will need help regularly :huh: . Thank you again!

#20 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 24 July 2012 - 09:23 AM

Hi again!!

I started again with this issue after some busy days doing other things. I´m translating the code from GitHub but I have found a problem, in this piece of code, what the hell could be _VB() variable????? Here is:

void Adafruit_PN532::spiwrite(uint8_t c)
{
int8_t i;
digitalWrite(_clk, HIGH);
for (i=0; i<8; i++)
{
digitalWrite(_clk, LOW);
if (c & _BV(i))
{
digitalWrite(_mosi, HIGH);
}
else
{
digitalWrite(_mosi, LOW);
}
digitalWrite(_clk, HIGH);
}
}

Has to be (I think.....) some kind of buffer, but what has it in??. Finally I see that The SPI comunication has to be done manually instead of using The .Net Micro Framework´s Class, are you agree??




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.