Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

rfid pn532

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 71

poland.gif
PostPosted: Tue Aug 21, 2018 9:23 am    Post subject: rfid pn532 Reply with quote

Hello,

i\'m during bulding my project where need to use RFID/NFC PN532 13,56MHz I2C/SPI. I\'ve ordered one to test but meantime would like to learn about how to program it basing on i2c. I\'ve read from datasheet that it use
- Mifare 1k, 4k, Ultralight, carts DesFire
- cards ISO/IEC 14443-4 i.e. CD97BX, CD light, Desfire, P5CN072 (SMX)
- cards Innovision Jewel i.e. IRT500
- cards FeliCa i.e. RCS_860 oraz CS_854

Maybe someone got similar project and could share experience. Simply I have any idea how to begin.

Martin

(BASCOM-AVR version : 2.0.7.6 , Latest : 2.0.8.1 )
Back to top
View user's profile
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 71

poland.gif
PostPosted: Sat Aug 25, 2018 1:55 pm    Post subject: Reply with quote

Hello,

I know from datasheet that pn532 has an address &H48. I also have it proven by i2c scanner.
So I thought that simply frame may look like:

asking:
-i2c address
-function

response:
-i2c addres
-response


Code:

\\\' Ask for firmware version
 I2cstart
 I2cwbyte &H48 \\\'i2c address
 I2cwbyte &H02 \\\'function getFirmawareVersion command - datasheet
 I2cstop
 Waitms 5

\\\'get response with firmware version
 I2cstart
 I2cwbyte &H48
 I2crbyte FV, Nack \\\'THERE Should be whatever
 I2cstop

 Print hex(FV)
 


FV=48H but this my address and if I change address into new, always I get FV=new address.
Is an idea of i2c described in the above code correct?

Martin
Back to top
View user's profile
MWS

Bascom Member



Joined: 22 Aug 2009
Posts: 1830

blank.gif
PostPosted: Sat Aug 25, 2018 3:35 pm    Post subject: Reply with quote

krolikbest wrote:
that pn532 has an address &H48

Bascom I2C commands require addresses in 8-bit format including the r/w bit, while usually addresses are given as 7 bit.
Additionally the shown code does not resemble a proper way to do an I2C-read.
Where's the read-address for example? Learn some basics about I2C communication first.
Back to top
View user's profile
krolikbest

Bascom Member



Joined: 02 Jan 2017
Posts: 71

poland.gif
PostPosted: Mon Aug 27, 2018 8:21 pm    Post subject: Reply with quote

So i attach working code for reading "version info" from pn532 in i2c mode. Maybe someone use it ..
Code:

$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 115200                                              
$hwstack = 80                                              
$swstack = 80                                              

$framesize = 90                                            
Dim K As Byte
Dim M As Word

Dim Zapyt(9) As Byte
Dim Wake_up(4) As Byte
Dim dane(19) As Byte

Dim addr_w as byte
Dim addr_r as byte

Wake_up(1) = &H55
Wake_up(2) = &H00
Wake_up(3) = &H00
Wake_up(4) = &H00

Zapyt(1) = &H00
Zapyt(2) = &H00
Zapyt(3) = &HFF
Zapyt(4) = &H02
Zapyt(5) = &HFE
Zapyt(6) = &HD4
Zapyt(7) = &H02
Zapyt(8) = &H2A
Zapyt(9) = &H00

'I2C
Config I2cdelay = 10
Config Twi = 100000
Config Scl = Portc.5
Config Sda = Portc.4

$lib "I2C_TWI.LBX"

I2cinit
'print dane(1).7 ; " " ; dane(3).7

addr_w=&H48
addr_r=&H49

Do

 I2cstart
  I2cwbyte addr_w


 ' for m=1 to 4
 '   I2cwbyte wake_up(m)
 ' next m

  for m=1 to 9
    I2cwbyte zapyt(m)
  next m

 I2cstop

 waitms 50

 I2cstart
  I2cwbyte addr_r

  for k=1 to 18
   I2crbyte Dane(k) , Ack
  next

  I2crbyte Dane(19) , NAck
 I2cstop

 For K = 1 To 19
  Print K ; "  " ; Hex(dane(k))
 Next

 wait 1

Loop

End
 
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum