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(;{
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.
Please disregard this post. I found what I was doing wrong.
Glad, you get the bug out. I am also interested in interfacing the Parallax RFID to the Dragon board. Can you share your working code. Thanks.
No problem. I'm sorry if it looks kinda sloppy, I haven't put in comments yet. I'm using Tera Term to output the tag id.
#include <hidef.h> /* common defines and macros */
#include <mc9s12dg256.h> /* derivative information */
#include "TERMIOSCI.H"
#include <stdio.h>
#pragma LINK_INFO DERIVATIVE "mc9s12dg256b"
char code[11];
void init_SCI1(void);
char getcSCI1(void);
void delay(int);
void init_PLL(void);
#define RDRF 0x20;
void main(){
init_SCI1();
init_PLL();
TERMIO_Init();
DDRJ |= 0x02; // PJ1 outputs
PTJ &= ~0x02; // PJ1 = 0 to enable on-board LEDs for use with Port B
DDRB = 0xFF; // Port B outputs
SCI0BDL = 156;
for(;{}
}
/***************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 = 0xA0;
SCI1CR2 = 0x24; // enable receive and transmit
}
char getcSCI1(){
while(!(SCI1SR1 & 0x20)){}
SCI1SR1;
return (SCI1DRL);
}
#pragma CODE_SEG NON_BANKED
interrupt 21 void SCI_INT(){
int val;
int i = 0;
int bytesRead;
if((val = getcSCI1()) > 0){
if(val == 0x0A){
bytesRead = 0;
i = 0;
while(bytesRead < 10){
if(SCI1DRL > 0){
val = getcSCI1();
if((val == 0x0A) || (val == 0x0D)){
break;
}
code[bytesRead] = val;
bytesRead++;
i++;
}
if(bytesRead == 10){
code[10] = '\0';
}
}
}
}
if(i == 10){
printf("Tag code is: %s\n\r", code);
i = 0;
}
}
#pragma CODE_SEG DEFAULT
void delay(int del){
int i,j;
for(i=0; i<del; i++)
for(j=0; j<2000; j++);
}
I'm trying to use a Parallax RFID for a project and hope that you would be willing to send me your complete code.
Hello friend, I'm trying to read TAG 1K with EN 60 and RFID-RC522a but I failed. You have any ideas to help me?
Thanks,
Thanks for sharing your code. I'll try it.