/*
Connexions HTRC110 <--> Arduino
> SCLK: HTRC110_pin8 -- Arduino_D13
> DIN: HTRC110_pin9 -- Arduino_D11
> DOUT: HTRC110_pin10 -- Arduino_D12
*/
// Variables
byte Cde = B00000000;
byte Data = B10000001;
// Interface HTRC110 - Function transfer
// rappel: CLK-> 13, HTRC110_Din-> 11, HTRC110_Dout-> 12
byte Transfer(byte Cde)
{
int Tdemi = 20; //µs
int i;
boolean b;
byte Rep;
// initialisation
digitalWrite(13,HIGH); //CLK High
delayMicroseconds(Tdemi);
digitalWrite(11, LOW);
delayMicroseconds(Tdemi);
digitalWrite(11, HIGH);
delayMicroseconds(Tdemi);
//8 clock periods to send the commands
for (i=7;i>=0;i--)
{
// Falling edge
digitalWrite(13, LOW);
b = bitRead(Cde,i);
digitalWrite(11, b);
delayMicroseconds(Tdemi);
// Rising edge
digitalWrite(13, HIGH);
delayMicroseconds(Tdemi);
}
// 8 clocks period for data
for (i=7;i>=0;i--){
// Falling edge
digitalWrite(13, LOW);
delayMicroseconds(Tdemi);
digitalWrite(13, HIGH);
//Rising edge
b = digitalRead(12);
bitWrite(Rep,i,b);
delayMicroseconds(Tdemi);
}
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
return Rep;
}
//------------------------
// Specific function to send the READ_TAG command
// '111' sent and clock low
void READmode()
{
int Tdemi = 20; // en microseconde
int i;
int j;
boolean b;
// INIT
digitalWrite(13,HIGH); //CLK High
delayMicroseconds(Tdemi);
digitalWrite(11, LOW);
delayMicroseconds(Tdemi);
digitalWrite(11, HIGH);
delayMicroseconds(Tdemi);
// 3 clocks for the three '1'
for (i=2;i>=0;i--){
//falling
digitalWrite(13, LOW);
digitalWrite(11, 1);
delayMicroseconds(Tdemi);
// rising
digitalWrite(13, HIGH);
delayMicroseconds(Tdemi);
}
digitalWrite(13,LOW);
delay(200);
digitalWrite(13,HIGH);
}
//SETUP
void setup() {
// Serial
Serial.begin(9600);
Serial.print("Demarrage:\n");
//Link with HTRC110
// CLK-> 13, HTRC110_Din-> 11, HTRC110_Dout-> 12
pinMode(11,OUTPUT);
pinMode(12,INPUT);
pinMode(13,OUTPUT);
delay(10);
}
//MAIN
void loop() {
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
//CONFIG PAGES
//Page 3
Transfer(B01110000);
delay(2);
//Page 0
Transfer(B01000011);
delay(2);
//Page 2
Transfer(B01101100);
delay(2);
//Page 1
Transfer(B01010000);
delay(2);
////-----------------------------------------------
//CALCULATING SAMPLING TIME
byte t_ant;
t_ant = Transfer(B00001000);
//Calculation
t_ant <<= 1;
t_ant += B00111111;
t_ant &= B00111111;
Serial.println("t_ant sent=");
Serial.println(t_ant);
delay(2);
//Set sampling time
Transfer((B10000000 | t_ant));
delay(2);
//Get sampling time
byte resp_samp_time;
resp_samp_time = Transfer(B00000010);
Serial.println("t_ant read=");
Serial.println(resp_samp_time);
////-----------------------------------------------
//-------------------------------------------------
//GENERAL SETTLING SEQUENCE
Transfer(B01101011);
delay(4);
Transfer(B01101000);
delay(1);
Transfer(B01100000);
delay(2);
//-------------------------------------------------
READmode();
delay(1000);
}
Here is just my code.
Transfer : function to activate CLK, 16 clocks period, 8 to sent data, 8 to read Dout. Works ok, cause I read the registers.
Read_mode : special function for READ_TAG command. Send '111' and setup clok low. Looks like it works well too.
The command READ_TAG is well interpreted by the chip cause if I add a '1' or if I forget to set up CLK low, I don't have anything on DOUT.
At the moment, I have things on DOUT but erratic, whatever I do in the code.
I still can't see the commands on the 125kHz sin wave sent by the chip. No command are RF sent.
My setup is powered by USB and I just disconnect and reconnect when I update the registers.