|
|
View previous topic :: View next topic |
Author |
Message |
denis_11
Joined: 13 Jul 2010 Posts: 45
|
HTRC110 and PIC |
Posted: Sat Sep 04, 2010 7:14 am |
|
|
Hi I am working with a pic 16F876 and HTRC110. I would like to know how to initialize communication between these two components. I have already created a routine I2C with CLOCK DIN and DOUT but I wanted to know if I could also use the SPI. I would also like to know where I can find an example of a sequence of read / write so I understand how I set the functions of the pic. Thanks to all. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Sat Sep 04, 2010 6:17 pm |
|
|
ok thank you, I read the datasheet and I realized that I can use the libraries of i2c because I can join together data-in and data-out. I realized that should I send the byte 0xC0 for write tag and then send all other bytes and then stop, or use WRITE_TAG_N that I still have not figured out how to act ... to read the tags I send 0xE0 and wait to receive data ... right? This is what I did not understand. Then you think I can use the i2c simple? ie: START, WRITE_BYTE, WRITE_BYTE ,.... , STOP;
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
denis_11
Joined: 13 Jul 2010 Posts: 45
|
|
Posted: Sat Sep 04, 2010 7:14 pm |
|
|
I do not understand why you wrote me those links ... I know how works the I2C and SPI, but I wanted clarity because the I2C is the start, controlbyte, bytes, bytes ....., stop over 2 lines and the SPI have 3 lines and not controlbyte start and stop... I wrote a routine to handle the i2c on 3lines,sdain , sdaout and clk ... Now I haven't a HTRC110 and for this I asked some clarification from the datasheet that it is not clear if it uses the SPI or I2C ... I realized that is a I2C modified but wanted to know if I could use the same libraries or what of i2c change ... not sending the controlbyte so I suppose it was enough the start and then send the bytes and then stop ... right? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 04, 2010 10:02 pm |
|
|
Quote: |
8.7. Serial Interface
The communication between the HTRC110 and the microcontroller is done
via a three wire digital interface. The interface is operated by the
following signals:
SCLK Clock
DIN Data Input
DOUT Data Output
|
The signals list above are not for i2c.
The Philips documentation is not very complete.
This appnote describes a 2-wire SPI interface for another chip.
It provides a better description:
http://micromegacorp.com/downloads/documentation/AN007-SPI%20Interface.pdf
Quote: |
SPI Interface
The uM-FPU can be connected using either a 2-wire or 3-wire SPI
interface depending on the capabilities of the microcontroller. The 3-wire
SPI interface uses separate data input and data output pins on the
microcontroller, while the 2-wire SPI interface uses a single bidirectional
pin for both data input and data output.
|
|
|
|
Geps
Joined: 05 Jul 2010 Posts: 129
|
|
Posted: Mon Sep 06, 2010 7:46 am |
|
|
As PCM Programmer says the device uses SPI.
I've used it before but unfornuately NDA and IP clauses prevent me from releasing my code.
The HTRC110 requires an intialisation pulse BEFORE you transit any data and every time you send it a command. From memory you take the clock line high, followed by the data_in line and then low the clock.
It is explained in the datasheet.
You also don't want to write 0xE0 to read_tag. You need 3 1s without the trailing 0s. |
|
|
koray_duran
Joined: 04 Feb 2010 Posts: 37
|
|
Posted: Sun Nov 14, 2010 10:45 am |
|
|
Hi Denis!
if you writed a driver for htrc110, please share with us. |
|
|
MKY
Joined: 17 Feb 2007 Posts: 3
|
Here is Htrc110 fully working code |
Posted: Sat Apr 25, 2015 11:56 am |
|
|
Code: | #include <16F721.h>
#device adc=8
#FUSES INTRC_IO, PLLEN, BROWNOUT, NOWDT, PUT, PROTECT, NOBROWNOUT, WRT
// Htrc110 Kristal 4MHz
#use delay(clock=16000000)
#use rs232(baud=4800, ERRORS, parity=N, xmit=PIN_B7, rcv=PIN_B5, bits=8, STREAM=PORT1)
#OPT 8
#ZERO_RAM
#define BOYUT_DIZI_PORT1_GELEN 40
#define BOYUT_DIZI_PORT1_GIDEN 40
#define KISA 0
#define UZUN 1
#BYTE Timer0 = 0X01
#BYTE PORTA = 0X05
#BYTE PORTB = 0X06
#BYTE PORTC = 0X07
#BYTE OPTION = 0X81
#BYTE WPUA = 0X95
#BYTE IOCA = 0X96
#BYTE IOCB = 0X116
#BYTE TXREG = 0X19
#BYTE OSCCON = 0X90
#BIT PinRunLed = PORTC.1
#BIT PinKartLed = PORTC.2
#BIT SpiSclk = PORTB.6
#BIT SpiMosi = PORTC.7
#BIT SpiMiso = PORTB.4
#BYTE Timer1Ust = 0X0F
#BYTE Timer1Alt = 0X0E
int CevirAscii(int);
int ChkSumDizi(int);
int Ascii2Hex(int);
void ChkSumHesapla(char *p);
int ChkSumKontrol(char *p);
int IdKontrol(char *p);
void Port1Tamam(void);
void DiziDataYerlestir(void);
void Htrc110Init(void);
char Htrc110ReadTag(char);
void Htrc110ReadSet(void);
char SpiDataGonder(char);
void Gecikme(void);
void DiziYerlestir(int);
char DiziPort1Gelen[BOYUT_DIZI_PORT1_GELEN];
char DiziPort1Giden[BOYUT_DIZI_PORT1_GIDEN];
int DiziRfidGelen[12];
char DiziOkunanEtiket[5];
char DiziOkunanEtiketOnceki[5];
char DiziRfidOkunan[5];
int DurumBaslangic;
int SayacRunLed;
int E2CihazNo=5;
int SayacPort1Gelen;
int SayacPort1Giden;
char KarakterRs232;
int SayacRfidGelen;
int TamponTimer;
int Bayrak;
int Sayac;
int SayacKose;
int16 SayacEtiketSifirlama;
#BIT PinData = Bayrak.0
#BIT Sinyal = Bayrak.2
#int_TIMER1
void Timer1KesmeGeldi(void){
if(++SayacRunLed > 64){
PinRunLed=1;
SayacRunLed=0;
}
else{
PinRunLed=0;
}
if(PinKartLed!=0){
if(++SayacEtiketSifirlama>150){
SayacEtiketSifirlama=0;
PinKartLed=0;
DiziOkunanEtiket[0]=0;
DiziOkunanEtiket[1]=0;
DiziOkunanEtiket[2]=0;
DiziOkunanEtiket[3]=0;
DiziOkunanEtiket[4]=0;
DiziRfidOkunan[0]=0;
DiziRfidOkunan[1]=0;
DiziRfidOkunan[2]=0;
DiziRfidOkunan[3]=0;
DiziRfidOkunan[4]=0;
DiziOkunanEtiketOnceki[0] =0;
DiziOkunanEtiketOnceki[1] =0;
DiziOkunanEtiketOnceki[2] =0;
DiziOkunanEtiketOnceki[3] =0;
DiziOkunanEtiketOnceki[4] =0;
sprintf(DiziPort1Giden, "\X02%02uKY\X05", E2CihazNo); // Kart Yok
ChkSumHesapla(DiziPort1Giden);
SayacPort1Giden=0;
enable_interrupts(INT_TBE);
}
}
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //16 ms
restart_wdt();
}
#int_TBE
void SeriPort1DataGittiInterrupt(void){
KarakterRs232 = DiziPort1Giden[SayacPort1Giden];
if((++SayacPort1Giden > BOYUT_DIZI_PORT1_GIDEN) || (KarakterRs232 == 0) ){
disable_interrupts(INT_TBE);
}
else{
fputc(KarakterRs232, PORT1);
}
}
#int_RDA
void SeriPort1DataGeldiInterrupt(){ //
KarakterRs232 = fgetc(PORT1);
if (KarakterRs232==2 || SayacPort1Gelen >=BOYUT_DIZI_PORT1_GELEN ){
SayacPort1Gelen=0;
}
else if(KarakterRs232==3 && DiziPort1Gelen[0]==2){
if(ChkSumKontrol(DiziPort1Gelen)==1){
if(IdKontrol(DiziPort1Gelen)==1){
if( DiziPort1Gelen[3]=='R'){
if(DiziPort1Gelen[4]=='S'){ // Reset Cpu
reset_cpu();
}
else if(DiziPort1Gelen[4]=='O'){
for(Sayac=0 ;Sayac<255; Sayac++){
fprintf(PORT1, "*[%2X] = %2X ", Sayac, *Sayac);
}
}
else if(DiziPort1Gelen[4]=='A'){ // Raeder Aç
Htrc110ReadTag(0XE0);
}
else if(DiziPort1Gelen[4]=='K'){ // Reader Kapat
Htrc110ReadTag(0X00);
}
}
else if(DiziPort1Gelen[3]=='S'){
if(DiziPort1Gelen[4]=='R'){ // Reset Cpu
reset_cpu();
}
}
else if(DiziPort1Gelen[3]=='I'){
if(DiziPort1Gelen[4]=='O'){ // Id Numarası
}
}
else if(DiziPort1Gelen[3]=='C'){
if(DiziPort1Gelen[4]=='I'){ // Cihaz Initialize
Htrc110Init();
}
}
else if(DiziPort1Gelen[3]=='P'){
if(DiziPort1Gelen[4]=='O'){ // Parametre Oku
Htrc110ReadSet();
}
}
else if(DiziPort1Gelen[3]=='K'){ // Kart Oku
if(DiziPort1Gelen[4]=='O'){
if(PinKartLed==1){
sprintf(DiziPort1Giden, "\X02%02uKN%2X%2X%2X%2X%2X\X05", E2CihazNo, DiziRfidOkunan[0], DiziRfidOkunan[1], DiziRfidOkunan[2], DiziRfidOkunan[3], DiziRfidOkunan[4] );
}
else{
sprintf(DiziPort1Giden, "\X02%02uKY\X05", E2CihazNo); // Kart Yok
}
ChkSumHesapla(DiziPort1Giden);
SayacPort1Giden=0;
enable_interrupts(INT_TBE);
}
}
}
}
}
DiziPort1Gelen[SayacPort1Gelen++] = KarakterRs232;
}
#int_RAB
void PortABDegistiInterrupt(void){
TamponTimer=Timer0;
if(SpiMiso==0) PinData=0;
else PinData=1;
Timer0=0;
if( TamponTimer>8 && TamponTimer<21){
Sinyal=KISA;
}
else if(TamponTimer>20 && TamponTimer<40){
Sinyal=UZUN;
}
else{
DurumBaslangic=0;
SayacRfidGelen=0;
}
if( DurumBaslangic==0){
if(Sinyal==UZUN && PinData==1){
DurumBaslangic=10;
SayacRfidGelen=0;
}
}
else if(DurumBaslangic==10){
if(Sinyal==KISA ){
if(++SayacRfidGelen==16){ // Başlangıç Oluştu
DurumBaslangic=20;
SayacRfidGelen=0;
SayacKose=0;
}
}
else{
DurumBaslangic=0;
}
}
else if(DurumBaslangic==20){
if(Sinyal==UZUN){
if(PinData==0){
DiziYerlestir(1);
}
else{
DiziYerlestir(0);
}
SayacKose=0;
}
else if(Sinyal==KISA){
if(++SayacKose==2){
SayacKose=0;
if(PinData==0){
DiziYerlestir(1);
}
else{
DiziYerlestir(0);
}
}
else
return;
}
else{
SayacRfidGelen=0;
DurumBaslangic=20;
}
}
}
void DiziYerlestir(int GelenData){
int Bolum;
int Mod;
Bolum=SayacRfidGelen/5;
Mod = (Bolum*5+7) - SayacRfidGelen;
if(GelenData==1){
bit_clear(DiziRfidGelen[Bolum], Mod);
}
else{
bit_set(DiziRfidGelen[Bolum], Mod);
}
if(++SayacRfidGelen>54){
if((DiziRfidGelen[0]%2==0)&&(DiziRfidGelen[1]%2==0)&&(DiziRfidGelen[2]%2==0)&&(DiziRfidGelen[3]%2==0)&&(DiziRfidGelen[4]%2==0)&&(DiziRfidGelen[5]%2==0)&&(DiziRfidGelen[6]%2==0)&&(DiziRfidGelen[7]%2==0)&&(DiziRfidGelen[8]%2==0)&&(DiziRfidGelen[9]%2==0)){
DiziRfidGelen[0] &= 0XF0;
DiziRfidGelen[1] &= 0XF0;
DiziRfidGelen[2] &= 0XF0;
DiziRfidGelen[3] &= 0XF0;
DiziRfidGelen[4] &= 0XF0;
DiziRfidGelen[5] &= 0XF0;
DiziRfidGelen[6] &= 0XF0;
DiziRfidGelen[7] &= 0XF0;
DiziRfidGelen[8] &= 0XF0;
DiziRfidGelen[9] &= 0XF0;
DiziRfidGelen[10] &= 0XF0;
if(((((((((((DiziRfidGelen[0]^DiziRfidGelen[1])^DiziRfidGelen[2])^DiziRfidGelen[3])^DiziRfidGelen[4])^DiziRfidGelen[5])^DiziRfidGelen[6])^DiziRfidGelen[7])^DiziRfidGelen[8])^DiziRfidGelen[9])^DiziRfidGelen[10])==0){
DiziOkunanEtiket[0]= DiziRfidGelen[0] | swap(DiziRfidGelen[1]);
DiziOkunanEtiket[1]= DiziRfidGelen[2] | swap(DiziRfidGelen[3]);
DiziOkunanEtiket[2]= DiziRfidGelen[4] | swap(DiziRfidGelen[5]);
DiziOkunanEtiket[3]= DiziRfidGelen[6] | swap(DiziRfidGelen[7]);
DiziOkunanEtiket[4]= DiziRfidGelen[8] | swap(DiziRfidGelen[9]);
PinKartLed=1;
SayacEtiketSifirlama=0;
if( (DiziOkunanEtiket[0] != DiziOkunanEtiketOnceki[0]) ||
(DiziOkunanEtiket[1] != DiziOkunanEtiketOnceki[1]) ||
(DiziOkunanEtiket[2] != DiziOkunanEtiketOnceki[2]) ||
(DiziOkunanEtiket[3] != DiziOkunanEtiketOnceki[3]) ||
(DiziOkunanEtiket[4] != DiziOkunanEtiketOnceki[4])){
DiziOkunanEtiketOnceki[0] = DiziOkunanEtiket[0];
DiziOkunanEtiketOnceki[1] = DiziOkunanEtiket[1];
DiziOkunanEtiketOnceki[2] = DiziOkunanEtiket[2];
DiziOkunanEtiketOnceki[3] = DiziOkunanEtiket[3];
DiziOkunanEtiketOnceki[4] = DiziOkunanEtiket[4];
DiziRfidOkunan[0] = DiziOkunanEtiket[0];
DiziRfidOkunan[1] = DiziOkunanEtiket[1];
DiziRfidOkunan[2] = DiziOkunanEtiket[2];
DiziRfidOkunan[3] = DiziOkunanEtiket[3];
DiziRfidOkunan[4] = DiziOkunanEtiket[4];
sprintf(DiziPort1Giden, "\X02%02uKN%2X%2X%2X%2X%2X\X05", E2CihazNo, DiziRfidOkunan[0], DiziRfidOkunan[1], DiziRfidOkunan[2], DiziRfidOkunan[3], DiziRfidOkunan[4] );
ChkSumHesapla(DiziPort1Giden);
SayacPort1Giden=0;
enable_interrupts(INT_TBE);
}
}
}
DurumBaslangic=0;
for(Sayac=0; Sayac<11; Sayac++){
DiziRfidGelen[Sayac]=0;
}
}
}
int IDKontrol(char *p){
if ( *(p+1)==0X30 && *(p+2)==0X30 ){
return 1;
}
else if (E2CihazNo == (10*(*(p+1)-0X30) + (*(p+2)-0X30 ))){
return 1;
}
return -1;
}
void ChkSumHesapla(char *p){
int ChkSum=0;
p++;
do{
ChkSum=ChkSum ^ *p;
}while(*(++p) != 5);
*(++p)=CevirAscii(ChkSum>>4 & 0X0F);
*(++p)=CevirAscii(ChkSum&0X0F);
*(++p)=3;
*(++p)=13;
*(++p)=10;
*(++p)=0;
}
int ChksumKontrol(char *p){
int i=1, ChkSumHesap, ChkSum=0;
do{
ChkSum = ChkSum ^ *(p+(i++));
}while((*(p+i)!= 0X05) && i != 0 );
ChkSumHesap = swap(ChkSumDizi(*(p+(++i)))) | ChkSumDizi(*(p+(++i)));
if(ChkSum == ChkSumHesap){ return 1;}
return 0;
}
int ChkSumDizi(int a){
if(a<'A') return a-0X30;
return a-0X37;
}
int Ascii2Hex(int a){
if(a<'A') return a-0X30;
return a-0X37;
}
int CevirAscii(int a){
if(a<10) return a + 0X30;
return a + 0X37;
}
void Gecikme(void){
delay_us(20);
}
char SpiDataGonder(char GonderilenData){
int Sayac;
char AlinanData;
SpiSclk=1;
Gecikme();
SpiMosi=0;
Gecikme();
SpiMosi=1;
Gecikme();
for(Sayac=7; Sayac!=(0-1); Sayac--){
SpiSclk=0;
Gecikme();
if( bit_test(GonderilenData, Sayac) == 1){
SpiMosi=1;
}
else{
SpiMosi=0;
}
Gecikme();
SpiSclk=1;
Gecikme();
}
for(Sayac=7; Sayac!=(0-1); Sayac--){
SpiSclk=0;
Gecikme();
SpiSclk=1;
Gecikme();
if( SpiMiso==1 ){
bit_set(AlinanData, Sayac);
}
else{
bit_clear(AlinanData, Sayac);
}
SpiSclk=0;
}
SpiSclk=0;
SpiMosi=1;
return AlinanData;
}
void Htrc110Init(void){
char AlinanData;
SpiDataGonder(0X16);
delay_ms(5);
SpiDataGonder(0b01001100);
delay_ms(5);
SpiDataGonder(0X50);
delay_ms(5);
SpiDataGonder(0X6C);
delay_ms(5);
SpiDataGonder(0X70);
delay_ms(5);
SpiDataGonder(0X8F);
delay_ms(5);
AlinanData=SpiDataGonder(0X04);
AlinanData = AlinanData<<1;
AlinanData = AlinanData+0X3F;
AlinanData = AlinanData&0X3F;
delay_ms(5);
SpiDataGonder(0X80 | AlinanData);
delay_ms(5);
SpiDataGonder(0X6B);
delay_ms(5);
SpiDataGonder(0X68);
delay_ms(5);
SpiDataGonder(0X60);
delay_ms(5);
}
char Htrc110ReadTag(char GonderilenData){
SpiSclk=1;
Gecikme();
SpiMosi=0;
Gecikme();
SpiMosi=1;
Gecikme();
SpiSclk=0;
Gecikme();
SpiMosi=1;
for(Sayac=0; Sayac<3; Sayac++){
Gecikme();
SpiSclk=1;
Gecikme();
SpiSclk=0;
Gecikme();
}
SpiSclk=0;
delay_ms(1);
enable_interrupts(INT_RAB);
return 0; // Bu andan itibare SpiMiso pininde sürekli sadece tag data var
}
void Htrc110ReadSet(void){
char AlinanData;
AlinanData=SpiDataGonder(0X07);
fprintf(PORT1, "PAGE 3 =%2X\X0D\X0A", AlinanData);
AlinanData=SpiDataGonder(0X06);
fprintf(PORT1, "PAGE 2 =%2X \X0D\X0A", AlinanData);
AlinanData=SpiDataGonder(0X05);
fprintf(PORT1, "PAGE 1 =%2X \X0D\X0A", AlinanData);
AlinanData=SpiDataGonder(0X04);
fprintf(PORT1, "PAGE 0 =%2X \X0D\X0A", AlinanData);
AlinanData=SpiDataGonder(0X03);
fprintf(PORT1, "%2X \X0D\X0A", AlinanData);
AlinanData=SpiDataGonder(0X02);
fprintf(PORT1, "Sample Time =%2X \X0D\X0A", AlinanData);
}
void main() {
SET_TRIS_A(0b01111111);
SET_TRIS_B(0b00110000);
SET_TRIS_C(0b00000000);
IOCB =0b00010000;
PinKartLed=1;
PinRunLed=1;
delay_ms(500);
PinKartLed=0;
PinRunLed=0;
sprintf(DiziPort1Giden, "\X02%02uStartPort1\X05", E2CihazNo);
ChkSumHesapla(DiziPort1Giden);
Htrc110Init();
Htrc110ReadTag(0XE0);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_64);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //16 ms
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TBE);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(TRUE){
;
}
} |
|
|
|
MKY
Joined: 17 Feb 2007 Posts: 3
|
|
Posted: Sat Apr 25, 2015 12:05 pm |
|
|
I read some 125 kHz tag distance 15 - 20 cm, coil 600- 700 uH
( Htrc ile ilgiili çok kod aradım ama işe yarar pek bir şey bulamadım.
Arayıpda bulamayanlar buradan faydalanabilir)
Translation:
( I searched for a lot of code for HTRC but couldn't find anything that
works. Those who searched but could not find it can benefit from here) |
|
|
|
|
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
|