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

#21 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 24 July 2012 - 09:57 AM

_BV is an arduino macro, for bit shifting n number of places left (more info here) same thing can be done in c# using the << operator
here are some articles on bitwise operations using c#

http://www.blackwasp...BitwiseOps.aspx
http://www.codeproje...operations-in-C

As far as bitbanging (manually setting pin levels) i wouldn't bother as it negates the benefit of the managed SPI code, you should be able to divine the relevant bytes to send based on the defines in the header file in the repository i linked to on github
(Adafruit_PN532.h)

Nak.

#22 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 25 July 2012 - 11:42 AM

Hi!! I translated part of the code, and tried it. But I aleways have the same response,"Didn't find PN53x board".......

#23 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 25 July 2012 - 01:47 PM

Please post your code, might shed some light on the issue :) Nak.

#24 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 25 July 2012 - 02:19 PM

Ok, here you have, it´s only the first test, my idea was to transform it into a library when it was operative..........:

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using NFC;
using System.Text;

namespace GitHub
{
    public class Program
    {
        //static SPI PN532 = new SPI(new SPI.Configuration(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_NONE, true, 0, 0, false, true, 400, SPI.SPI_module.SPI1));
        static OutputPort NSS = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D10, true);
        static OutputPort CLK = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D13, true);
        static OutputPort MOSI = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D11, true);
        static OutputPort MISO = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D12, true);
        static byte[] pn532ack = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00 };
        static byte[] pn532response_firmwarevers = {0x00, 0xFF, 0x06, 0xFA, 0xD5, 0x03};
        const byte PN532_PACKBUFFSIZ = 64;
        static byte[] pn532_packetbuffer=new byte[PN532_PACKBUFFSIZ];


        public static void Main()
        {

            begin();

            uint versiondata = GetFirmwareVersion();

            while (versiondata==0)
            {
                Debug.Print("\nDidn't find PN53x board");
                // halt  
            }
            
            // Got ok data, print it out!
            Debug.Print("\nFound chip PN5");
            Debug.Print("\n"+((versiondata>>24) & 0xFF));
            Debug.Print("Firmware ver. ");
            Debug.Print("\n "+((versiondata>>16) & 0xFF).ToString());
            Debug.Print(".");
            Debug.Print("\n "+((versiondata>>8) & 0xFF));

        }

        static void begin()
        {
            NSS.Write(false); ;
            Thread.Sleep(1000);  // not exactly sure why but we have to send a dummy command to get synced up  
            pn532_packetbuffer[0] = Constants.PN532_COMMAND_GETFIRMWAREVERSION;
            sendCommandCheckAck(pn532_packetbuffer, 1,3000);
            // ignore response!
        }

        static Boolean sendCommandCheckAck(byte[] buffer,byte buffer_length,int Timeout)
        {
            int Timer=0;

             // write the command  
            WRITE_SPI_COMMAND(buffer, buffer_length);

             // Wait for chip to say its ready!
            while (READ_SPI_STATUS() != Constants.PN532_SPI_READY)
            {
                if (Timeout != 0)
                {
                    Timer+=10;
                    if (Timer > Timeout)
                        return false;
                }    Thread.Sleep(10);
            }

            // read acknowledgement
            if (!SPI_READ_ACK())
            {
                return false;
            }

            Timer = 0;
            // Wait for chip to say its ready!
            while (READ_SPI_STATUS() != Constants.PN532_SPI_READY)
            {
                if (Timeout != 0)
                {
                    Timer+=10;
                    if (Timer > Timeout)
                        return false;
                }
                Thread.Sleep(10);
            }
            
            return true;
        }

        static uint GetFirmwareVersion()
        {
            uint response;

            pn532_packetbuffer[0] = Constants.PN532_COMMAND_GETFIRMWAREVERSION;

            if (!sendCommandCheckAck(pn532_packetbuffer, 1,3000))
                return 0;

            SPI_READ_DATA(pn532_packetbuffer, 12);

            if (0 != String.Compare(pn532_packetbuffer.ToString(), pn532response_firmwarevers.ToString()))
            {
                return 0;
            }

            response = pn532_packetbuffer[6];
            response <<= 8;
            response |= pn532_packetbuffer[7];
            response <<= 8;
            response |= pn532_packetbuffer[8];
            response <<= 8;
            response |= pn532_packetbuffer[9];
            
            return response;
        }

        static void WRITE_SPI_COMMAND(byte[] buffer,byte buffer_length)
        {
            byte checksum;

            buffer_length++;

            Debug.Print("\nSending.....");

            NSS.Write(false); ;
            Thread.Sleep(2);     // or whatever the delay is for waking up the board
            SPI_WRITE(Constants.PN532_SPI_DATAWRITE);

            checksum = Constants.PN532_PREAMBLE + Constants.PN532_PREAMBLE + Constants.PN532_STARTCODE2;
            SPI_WRITE(Constants.PN532_PREAMBLE);
            SPI_WRITE(Constants.PN532_PREAMBLE);
            SPI_WRITE(Constants.PN532_STARTCODE2);

            SPI_WRITE(buffer_length);
            SPI_WRITE((byte)(~buffer_length+1));

            SPI_WRITE(Constants.PN532_HOSTTOPN532);
            checksum += Constants.PN532_HOSTTOPN532;

            Debug.Print(Constants.PN532_PREAMBLE.ToString());
            Debug.Print(Constants.PN532_PREAMBLE.ToString());
            Debug.Print(Constants.PN532_STARTCODE2.ToString());
            Debug.Print(buffer_length.ToString());
            Debug.Print(((byte)(~buffer_length + 1)).ToString());
            Debug.Print(Constants.PN532_HOSTTOPN532.ToString());

            for (byte i = 0; i < buffer_length - 1; i++)
            {
                SPI_WRITE(buffer[i]);
                checksum += buffer[i];
                Debug.Print(buffer[i].ToString());
            }

            

            SPI_WRITE((byte)~checksum);
            SPI_WRITE(Constants.PN532_POSTAMBLE);
            
            NSS.Write(true);

            Debug.Print((byte)(~buffer_length).ToString());
            Debug.Print( Constants.PN532_POSTAMBLE.ToString());
        }


        static byte READ_SPI_STATUS()
        {
            NSS.Write(false);
            Thread.Sleep(2);
            SPI_WRITE(Constants.PN532_SPI_STATREAD);  // read byte
            byte x = SPI_READ();
            NSS.Write(true) ;
            return x;
        }

        static Boolean SPI_READ_ACK()
        {
            byte[] buffer=new byte[6];

            SPI_READ_DATA(buffer,6);

            return (0 == String.Compare(buffer.ToString(), pn532ack.ToString()));
        }

        static void SPI_READ_DATA(byte[] buffer, byte n)
        {
            NSS.Write(false);
            Thread.Sleep(2);
            SPI_WRITE(Constants.PN532_SPI_DATAREAD);

            Debug.Print("\nReading.....");


            for (uint i = 0; i < n; i++)
            {
                Thread.Sleep(1);
                buffer[i] = SPI_READ();
                Debug.Print(buffer[i].ToString());
            }

           
            NSS.Write(true);
        }

        static void SPI_WRITE(byte constant)
        {
            int i,x=1;
            CLK.Write(true); 
            
            for (i = 0; i < 8; i++)
            {
                CLK.Write(false);  
                if ((constant & (x<<(i)))==1)
                {
                    MOSI.Write(true) ;
                } 
                else
                {
                    MOSI.Write(false);
                }
                CLK.Write(true);
            }
        }


I have all the constants in a .cs attached to the proyect.They are the same as the .h file

The code is only to try to have any kind of response from the PN532.

#25 tlmiii01

tlmiii01

    Member

  • Members
  • PipPip
  • 12 posts

Posted 25 July 2012 - 04:25 PM

Is some of the code missing? I don't see where SPI_READ() is defined. Thomas

#26 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 26 July 2012 - 07:38 AM

yes!! Sorry!!!! Here goes:

  static byte SPI_READ()
        {
            
            int    i,x = 0, z = 1;
            CLK.Write(true);

            for (i = 0; i < 8; i++)
            {
                if (MISO.Read())
                {
                    x |= (z<<(i));
                }
                CLK.Write(false);
                CLK.Write(true);
            }

            return ((byte)x);
        }


#27 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 26 July 2012 - 11:43 AM

Hi again!!

I tried it again with I2C, with the GitHub code. But it neither works........here is the code i used:

namespace GitHub_I2C
{
    public class Program
    {
        const int I2CAddress = 0x48;
        const int I2CTimeout = 1000;
        const int I2CClockRateKhz = 200;
        static byte[] write_buffer;
        static byte[] read_buffer;

        static I2CDevice PN532 = new I2CDevice(new I2CDevice.Configuration(I2CAddress, I2CClockRateKhz));

        

        static OutputPort Reset = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D3, false);
        static InputPort Irq= new InputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D2,true,Port.ResistorMode.Disabled);

        static byte[] pn532ack = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00 };
        static byte[] pn532response_firmwarevers = { 0x00, 0xFF, 0x06, 0xFA, 0xD5, 0x03 };
        const byte PN532_PACKBUFFSIZ = 64;
        static byte[] pn532_packetbuffer = new byte[PN532_PACKBUFFSIZ];


        public static void Main()
        {

            begin();

            uint versiondata = GetFirmwareVersion();

            while (versiondata == 0)
            {
                Debug.Print("\nDidn't find PN53x board");
                // halt  
            }

            // Got ok data, print it out!
            Debug.Print("\nFound chip PN5");
            Debug.Print("\n 0x" + ((versiondata >> 24) & 0xFF));
            Debug.Print("Firmware ver. ");
            Debug.Print("\n " + ((versiondata >> 16) & 0xFF).ToString());
            Debug.Print(".");
            Debug.Print("\n " + ((versiondata >> 8) & 0xFF));

        }

        static void begin()
        {
            Reset.Write(true);
            Reset.Write(false);
            Thread.Sleep(400);
            Reset.Write(true);
        }

        static Boolean sendCommandCheckAck(byte[] buffer, byte buffer_length, int Timeout)
        {
            int Timer = 0;

            // write the command  
            WRITE_I2C_COMMAND(buffer, buffer_length);

            // Wait for chip to say its ready!
            while (READ_I2C_STATUS() != Constants.PN532_SPI_READY)
            {
                if (Timeout != 0)
                {
                    Timer += 10;
                    if (Timer > Timeout)
                        return false;
                } Thread.Sleep(10);
            }

            Debug.Print("\n IRQ Received");
            // read acknowledgement
            if (!I2C_READ_ACK())
            {
                Debug.Print("No ack received");
                return false;
            }
            return true;
        }

        static uint GetFirmwareVersion()
        {
            uint response;

            pn532_packetbuffer[0] = Constants.PN532_COMMAND_GETFIRMWAREVERSION;

            if (!sendCommandCheckAck(pn532_packetbuffer, 1, 3000))
                return 0;

            I2C_READ_DATA();

            if (0 != String.Compare(pn532_packetbuffer.ToString(), pn532response_firmwarevers.ToString()))
            {
                return 0;
            }

            response = pn532_packetbuffer[6];
            response <<= 8;
            response |= pn532_packetbuffer[7];
            response <<= 8;
            response |= pn532_packetbuffer[8];
            response <<= 8;
            response |= pn532_packetbuffer[9];

            return response;
        }

        static void WRITE_I2C_COMMAND(byte[] buffer, byte buffer_length)
        {
            byte checksum;
            write_buffer = new byte[8 + buffer_length];

            buffer_length++;

            Debug.Print("\nSending.....");

           
            Thread.Sleep(2);     // or whatever the delay is for waking up the board
            

            checksum = Constants.PN532_PREAMBLE + Constants.PN532_PREAMBLE + Constants.PN532_STARTCODE2;
            write_buffer[0]=(Constants.PN532_PREAMBLE);
            write_buffer[1] = (Constants.PN532_PREAMBLE);
            write_buffer[2] = (Constants.PN532_STARTCODE2);

            write_buffer[3] = (buffer_length);
            write_buffer[4] = ((byte)(~buffer_length + 1));

            write_buffer[5] = (Constants.PN532_HOSTTOPN532);
            checksum += Constants.PN532_HOSTTOPN532;

            Debug.Print(" 0x" + Constants.PN532_PREAMBLE);
            Debug.Print(" 0x" + Constants.PN532_PREAMBLE);
            Debug.Print(" 0x" + Constants.PN532_STARTCODE2);
            Debug.Print(" 0x" + buffer_length);
            Debug.Print(" 0x" + (byte)(~buffer_length + 1));
            Debug.Print(" 0x" + Constants.PN532_HOSTTOPN532);

            for (byte i = 0; i < buffer_length - 1; i++)
            {
                write_buffer[6 + i] = buffer[i] ;
                checksum += buffer[i];
                Debug.Print("0x" + buffer[i]);
            }



            write_buffer[6+buffer_length-1]=((byte)~checksum);
            write_buffer[6 + buffer_length] = (Constants.PN532_POSTAMBLE);

            var transaction = new I2CDevice.I2CTransaction[] 
                {
                    I2CDevice.CreateWriteTransaction(write_buffer)
                };

            PN532.Execute(transaction, I2CTimeout);

            Debug.Print(" 0x" + (byte)(~buffer_length));
            Debug.Print(" 0x" + Constants.PN532_POSTAMBLE);
        }


        static byte READ_I2C_STATUS()
        {
            if (Irq.Read()==true)
                return Constants.PN532_I2C_BUSY;
            else
                return Constants.PN532_I2C_READY;
        }

        static Boolean I2C_READ_ACK()
        {
            byte[] buffer = new byte[6];

            I2C_READ_DATA();
            buffer = read_buffer;

            return (0 == String.Compare(buffer.ToString(), pn532ack.ToString()));
        }

        static void I2C_READ_DATA()
        {
            
            Thread.Sleep(2);

            Debug.Print("\nReading.....");

            var transaction = new I2CDevice.I2CTransaction[] 
                {
                    I2CDevice.CreateReadTransaction(read_buffer)
                };

            PN532.Execute(transaction, I2CTimeout);

            for (uint i = 0; i < read_buffer.Length; i++)
            {
                Thread.Sleep(1);
                Debug.Print(read_buffer[i].ToString());
            }
        }

        
    }
}



#28 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 26 July 2012 - 12:25 PM

Ok, here you have, it´s only the first test, my idea was to transform it into a library when it was operative..........:

I have all the constants in a .cs attached to the proyect.They are the same as the .h file

The code is only to try to have any kind of response from the PN532.


Looks like you are bitbanging the SPI interface here, will probably be too slow to work properly, try using the managed SPI interface and sending the byte arrays, SPI doesnt have a read command, you can either write a byte array, or do a simultaneous write read, so you write and fill a read buffer at the same time.

If i have time after work i will try and reimplement your code to use the SPI object..

Nak.

#29 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 27 July 2012 - 09:24 AM

I did it. But nothing........what do you think abaut the code????:

Maybe I have to try to write the PN532_SPI_READY byte first????

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
using NFC;
using System.Text;

namespace GitHub
{
    public class Program
    {
        static SPI PN532 = new SPI(new SPI.Configuration(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D0, true, 0, 0, false, true, 400, SPI.SPI_module.SPI1));
        //static OutputPort NSS = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D10, true);
        //static OutputPort CLK = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D13, true);
        //static OutputPort MOSI = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D11, true);
        //static OutputPort MISO = new OutputPort(SecretLabs.NETMF.Hardware.Netduino.Pins.GPIO_PIN_D12, true);
        static byte[] pn532ack = { 0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00 };
        static byte[] pn532response_firmwarevers = {0x00, 0xFF, 0x06, 0xFA, 0xD5, 0x03};
        const byte PN532_PACKBUFFSIZ = 64;
        static byte[] pn532_packetbuffer=new byte[PN532_PACKBUFFSIZ];


        public static void Main()
        {

            begin();

            uint versiondata = GetFirmwareVersion();

            while (versiondata==0)
            {
                Debug.Print("\nDidn't find PN53x board");
                // halt  
            }
            
            // Got ok data, print it out!
            Debug.Print("\nFound chip PN5");
            Debug.Print("\n 0x"+((versiondata>>24) & 0xFF));
            Debug.Print("Firmware ver. ");
            Debug.Print("\n "+((versiondata>>16) & 0xFF).ToString());
            Debug.Print(".");
            Debug.Print("\n "+((versiondata>>8) & 0xFF));

        }

        static void begin()
        {
            //NSS.Write(false); ;
            Thread.Sleep(1000);  // not exactly sure why but we have to send a dummy command to get synced up  
            pn532_packetbuffer[0] = Constants.PN532_COMMAND_GETFIRMWAREVERSION;
            sendCommandCheckAck(pn532_packetbuffer, 1,500);
            // ignore response!
        }

        static Boolean sendCommandCheckAck(byte[] buffer,byte buffer_length,int Timeout)
        {
            int Timer=0;

             // write the command  
            WRITE_SPI_COMMAND(buffer, buffer_length);

             // Wait for chip to say its ready!
            while (READ_SPI_STATUS() != Constants.PN532_SPI_READY)
            {
                if (Timeout != 0)
                {
                    Timer+=10;
                    if (Timer > Timeout)
                        return false;
                }    Thread.Sleep(10);
            }

            // read acknowledgement
            if (!SPI_READ_ACK())
            {
                return false;
            }

            Timer = 0;
            // Wait for chip to say its ready!
            while (READ_SPI_STATUS() != Constants.PN532_SPI_READY)
            {
                if (Timeout != 0)
                {
                    Timer+=10;
                    if (Timer > Timeout)
                        return false;
                }
                Thread.Sleep(10);
            }
            
            return true;
        }

        static uint GetFirmwareVersion()
        {
            uint response;

            pn532_packetbuffer[0] = Constants.PN532_COMMAND_GETFIRMWAREVERSION;

            if (!sendCommandCheckAck(pn532_packetbuffer, 1,500))
                return 0;

            SPI_READ_DATA(pn532_packetbuffer);

            if (0 != String.Compare(pn532_packetbuffer.ToString(), pn532response_firmwarevers.ToString()))
            {
                return 0;
            }

            response = pn532_packetbuffer[6];
            response <<= 8;
            response |= pn532_packetbuffer[7];
            response <<= 8;
            response |= pn532_packetbuffer[8];
            response <<= 8;
            response |= pn532_packetbuffer[9];
            
            return response;
        }

        static void WRITE_SPI_COMMAND(byte[] buffer,byte buffer_length)
        {
            byte checksum;

            buffer_length++;

            Debug.Print("\nSending.....");

            //NSS.Write(false); ;
            Thread.Sleep(2);     // or whatever the delay is for waking up the board
            SPI_WRITE(Constants.PN532_SPI_DATAWRITE);

            checksum = Constants.PN532_PREAMBLE + Constants.PN532_PREAMBLE + Constants.PN532_STARTCODE2;
            SPI_WRITE(Constants.PN532_PREAMBLE);
            SPI_WRITE(Constants.PN532_PREAMBLE);
            SPI_WRITE(Constants.PN532_STARTCODE2);

            SPI_WRITE(buffer_length);
            SPI_WRITE((byte)(~buffer_length+1));

            SPI_WRITE(Constants.PN532_HOSTTOPN532);
            checksum += Constants.PN532_HOSTTOPN532;

            Debug.Print(" 0x" + Constants.PN532_PREAMBLE);
            Debug.Print(" 0x" + Constants.PN532_PREAMBLE);
            Debug.Print(" 0x" + Constants.PN532_STARTCODE2);
            Debug.Print(" 0x" + buffer_length);
            Debug.Print(" 0x" + (byte)(~buffer_length + 1));
            Debug.Print(" 0x" + Constants.PN532_HOSTTOPN532);

            for (byte i = 0; i < buffer_length - 1; i++)
            {
                SPI_WRITE(buffer[i]);
                checksum += buffer[i];
                Debug.Print("0x"+buffer[i]);
            }

            

            SPI_WRITE((byte)~checksum);
            SPI_WRITE(Constants.PN532_POSTAMBLE);
            
            //NSS.Write(true);

            Debug.Print(" 0x" + (byte)(~buffer_length));
            Debug.Print(" 0x" + Constants.PN532_POSTAMBLE);
        }


        static byte READ_SPI_STATUS()
        {
            //NSS.Write(false);
            Thread.Sleep(2);
            SPI_WRITE(Constants.PN532_SPI_STATREAD);  // read byte
            byte x = SPI_READ();
            //NSS.Write(true) ;
            return x;
        }

        static Boolean SPI_READ_ACK()
        {
            byte[] buffer=new byte[6];

            SPI_READ_DATA(buffer);

            return (0 == String.Compare(buffer.ToString(), pn532ack.ToString()));
        }

        static void SPI_READ_DATA(byte[] buffer)
        {
            //NSS.Write(false);
            int i=0;
            Thread.Sleep(2);
            SPI_WRITE(Constants.PN532_SPI_DATAREAD);

            Debug.Print("\nReading.....");


            /*for (uint i = 0; i < n; i++)
            {
                Thread.Sleep(1);
                buffer[i] = SPI_READ();
                Debug.Print(" 0x" + buffer[i]);
            }*/

            
            while(buffer[i]!=Constants.PN532_POSTAMBLE)
            {
                Thread.Sleep(1);
                buffer[i] = SPI_READ();
                i++;
            }

           
            //NSS.Write(true);
        }

        static void SPI_WRITE(byte constant)
        {

            byte[] buffer = new byte[1] ;
            /*CLK.Write(true); 
            
            for (i = 0; i < 8; i++)
            {
                CLK.Write(false);  
                if ((constant & (x<<(i)))==1)
                {
                    MOSI.Write(true) ;
                } 
                else
                {
                    MOSI.Write(false);
                }
                CLK.Write(true);
            }*/
            buffer[0] = constant;
            PN532.Write(buffer);
        }

        static byte SPI_READ()
        {

            byte x;
            byte[] Buffer=new byte[1];
            byte[] Read_buffer=new byte[1];
            /*CLK.Write(true);

            for (i = 0; i < 8; i++)
            {
                if (MISO.Read())
                {
                    x |= (z<<(i));
                }
                CLK.Write(false);
                CLK.Write(true);
            }*/
            Buffer[0]=Constants.PN532_SPI_DATAREAD;
            PN532.WriteRead(Buffer,Read_buffer);
            x = Read_buffer[0];
            return (x);
        }
    }
}



#30 tlmiii01

tlmiii01

    Member

  • Members
  • PipPip
  • 12 posts

Posted 27 July 2012 - 12:07 PM

One thing you might want to try is to create the entire command array first, then Write the entire command buffer. In the Arduino code, it looks like they hold the CS pin low while writing the individual bytes, then sets the CS pin high. On the Netduino, the CS pin changes state with each Write. Thomas

#31 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 23 August 2012 - 07:37 AM

Hello! Sorry but I´ve been in holidays and I wanted to forget everything for some days, that sometimes is necessary to come back with more energy :lol: . I was thinking and the problem may be that Netduino doesn´t manage the SS pin(that I was thinking that it does in pin 10)??? So before each writing action I have to put down a pin conected to SS of the shield. May it be a possible solution?? I´ll do some trys.....

#32 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 27 August 2012 - 10:40 AM

Finally a friend borrowed me an Arduino, and I tried the shield with I2C and Arduino, and it works, so the problem has to be the CS signal and the way of managing it...............Maybe now the way would be to try to use a logic analyser as Setefan suggested!! I´m used to Tektronix ones but I don´t have any..Could you suggest a good one, or maybe they are too expensive?? :huh:

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.



#33 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 28 August 2012 - 01:09 PM

Hi Gomore These are really good and under $200 http://www.saleae.com/logic/ I have one of these http://www.ikalogic....s/scanalogic-2/ and find it to be invaluable and it was pretty cheap as well < $60 As for the CS line are you using the SPI object or still trying to bit bang the interface? Bitbanging will probably be to slow but if you take the command and control logic out of the arduino code and use it in C# with the spi objects it "should" just work... Nak.

#34 tlmiii01

tlmiii01

    Member

  • Members
  • PipPip
  • 12 posts

Posted 28 August 2012 - 01:31 PM

I also use the Saleae Logic. It has been extremely useful in troubleshooting issues like these. I have run into issues with the CS line before with my Netduino. I had to put a resistor (around 200 ohms) in series with the with the CS pin. I've seen other posters have had the same problem. Something else to try... Thomas

#35 haxburgen

haxburgen

    Member

  • Members
  • PipPip
  • 21 posts

Posted 14 February 2013 - 01:31 AM

Hi all, has this issue been resolved? Looking to integrate nfc into my current project.



#36 NoxiaZ

NoxiaZ

    Member

  • Members
  • PipPip
  • 12 posts

Posted 14 February 2013 - 10:14 AM

Hey guys, I am also interested in hearing about you resolved the problem or found another solution :)

 

 

 



#37 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 14 February 2013 - 03:39 PM

hm iam wondering why you bitbang the data, and not use the normal spi/i2c classes, that would be a lot faster and way less code, less errors and such. i dont have such a device so i cant try, but except some really exotic devices all is kinda "standard" that just works with netduino

- ofc the right code for accessing the right registers at the right time is still needed.



#38 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 21 February 2013 - 10:30 AM

Hi all again.

 

Has someone tried to use I2C with Netduino 2??? I see that the pinset is a bit different know, and matches exactly with the nfc shield ones.............Has something changed in the I2C class in the framework?????? Wicth is the difference between Arduino and Netduino in the way of manage the I2C bus(the CS pin??). Thank you im still trying to to get this shield working on Netduino............



#39 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 21 February 2013 - 12:04 PM

i2c does not have/need a cs (chipselect) pin. it access the device with an address.

maybe the pin is used for something else.



#40 gomore11

gomore11

    Advanced Member

  • Members
  • PipPipPip
  • 87 posts

Posted 26 February 2013 - 08:16 AM

Oh!! Sorry..........you are wright........I got confused with I2C and SPI becouse of the lots of tryes Ive  done. But my cuestion its obout the I2C and netduino 2..............finally I bought a logic analyzer (one from ikalogic especially designed to analize comunications) and Im waiting to it to come. Ill post the results of the tests to see if we can do something..........






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.