Adafruit NFC shield
#1
Posted 11 July 2012 - 06:59 AM
#2
Posted 16 July 2012 - 09:39 AM
#3
Posted 16 July 2012 - 09:48 AM
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#4
Posted 16 July 2012 - 10:24 AM
#5
Posted 16 July 2012 - 11:27 AM
I haven't said thatYou don´t think that its possible to comunicate with the PN532 by Netduino´s SPI????????
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.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#6
Posted 16 July 2012 - 12:07 PM
#7
Posted 16 July 2012 - 12:29 PM
So, you haven't defined the chip select port, and the active state should be high. I'd suggest using this one: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.......
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.
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#9
Posted 16 July 2012 - 12:46 PM
Good find, changed my code abovelooking 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...
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#10
Posted 16 July 2012 - 01:35 PM
#11
Posted 16 July 2012 - 01:37 PM
That's great!Hey guys!!
It seems that I´ve got some kind of response!!
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.GPIO_NONE in the configuration field
Depends, I would do it step by step, it's not an easy process though!How can I easily transport a c++ library to .NET???? Or I have to translate it from c++ to c# step by step??
- gomore11 likes this
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#12
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 . 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
#13
Posted 16 July 2012 - 02:56 PM
#14
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
Posted 17 July 2012 - 06:49 AM
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
Posted 19 July 2012 - 02:03 PM
#17
Posted 19 July 2012 - 03:22 PM
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
Posted 19 July 2012 - 03:36 PM
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
Posted 20 July 2012 - 07:03 AM
#20
Posted 24 July 2012 - 09:23 AM
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