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

EM4150 reading problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
koray_duran



Joined: 04 Feb 2010
Posts: 37

View user's profile Send private message

EM4150 reading problem
PostPosted: Thu Dec 23, 2010 4:03 am     Reply with quote

Hello again,

I have a problem about reading my 4150 tag which I supplied from ccs c rfid development kit. I've some changed the code for my own hardware but the drivers and basic hardware not modified.
I can read 4102 tags, I can login to 4150 and I can write to 4150 (not tested) but I can't read 4150.
The problem I get is : PARITY ERROR

Please give me some idea. Here is my code :
Code:

#include <16F876A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=20M)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=RS)

#define  BUZZER      PIN_C4
#define  RS485_EN1   PIN_B4
#define  RS485_EN2   PIN_B5
#define  SENSE       INPUT(PIN_C3)

#include <em4095.c>
#include <em4102.c>
#include <em4150.c>
#include <stdlib.h>

int8 msg[32];
int8 code[5];
int8 rcv_data=0;
int8 err;

typedef enum {OFF, GREEN, RED, BLUE, YELLOW, WHITE} LEDcolor;

// LED Control
void led_control(LEDcolor color) {
   switch(color) {     
      case OFF:
      output_low(PIN_A1);
      output_low(PIN_A0);
      output_low(PIN_A2);
      break;
     
      case GREEN:
      output_low(PIN_A1);
      output_low(PIN_A0);
      output_high(PIN_A2);
      break;
     
      case RED:
      output_high(PIN_A1);
      output_low(PIN_A0);
      output_low(PIN_A2);
      break;
     
      case BLUE:
      output_low(PIN_A1);
      output_high(PIN_A0);
      output_low(PIN_A2);
      break;
     
      case YELLOW:
      output_high(PIN_A1);
      output_low(PIN_A0);
      output_high(PIN_A2);
      break;
     
      case WHITE:
      output_high(PIN_A1);
      output_high(PIN_A0);
      output_high(PIN_A2);
      break;
   }
}

void rs_init(int8 way) {
if(way==0) {
output_low(RS485_EN1);
output_low(RS485_EN2);
}
if(way==1) {
output_high(RS485_EN1);
output_high(RS485_EN2);
delay_ms(25);
}
}

void clear() {
   rs_init(0);
   led_control(GREEN);
   rcv_data=0;
}

#INT_RDA
void receiving_data() {
   rcv_data=getc(RS);
}

void main(void) {

   int32 tagNum=0x00;
   int8  customerCode=0x00;
   int8  tag_adr=0x00; // tag_adr is between 0-33
   
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   
   rf_init();
   //rf_powerUp();
   
   rs_init(0);
   led_control(GREEN);
   
   while(true) {
   
   restart_wdt();
     
      if(rcv_data==0x45) {
      led_control(OFF);
      reset_4150();
      CLEAR();
      }
     
      if(rcv_data==0x4C) {
      led_control(YELLOW);
      rs_init(1);
      err = login_4150(0x00);
      switch(err) {
      case ERR_OK: sprintf(msg,"\n\rOK"); break;
      case ERR_LIW: sprintf(msg,"\n\rLIW"); break;
      case ERR_NAK: sprintf(msg,"\n\rNAK"); break;
      case ERR_PARITY: sprintf(msg,"\n\rPARITY"); break;
      }
      puts(msg,RS);
      CLEAR();
      }
     
      if(rcv_data==0x54) {
      led_control(WHITE);
      rs_init(1);
      if((err = read_4150(msg,tag_adr)) == ERR_OK) {
      tagNum = make32(msg[3], msg[2], msg[1], msg[0]);
      sprintf(msg, "\n\rData: %lu", tagNum);
      }
      switch(err) {
      case ERR_LIW: sprintf(msg,"\n\rLIW"); break;
      case ERR_NAK: sprintf(msg,"\n\rNAK"); break;
      case ERR_PARITY: sprintf(msg,"\n\rPARITY"); break;
      }
      puts(msg,RS);
      CLEAR();
      }

      if(rcv_data==0x52) {
      led_control(BLUE);
      if(read_4102(code)) {
         rs_init(1);
         tagNum = make32(code[1],code[2],code[3],code[4]);
         sprintf(msg,"\r\nScanned ID: %u-%lu",customerCode,tagNum);
         puts(msg,RS);         
         sprintf(msg,"( [%u][%u]",code[0],code[1]);
         puts(msg,RS);
         sprintf(msg,"[%u][%u][%u] )",code[2],code[3],code[4]);
         puts(msg,RS);
         CLEAR();
      }
      }
     
      if(rcv_data==0x57) {
      led_control(RED);
      rs_init(1);
      tagNum = make32(0x01,0x02,0x03,0x04);
      tag_adr=0;
      err = write_4150(tagNum,tag_adr);
      switch(err) {
      case ERR_OK: sprintf(msg,"\n\rOK"); break;
      case ERR_LIW: sprintf(msg,"\n\rLIW"); break;
      case ERR_NAK: sprintf(msg,"\n\rNAK"); break;
      case ERR_PARITY: sprintf(msg,"\n\rPARITY"); break;
      }
      puts(msg,RS);
      PWprotect_4150(FALSE);
      CLEAR();
      }
     
   }
}


olivervd



Joined: 10 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Tue Oct 14, 2014 5:43 am     Reply with quote

hello,
me too.
I have same problem.
Can you help me?sorry
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Oct 14, 2014 6:10 am     Reply with quote

see #4 in this post
http://www.ccsinfo.com/forum/viewtopic.php?t=26245

this of course dos not compile as is.
AND
also - you have quite a few LIBS that you call -but no code for them shown.

AND the "logic" of your tests on
rcv_data seems quite faulty.
To see this ,
trace out what happens in main when a given recognized value for it IS received, but then no new chars follow ?

What will main() do about it ?

what does your schematic look like
OR how are you simulating / testing this ?
olivervd



Joined: 10 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Thu Oct 16, 2014 12:56 am     Reply with quote

Hello,
Thanks for you answer, this is my code.
I use PCW compiler(CCS).
My hardware is the recommended EM Marin for Em4150. If you need my schematic I can send for email.
When I run my circuit emerge the next message "ERROR PARITY".
I can read em4100 and em4102, also I can write em4150, but I can't read em4150.
Can you help me?
This is my email: olivercharmander@hotmail.com


Code:
 
#include <16F876.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=20000000)
#users232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=S)
#include <em4095.c>
#include <em4102.c>
#include <em4150.c>
#include <stdlib.h>

int32 msg;
int8 err;
int32 tagNum=0x00;
int8  tag_adr=5;// tag_adr is between 0-33

#INT_RDA
void receiving_data() {
   rcv_data=getc(RS);
   printf("valor de rcv_data principal= %d",rcv_data);
 
}

void main(void) {

enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   
   delay_ms(1000);
   
   rf_init();
   rf_powerUp();

while(true) {
 
 restart_wdt();

err = read_4150(*msg,tag_adr);

tagNum=msg;

switch(err) {
     
      case ERR_OK: //sprintf(msg, "\n\rData: %lu", tagNum);
      sprintf(msg, "\n\rData: %x", tagNum);
      break;
      case ERR_LIW: sprintf(msg,"\n\rLIW LECTURA");
     
      break;
      case ERR_NAK: sprintf(msg,"\n\rNAK LECTURA");
   
      break;
      case ERR_PARITY:
      sprintf(msg,"\n\rPARITY LECTURA");
     //printf("PARITY\n\r");
      break;
     
     
   
      }
     
      puts(msg,RS);
      clear();
  }
}
olivervd



Joined: 10 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Thu Oct 16, 2014 1:07 am     Reply with quote

For simulation I use serial transmission, by Arduino (I use Arduino example "Software Serial").
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 16, 2014 11:32 am     Reply with quote

First, your code doesn't compile, so that's not your real program.
For example, you have stream=S, but then you call fgetc(RS).
There are several errors like this.

But the main problem is that you are not calling read_em4150()
correctly. The first parameter is declared to be a pointer, so you
should be giving it the address of msg.

You are doing this. It's wrong:
Quote:
err = read_4150(*msg, tag_adr);


You should do it like this:
Code:
err = read_4150(&msg, tag_adr);
olivervd



Joined: 10 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Fri Oct 17, 2014 12:36 am     Reply with quote

PCM thank you for your answer,
I have tried your advise but I have a same problem. I run my circuit and emerge the same error "PARITY".

Code:

#include <16F876a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT,NOPUT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=RS)



#include <em4095.c>
#include <em4102.c>
#include <em4150.c>
#include <stdlib.h>


int32 msg;
int8 err;
int32 tagNum=0x00;
 int8  tag_adr=5;// tag_adr is between 0-33

void main(void) {

 rf_init();
   rf_powerUp();
   
 
  while(true) {
 
// restart_wdt();
 
 
     
     
     
      //LOGIN
   
      err = login_4150(0x00);
     // resultado=readProtect_4150(1, 2);
    //  printf("valor de Resultado = %d\n\r",resultado);
     
   //   printf("valor de ERR LOGIN = %d\n\r",err);
     
      switch(err) {
      case ERR_OK: printf("\n\rOK LOGIN"); break;
      case ERR_LIW:printf("\n\rLIW LOGIN"); break;
      case ERR_NAK:printf("\n\rNAK LOGIN"); break;
      case ERR_PARITY: printf("\n\rPARITY LOGIN"); break;
      }
      puts(msg,RS);
      delay_ms(500);
       
 
 //ESCRITURA
   tagNum = make32(0x01,0x02,0x03,0x04);
     tag_adr=5;
     err = write_4150(tagNum,tag_adr);
      switch(err) {
      case ERR_OK: printf("\n\rOK ESCRITURA");
      break;
      case ERR_LIW:printf("\n\rLIW ESCRITURA"); break;
      case ERR_NAK: printf("\n\rNAK ESCRITURA"); break;
      case ERR_PARITY: printf("\n\rPARITY ESCRITURA"); break;
      }
      puts(msg,RS);
      PWprotect_4150(FALSE);
    delay_ms(500);
     
     
err=setPassword_4150(oldPassword, newPassword);
printf("valor de ERR Password = %d\n\r",err);

     
   //LECTURA   
  err = read_4150(&msg,5);

tagNum=msg;
 
       
      switch(err) {
     
      case ERR_OK: printf("Data: %lu \n\r", tagNum);
      printf("Data: %x \n\r", tagNum);
      break;
      case ERR_LIW: printf("\n\rLIW LECTURA");
     
      break;
      case ERR_NAK: printf("\n\rNAK LECTURA");
   
      break;
      case ERR_PARITY:
      printf("\n\rPARITY LECTURA");
     //printf("PARITY\n\r");
      break;
     
     
   
      }
     
      puts(msg,RS);
     
  //RESET
   err= reset_4150() ; 
   
   switch(err) {
     
      case ERR_OK: printf("\n\rOK RESET");
      break;
      case ERR_LIW: printf("\n\rLIW RESET");
     
      break;
      case ERR_NAK: printf("\n\rNAK RESET");
   
      break;
}
 
}
   }
olivervd



Joined: 10 Oct 2014
Posts: 10

View user's profile Send private message

PostPosted: Fri Oct 17, 2014 12:50 am     Reply with quote

The error R change RS, it was error by copy-paste.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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