Forum - MCS Electronics
View previous topic :: View next topic
Author
Message
pinkfloyd11 Joined: 02 Jul 2007 Posts: 247
Posted: Fri Nov 07, 2008 9:47 pm Post subject: can you help me to correct the code?
Dear Friends
I'm developing an RFID application with Mifare MFRC500 chip and atmega16.
In attachment you can found how hardware is configured, and timing diagram for read and write.
I would read and write the 64 register of MFRC500.
My problem is that "I always read the "address" and not the value written into register .
I explane me better: If I would read from register "FF", I set the address to "FF" and the value read is..... "FF"
The same happen with all other value.
Here the code:
$regfile = "m16def.dat"
$hwstack = 32
$swstack = 8
$framesize = 24
$crystal = 8000000
$baud = 19200
Declare Sub Set_address()
Declare Sub Read()
Declare Sub Read_Registry()
Declare Sub Write_registry()
Dim Address_in_hex As String * 2
Dim Value_read As Byte
Dim Value_to_write As Byte
Config Portd.4 = Output
Led_rosso Alias Portd.4
Config Portb.4 = Output
Led_verde Alias Portb.4
Config Portc.2 = Output
Not_read_enable Alias Portc.2
Config Portc.3 = Output
Not_write_enable Alias Portc.3
Config Portc.4 = Output
Not_chip_select Alias Portc.4
Config Portc.5 = Output
Address_latch_enable Alias Portc.5
Config Portd.7 = Output
Read_reset Alias Portd.7
'____________________________________________________________
'MAIN
Do
Address_in_hex = "29"
Value_to_write = 253
Call Write_registry
Wait 1
Call Read_Registry()
Print "Value Read = " ; Hex(Value_read )
Loop
'____________________________________________________________
Sub Read_Registry()
Reset Address_latch_enable
Waitms 50
Set Not_read_enable
Waitms 50
Set Not_chip_select
Set Address_latch_enable
Waitms 50
Call Set_address()
Waitms 50
Reset Address_latch_enable
Waitms 50
Reset Not_chip_select
Waitms 50
Reset Not_read_enable
Waitms 50
Call Leggi
Waitms 50
Set Not_read_enable
Waitms 50
Set Not_chip_select
End Sub
'____________________________________________________________
Sub Write_Registry()
Reset Address_latch_enable
Set Not_read_enable
Set Not_chip_select
Config Porta = Output
Set Address_latch_enable
Call Set_address()
Reset Address_latch_enable
Reset Not_chip_select
Reset Not_write_enable
PortA = value_to_write
Set Not_read_enable
Set Not_chip_select
End Sub
'____________________________________________________________
Sub Read()
Config PortA = Input
Value_read = PinA
End Sub
'____________________________________________________________
Sub Set_address()
Dim Address_in_byte As Byte
Indirizzo_in_byte = Hexval(Address_in_hex)
Config PortA = Output
PortA = Address_in_byte
End Sub
[/img]
Back to top
kubic Joined: 03 Nov 2008 Posts: 42
Posted: Sat Nov 08, 2008 7:19 am Post subject:
Hi,
There are 2 errors that are not in your posted code
Indirizzo_in_byte = Hexval(Address_in_hex)
Call Leggi
can it be thay you wait to long/short before you read ?
Call Write_registry()
Wait 1 '
Call Read_Registry()
there are alot of info on the Inet but only i C code
Try Google for MC081380.zip
If you try the simulator in bascom and push icon show Hardware emulation
you can test if you get input right just click on the green ledīs for port A
Back to top
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