Tilovon Crite

Parallax RFID interface

Discussion created by Tilovon Crite on Apr 11, 2011
Latest reply on Apr 11, 2016 by Charles Brown

Hi all,

 

This is my first post in the forums, so please forgive me in advance if it is not fully up to par. I'm trying to interface a parallax RFID reader to my MC9S12DG256 dragon board. The reader sends out 12 bytes of data with a start byte of 0x0A and a stop byte of 0x0D. I have the sout of the reader connected to pin PS2 of the dragon board. Here is the code I have written so far in Codewarrior:

 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg256.h>     /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"


char code[10];


void init_SCI1(void);
char getcSCI1(void);
void delay(int);
void init_PLL(void);
#define RDRF 1;

void main(){
  int val;
  int i;
  int bytesRead;
  init_SCI1();
 
  DDRJ |= 0x02;    // PJ1 outputs
  PTJ &= ~0x02;   // PJ1 = 0  to enable on-board LEDs for use with Port B
  DDRB = 0xFF;  // Port B outputs
 
  for(;:smileywink:{
    if((val = getcSCI1()) > 0){
      if(SCI1DRL == 0x0A){
        bytesRead = 0;
        while(bytesRead < 10){
          if(SCI1DRL > 0){
            val = getcSCI1();
            if((val == 0x0A) || (val == 0x0D)){
              break;
            }
            code[bytesRead] = val;
            bytesRead++;
          }
        }
      }
    }
    for(i = 10; i > 0; i--){
      PORTB = code[i];
      delay(1000);
    }
  }
}


/***************functions*****************/


void init_PLL( ){  // initializes phase-locked loop (hardware)for 24Mhz CPU clock
   asm(sei);        // for running board standalone w/out Codewarrior
   CLKSEL &= ~0x80;
   PLLCTL |= 0x40;
   SYNR = 0x05;
   REFDV = 0x01;
   while((CRGFLG & 0x08) == 0){ // wait here for lock
      CRGFLG |= 0x08;
   }
   CLKSEL |= 0x80;
   asm(cli);
}


void init_SCI1(){
  SCI1BDH = 0x02;  // Baud Div = 24MHz/(16x2400) = 625 =0x271
  SCI1BDL = 0x71;    // MSB of baud rate registers
  SCI1CR1 = 0x00;
  SCI1CR2 = 0x04;    // enable receive
}

char getcSCI1(){
  while(!(SCI1SR1 & 1)){}
  return (SCI1DRL);
}

void delay(int del){
  int i,j;
    for(i=0; i<del; i++)
       for(j=0; j<2000; j++);   
}

 

 

Any help would be greatly appreciated. Thanks.

Outcomes