Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F45k22 and RC522 rfid

Status
Not open for further replies.

paulpauls

Newbie level 2
Joined
Mar 1, 2018
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
36
Hi, I am new to using pic micro controller but I have much experience in using arduino. I am working on a school project that involves using PIC18F45k22 and a rfid module. I have done some research and done some simulation in proteus but the output is not the same from my input. I have tried removing the max232 and had the desired output in simulation. When connecting the hardware with and without max232 I get no output. I am using MikroC Pro for PIC for my code. My questions are:

1. Do I need to connect the RC522 as SPI or is there a way to use just uart and max232.
2. Do I need a library for RC522? Because I am using mikroC PRO for pic.

Will post my code and simulation.

Screenshot_7.png
 

Attachments

  • rfid.txt
    1.8 KB · Views: 110

According to the RC522 data sheet that I've found on the internet, it says that the device has a UART, but then (to my mind rather confusingly) says that it is "...similar to RS232 with voltage levels dependent on pin voltage levels".
That means that you need to look further in the data sheet for, in this case, a section labelled 'Recommended Operating Conditions' which says that the supply for the chip (both Vddd and Vdda) should be typically 3.3v (and 3.6V max). If you look in Seciton 14 ("Characteristics") there is an entry for the 'Rx' pin that the says the input voltage is between -1V and Vdda+1. There is also a footnote that says that it is clamped tobe tween AVSS and AVDD (which is also confusing!) but really means between 0V and Vdda or 3.3V.
Now you need to look at the data sheet for the PIC18F45k22 where you will see that it also runs at 3.3V. The data sheet will also tell you that the I/O pins use the same voltage range but this is quite common.
Therefore this all tells you that you do not need the MAX232 (look up what it does and the voltages it outputs on the RS232 side and you will see why it is not appropriate) as the voltages on the PIC and the RC522 are the same.
As to why your code works in simulation and not on the real hardware, this shows up one of the big problems with simulators - they tend to simulate the code execution parts only.
I can't see on your schematic where you have bypass capacitors but you will need to ensure that there are 100nF capacitors between the Vss and Vdd pins (normally as close to the pins as possible) to help ensure the MCU has a clean supply voltage.
Also, you have tied \MCLR\ high which is possible but Figure 4-2 of the data sheet shows the preferred way. Also you need to consider if you have ICSP capability in which case you need to look a how that is connected, especially to the \MCLR\ pin.
With respect to your code, it looks OK (but I don't use MikroC so I assume a lot of it is relying on runtime library calls) but I can't see the config settings which can be very important in setting up the MCU correctly. For example, your code does not set the oscillator so I assume you are usign the FOSC config setting to an appropriate setting for whatever frequency crystal you are using (I can't see the frequency mentioned on the schematic).
In your code you have a variable 'b' that is initialised to 0 and (as far as I can see) only ever used at the start of the main loop to set 'rfid[0]' to the null character.
However you then fill the 'rfid' array with 8 characters (which is OK as far as that goes) but then you pass the rfid array to the 'Lcd_Out' function. I would almost bet that the 'Lcd-Out' function is expecting a pointer to a null-terminated string as its 3rd parameter but this is not necessarily the case with your code (and looking at the previous use of the function to set the text of 'line 1').
For a start 'rfid' is only 8 characters long and you are already using 8 characters that you are reading in. Therefore there is no room for the terminating null character. You need to make 'rfid' at least 9 in size and set "rfid[8]='\0';" (or whatever is appropriate for your situation.
There may well be other reasons why your hardware is not working but you have not told us anything in that area. For example, are you getting any characters on the LCD (for example the first line of "RFID Tag Reader")?
I can't see the RC522 in your schematic, but are you setting the 'I2C' and 'EA' pins correctly to tell it to use the UART interface?
(Is that even the right schematic as it shows a keyboard that you are not using and does not show the RC522 which you say you are. Also I don't think the MAX232 (which we've determined you don't need) is necessarily connected up correctly.)
Susan
 


Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top