Forums

PIC 18f with RFID! communication problem!

Started by ishka June 30, 2015
Hi,
I am trying to interface RFID(RFid click which uses CR95HF 13.56 MHz
contactless transceiver as well as trace antenna) with PIC18F8722. It used
SPI communication.
I am trying to get its eco-response but there is no output! I checked
using oscilloscope the spi_write operation which is perfectly fine but i
guess the problems is in read operation. i am attaching my code. Any help
would be appreciated.  I am using MPLAB X v3.0 with C8 compiler v1.34. 


#include <p18f8722.h>
#include <stdio.h>
#include <stdlib.h>
#include <spi.h>
#include <xc.h>
#include <delays.h> 
#include "display_LCD.h" 

// CR95HF Commands Definition
#define    ECHO                   0x55

#define SSI_1 PORTFbits.RF7 // RA2
#define SSI_0 PORTDbits.RD7 // RE1
#define IRQ_IN PORTCbits.RC0
#define CS_rfid PORTEbits.RE0

void main() {
    
  MCU_Init();                           // Initialize MCU and peripherals
  
  EchoResponse();
  
}

void MCU_Init(){

  // Configure RFid Click pins
   ADCON1 = 0b1111; // set all bits of port a as digital
  TRISEbits.RE0= 0;
  TRISCbits.RC0=0;
  TRISDbits.RD7=0;
  TRISFbits.RF7=0;
  
  OpenSPI2(SPI_FOSC_64, MODE_10, SMPEND);   // Initialize SPI module
  IRQ_IN=0; 
  CS_rfid = 0;
  // Set in SPI mode 
  SSI_1=0;
  SSI_0=1;

  
}


char EchoResponse() {
  CS = 0;
    WriteSPI2(0x00);  // Send cmd to CR95HF
    WriteSPI2(ECHO);
  CS = 1;
  while(1){
    CS = 0;
      WriteSPI2(0x03);
      tmp = ReadSPI2;
    CS = 1;
    display_LCD_l(tmp);
     
    if((res & 0x08) >> 3){
      CS = 0;
      WriteSPI2(0x02);
      tmp = ReadSPI2;
      CS = 1;
      if(tmp == ECHO){
        return 1;
      }
      return 0;
    }
  }
}


---------------------------------------
Posted through http://www.EmbeddedRelated.com
On Tue, 30 Jun 2015 09:49:50 -0500, ishka wrote:

> Hi, > I am trying to interface RFID(RFid click which uses CR95HF 13.56 MHz > contactless transceiver as well as trace antenna) with PIC18F8722. It > used SPI communication. > I am trying to get its eco-response but there is no output! I checked > using oscilloscope the spi_write operation which is perfectly fine but i > guess the problems is in read operation. i am attaching my code. Any > help would be appreciated. I am using MPLAB X v3.0 with C8 compiler > v1.34. > > > #include <p18f8722.h> > #include <stdio.h> > #include <stdlib.h> > #include <spi.h> > #include <xc.h> > #include <delays.h> > #include "display_LCD.h" > > // CR95HF Commands Definition #define ECHO 0x55 > > #define SSI_1 PORTFbits.RF7 // RA2 #define SSI_0 PORTDbits.RD7 // RE1 > #define IRQ_IN PORTCbits.RC0 #define CS_rfid PORTEbits.RE0 > > void main() { > > MCU_Init(); // Initialize MCU and > peripherals > > EchoResponse(); > > } > > void MCU_Init(){ > > // Configure RFid Click pins > ADCON1 = 0b1111; // set all bits of port a as digital > TRISEbits.RE0= 0; > TRISCbits.RC0=0; > TRISDbits.RD7=0; > TRISFbits.RF7=0; > > OpenSPI2(SPI_FOSC_64, MODE_10, SMPEND); // Initialize SPI module > IRQ_IN=0; > CS_rfid = 0; > // Set in SPI mode SSI_1=0; > SSI_0=1; > > > } > > > char EchoResponse() { > CS = 0; > WriteSPI2(0x00); // Send cmd to CR95HF WriteSPI2(ECHO); > CS = 1; > while(1){ > CS = 0; > WriteSPI2(0x03); > tmp = ReadSPI2; > CS = 1; > display_LCD_l(tmp); > > if((res & 0x08) >> 3){ > CS = 0; WriteSPI2(0x02); > tmp = ReadSPI2; CS = 1; > if(tmp == ECHO){ > return 1; > } > return 0; > } > } > } > > > --------------------------------------- > Posted through http://www.EmbeddedRelated.com
I suspect that ReadSPI2 is a function, and that your compiler is glossing over the fact that tmp = ReadSPI2; puts the address of the function into tmp, rather than executing the function and putting its result into tmp. A good compiler would be emitting warnings right and left over this. I'm also pretty sure that you'll need to supply an address to ReadSPI2. -- www.wescottdesign.com