View previous topic :: View next topic |
Author |
Message |
krolikbest
Joined: 02 Jan 2017 Posts: 112
|
Posted: Tue Aug 21, 2018 9:23 am Post subject: rfid pn532 |
|
|
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 |
|
|
krolikbest
Joined: 02 Jan 2017 Posts: 112
|
Posted: Sat Aug 25, 2018 1:55 pm Post subject: |
|
|
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 |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Aug 25, 2018 3:35 pm Post subject: |
|
|
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 |
|
|
krolikbest
Joined: 02 Jan 2017 Posts: 112
|
Posted: Mon Aug 27, 2018 8:21 pm Post subject: |
|
|
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 |
|
|
|