HCS515 Keeloq Decoder

HCS515   Datasheet

The HCS515 is one of the thee possible decoders available for decoding the Keeloq code hopping encoders.

I decided to make this page after struggling with their datasheet as being a great example of how not to document a product. Relevant data is scattered all throughout the sheet, and trying to follow the logic is next to impossible.

This is Microchips suggested method for hooking it up to a microcontroller. Personally I have it hooked up to a PIC18F6720, but I suppose any old microcontroller would work. The RF data is coming in from the RF receiver, which could be any rf receiver, depending on the frequency you transmit at. a LINX receiver is a nice standalone package, which does it all for you. Really all the lines you need to the microcontroller are the S_CLK and S_DAT lines, which are the main communications lines.

To make this chip work along with the Keeloq encoders, it has to be programmed with the manufactures code, then activate learn mode and learn up to 7 transmitters.

 

Program Manufactures Code : START:0xB4:LSB…..MSB of Manufactures code: ACK

Erase all:

4.2.7 ERASE ALL: START: 0xC3:Subcommand:Dummy Byte: ACK

e.g.

0xC3  0x00 0x00 -> Erase all transmitters.

0xC3  0x01 0x00 -> Erase all transmitters, except the first

 The erase all command (Figure 4-6) erases all the transmitters in the decoder. After the command and two dummy bytes are clocked in, the clock line must be asserted to activate the command. After a successful completion of an erase all command, the data line is asserted until the clock line goes low.

After an erase all command, the receiver goes into test mode. This means that it will accept all transmitters, even if they are not learned by the system. This test mode is deactivated by the learning of a valid transmitter.

 So this is the next thing you would want to do: 

ACTIVATE LEARN:

Code: START: 0xD2 : 0x00:x00: STOP;

This is how to do it in C, using CCS C compiler 3.184, though since I am not using any fancy stuff here, any version of a C compiler should work. for Erasing all, call the function with the 0xD2 parameter:

keeloq_cmd(0xD2);  // sends the erase all command. I probably should change the function to accept two inputs, as you may want to control the sub command bytes too.. but they are zero for erase all, so this works fine. yes.. I will change it later.

 

 

 

 

 

 

void keeloq_cmd(char cmd){
int i;
char temp[1];
output_low(S_DAT);
output_float(S_DAT);
output_high(S_CLK);
while(bit_test(PORTE,7) == 0) {
}
delay_us(TRESP);
output_low(S_CLK);
while(bit_test(PORTE,7) == 1) {
}
delay_us(TSTART); // ready for programming mode.

temp[0] = cmd;
// Command
for(i=0;i<(8);i++) {
output_bit(S_DAT,shift_right(temp,1,1)); // shifts out the data from the receiveBuffer
output_high(S_CLK);
delay_us(TCLKH);
output_low(S_CLK);
delay_us(TCLKL);
}
output_low(S_DAT);
// Sub Command / Dummy Bytes
for(i=0;i<(16);i++) {
output_high(S_CLK);
delay_us(TCLKH);
output_low(S_CLK);
delay_us(TCLKL);
}
output_float(S_DAT);
output_high(S_CLK);
while(bit_test(PORTE,7) == 0) { // while data is low
}
delay_us(20);

output_low(S_CLK);
output_float(S_DAT);
}//end function

 the timing is of course nowhere near in the datasheet, but these values work :o) 

#define TREQ 50 // min 0.005 max 500 ms
#define TRESP 100 // suggested value
#define TSTART 100 // suggested Value
#define TCLKH 100 // microsecond delay Clock High
#define TCLKL 100 // microsecond delay Clock Low
#define T_ACK 50

Now for the actual learning of a transmitter. This is the fun part, as the documentation is split over 4 sections or so, without references to each other.

First you have to send the activate learn command, as shown above. Then  when you press the button on the transmitter, and if the HCS515 receives this valid string, it will set the data line high for 60ms. At this point you can clock out a max of 8 bytes, which are all zero. apparently to tell the difference between a learn and a valid key.

Interesting to see how they keep some 4 sections between the waveforms and the parameters :o\

 

It takes the Data line high for 60ms

 

READ AND WRITE TO THE HCS515

 

For some reason you can also write and read to the user EEPROM. Now the documentation does not mention what addresses contain what, now what you are supposed to write to them.