CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

RC522 RFID module SPI
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 1:57 pm     Reply with quote

I had some issues today which I can't fix before Friday :(.

Anyway I am not too sure how to connect the Reset. In this thread he guys claimed RST is connected to ground?
On some other schematics I see rst connect to 3.3V
Quote:
NRSTPD
reset and power-down input:
power-down: enabled when LOW; internal current sinks are switched off, the oscillator
is inhibited and the input pins are disconnected from the outside world
reset: enabled by a positive edge

I guess NRSTPD refers to the RST pin on the module. Thats the statement from the datasheet.
Ttelmah



Joined: 11 Mar 2010
Posts: 12517

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 2:29 pm     Reply with quote

The 'N' is a standard abbreviation for -ve. The PD input needs to be high, or the whole chip is disabled. However the data sheet suggests that the RST is an _edge triggered_ signal, with a reset triggered by the rising edge. I'd certainly tie it to +5v, but if it is edge triggered it may well be OK to have it just held to either rail.
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 3:48 pm     Reply with quote

Ttelmah wrote:
The 'N' is a standard abbreviation for -ve. The PD input needs to be high, or the whole chip is disabled. However the data sheet suggests that the RST is an _edge triggered_ signal, with a reset triggered by the rising edge. I'd certainly tie it to +5v, but if it is edge triggered it may well be OK to have it just held to either rail.


Since the entire chip works on 3.3V I guess I have to tie it up to 3.3 instead of 5V, correct?

I read some RFID MFRC522 libraries for Arduino to easily access the reader.
It is quiet cumbersome to understand the relation between every register and since we lack of time in this project I decided to adjust/port a proper library to PIC C. The library looks quiet ok and what I have to do is basically change the semantics to use it with CCS C Compiler,correct?

https://github.com/ljos/MFRC522

looks like a good one, but it is .cpp, dunno if CCS can handle cpp on the other hand I can just rewrite it without using a class
temtronic



Joined: 01 Jul 2010
Posts: 5755
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 21, 2017 5:24 pm     Reply with quote

...as for the hardware, just use a 3 volt power supply and keep set the PIC clock at 8MHz. This will interface properly however you might have damaged the RFID device from supplying 5 volts. It's best to read it's datasheet to see what the maximum any pin on the RFID device can have. Hopefully it's OK...

...as for software, porting over the A-code is in itself quite a task but will work ONCE you've got the basics down. You should be able to write a register as plenty of people have responded to you already.

I can't supply any working code as I don't have the RFID device to test. While I could write 'pseudo-code' without hands on testing, it's still a guess. Sending you code that should work might not due to a hardware problem, like 2 pins shorted on your PCB.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 12517

View user's profile Send private message

PostPosted: Wed Nov 22, 2017 2:17 am     Reply with quote

Quote:

Since the entire chip works on 3.3V I guess I have to tie it up to 3.3 instead of 5V, correct?


Yes the old "90% of PIC's still use 5v" slip..... Very Happy
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Wed Nov 22, 2017 6:01 am     Reply with quote

temtronic wrote:
...as for the hardware, just use a 3 volt power supply and keep set the PIC clock at 8MHz. This will interface properly however you might have damaged the RFID device from supplying 5 volts. It's best to read it's datasheet to see what the maximum any pin on the RFID device can have. Hopefully it's OK...

...as for software, porting over the A-code is in itself quite a task but will work ONCE you've got the basics down. You should be able to write a register as plenty of people have responded to you already.

I can't supply any working code as I don't have the RFID device to test. While I could write 'pseudo-code' without hands on testing, it's still a guess. Sending you code that should work might not due to a hardware problem, like 2 pins shorted on your PCB.

Jay


I did not run the RFID with 5 Volts. It should be fine.
I know how to read and write registers but the MFRC522 is just not easy to use because a lot of registers depend on each other. In my previous assignments we used easier chip where we could read 1 or 2 registers in order to receive a value like temperature.

If I read the library now I have to use at least 5-10 registers before and some of them every time I want to read a UID.

A pseudo code would make my day Laughing

Thank you though Smile
temtronic



Joined: 01 Jul 2010
Posts: 5755
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Nov 22, 2017 6:01 pm     Reply with quote

Honestly that's what programming is ! Reading hundreds of pages of datasheets, spending weeks cutting code, and drinking pots of coffee into the wee hours to LEARN how to use 'chips'. I've got 5+ decades doing this, last 2 just using PICs and learn something new everyday.
While the RFID device is complicated, there are probably default or factory settings that will allow the device to operate in 'basic' mode.
You can 'cheat' by seeing what others have done, perhaps on another micro. If they use C, you can 'transpose' into CCS C. That is not really hard.

Jay
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Thu Nov 23, 2017 12:44 am     Reply with quote

temtronic wrote:
Honestly that's what programming is ! Reading hundreds of pages of datasheets, spending weeks cutting code, and drinking pots of coffee into the wee hours to LEARN how to use 'chips'. I've got 5+ decades doing this, last 2 just using PICs and learn something new everyday.
While the RFID device is complicated, there are probably default or factory settings that will allow the device to operate in 'basic' mode.
You can 'cheat' by seeing what others have done, perhaps on another micro. If they use C, you can 'transpose' into CCS C. That is not really hard.

Jay


That exactly what I wanted to do with the RFID Arduino library, it is C++ but that should not be a problem for me to translate.
I am interested in learning more about that chip and reading the registers etc. Its just due too my limited time. My group members decided to do that project without telling me and they can't even print stuff on a LCD and now everything relies on me and I have got a lot of assigments left and cant spent a lot of time each day. It just the circumstances which makes it impossible for me to figure it out completely alone.
temtronic



Joined: 01 Jul 2010
Posts: 5755
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 25, 2017 8:31 pm     Reply with quote

Well I've ordered one and 3 fobs for a 'Winter project' direct from China, should be 16 days to get them based on the last parts I got.
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 10:46 am     Reply with quote

Cool beans,

I have another Question. I have an Arduino Mega here and the RFID reader is working perfectly fine. Anyway I need to use PIC16...

First step is reading the firmware version in the same order as I am doing it with Arduino but the "result" is fluctuating and giving me wrong value/version number.

I measured all the Voltage levels from Arduino to RFID and from PIC16 to RFID the only difference I can measure is that MOSI of PIC is under 1mV and on Arduino it is 3V.

Isnt 1mV too low? Despite that fact the MC3202-C ADC is working fine with that voltage levels.
Can I adjust the Voltage level somehow?
I initialize SPI as follows
Quote:
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);


Indeed, I need to hook up an oscilloscope on Tuedsay to have legit results.
Ttelmah



Joined: 11 Mar 2010
Posts: 12517

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 11:36 am     Reply with quote

You are selecting SPI Mode1. With this the clock _idles_ low.
I think the 522 uses mode0.

SPI_L_TO_H | SPI_XMIT_L_TO_H
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 12:17 pm     Reply with quote

Sounds reasonable but didnt change anything unfortunately

Thats all I want to do know because the rest will be selfexplaining once i get to write/read one register.

Quote:

output_low(CS);
//spi_write(((VersionReg<<1)&0x7E) | 0x80);
// version = spi_read(0x00);
version =spi_read(((VersionReg<<1)&0x7E) | 0x80);
output_high(CS);



if(!version)
{
lcd_clear();
text = "not found";
lcd_gotoxy(1, 1);//go to position 1,1 on lcd
lcd_print(text);
}
if(version)
{

lcd_clear();
text = "Module found";
lcd_gotoxy(1, 1);//go to position 1,1 on lcd
lcd_print(text);//print on lcd
sprintf(buffer,"%2X",(version)); //display version in hexadecimal
lcd_gotoxy(1, 2); //go to second line of lcd
lcd_print(buffer);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 20102

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 12:28 pm     Reply with quote

You didn't give us a full program there. Show us the #define statement
for 'VersionReg'.
Mario_KA



Joined: 16 Nov 2017
Posts: 22

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 12:36 pm     Reply with quote

Quote:

#include <main.h>
#include <lcd16216.c>
#define VersionReg 0x37

//spi modes
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)

char buffer[17],text[17];

byte version;
void main()
{
// setup_oscillator(OSC_8MHZ, 3); //Adjust Oscillator for proper Serial Communication
setup_spi(SPI_MASTER|SPI_MODE_0|SPI_CLK_DIV_16);
lcd_init();
lcd_clear();
output_high(CS);

while(TRUE)
{
output_low(CS);

//spi_write(((VersionReg<<1)&0x7E) | 0x80);
version =spi_read(((VersionReg<<1)&0x7E) | 0x80);;
output_high(CS);

if(!version)
{
lcd_clear();
text = "not found";
lcd_gotoxy(1, 1);
lcd_print(text);
}
if(version)
{

lcd_clear();
text = "Module found";
lcd_gotoxy(1, 1);
lcd_print(text);//print on lcd
sprintf(buffer,"%2X",(version));
lcd_gotoxy(1, 2);
lcd_print(buffer);
}

delay_ms(500);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 20102

View user's profile Send private message

PostPosted: Sun Nov 26, 2017 12:59 pm     Reply with quote

Instead of this,
Mario_KA wrote:

output_low(CS);
//spi_write(((VersionReg<<1)&0x7E) | 0x80);
version =spi_read(((VersionReg<<1)&0x7E) | 0x80);;
output_high(CS);


Try calling the read routine that was posted earlier in this thread.
Substitute the following line for the code listed above:
Code:
version = MFRC522_read(VersionReg);


Put this routine above main():
Code:
int8 MFRC522_read(int8 addr)
{
int8 retval;

output_low(MFRC522_CS_PIN);
spi_write(((addr << 1) & 0x7E) | 0x80);
retval = spi_read(0x00);
output_high(MFRC522_CS_PIN);

return(retval);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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


Powered by phpBB © 2001, 2005 phpBB Group