cancel
Showing results for 
Search instead for 
Did you mean: 

CR95HF not coming in ready state.

RSing.9
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

can you share more details about your hardware setup:

  • do you use your own custom board or do you use existing board (such as X-NUCLEO-NFC03A1 connected to an MCU board)
  • how is connected the CH95HF to the MCU: PCB connection or wire jumpers? If wire jumpers are used, verify them
  • what is the setup of the SSI_0 and SSI_1 pins? Can you probe those 2 signals during startup and make sure SSI_0=1 and SSI_1=0
  • can you check that the CR95HF is properly powered

Regarding the startup sequence, before sending the ECHO sequence, can you send a poll command and check that bit 2 is set in the poll answer?

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

4 REPLIES 4
RSing.9
Associate II
RSing.9
Associate II

I am using nrf52832 with CR95HF

here are basic functions for CR95HF

void reset_cr95hr(unsigned int ch)
{
  nrf_gpio_pin_clear(SPI_CS[ch]);
  nrf_delay_ms(1);
  SPI_byte_send(0x01);
  nrf_gpio_pin_set(SPI_CS[ch]);
  nrf_delay_ms(100);
}
 
 
char EchoResponse(unsigned int ch) {
  int ii=5, tmp;
  nrf_gpio_pin_clear(SPI_CS[ch]);
  nrf_delay_ms(1);
  SPI_byte_send(0x00);  // Send cmd to CR95HF
  SPI_byte_send(ECHO);
  nrf_gpio_pin_set(SPI_CS[ch]);
 
  while(1){
 
    nrf_gpio_pin_clear(SPI_CS[ch]);
    nrf_delay_ms(1);
    SPI_byte_send(0x03);
    tmp = SPI_byte_receive();
    nrf_gpio_pin_set(SPI_CS[ch]);
 
    if((tmp & 0x08) >> 3){
      nrf_gpio_pin_clear(SPI_CS[ch]);
      nrf_delay_ms(1);
      SPI_byte_send(0x02);
      tmp = SPI_byte_receive();
      nrf_gpio_pin_set(SPI_CS[ch]);
      if(tmp == ECHO){
        return 1;
      }
      return 0;
    }
  }
}
 
void writeCmd(unsigned short cmd, unsigned short dataLen, unsigned int ch){
  unsigned short i = 0;
 
  nrf_gpio_pin_clear(SPI_CS[ch]);
  nrf_delay_ms(1);
  SPI_byte_send(0x00);  // Send cmd to CR95HF
  SPI_byte_send(cmd);
  SPI_byte_send(dataLen);
  while (dataLen == 0){
    nrf_gpio_pin_set(SPI_CS[ch]);
    break;
  }
  for(i=0; i<dataLen; i++){
    SPI_byte_send(sdata[i]);
  }
  nrf_gpio_pin_set(SPI_CS[ch]);
}
 
void readCmd(unsigned int ch){
  unsigned short i = 0, ii=2;
 
  while(ii){
    ii--;
    nrf_gpio_pin_clear(SPI_CS[ch]);
    nrf_delay_ms(1);
    SPI_byte_send(0x03);
    res = SPI_byte_receive();
    nrf_gpio_pin_set(SPI_CS[ch]);
 
    if((res & 0x08) >> 3){
      nrf_gpio_pin_clear(SPI_CS[ch]);
      nrf_delay_ms(1);
      SPI_byte_send(0x02);
      res = SPI_byte_receive();
      dataNum = SPI_byte_receive();
      for(i=0; i<dataNum; i++)
        rdata[i] = SPI_byte_receive();
      nrf_gpio_pin_set(SPI_CS[ch]);
      break;
    }
    nrf_gpio_pin_set(SPI_CS[ch]);
    nrf_delay_ms(1);
  }
}
 
void IndexMod_Gain(unsigned int ch) {
  sdata[0] = 0x09;
  sdata[1] = 0x04;
  sdata[2] = 0x68;
  sdata[3] = 0x01;
  sdata[4] = 0x01;
  sdata[5] = 0x50;
  writeCmd(WrReg, 6, ch);
  readCmd(ch);
}
 
void AutoFDet(unsigned int ch)
{
  sdata[0] = 0x09;
  sdata[1] = 0x04;
  sdata[2] = 0x0A;
  sdata[3] = 0x01;
  sdata[4] = 0x02;
  sdata[5] = 0xA1;
  writeCmd(WrReg, 6,ch);
  readCmd(ch);
}
 
void Select_ISO_IEC_14443_A_Protocol(unsigned int ch) {
  sdata[0] = 0x02;
  sdata[1] = 0x00;
  writeCmd(ProtocolSelect, 2, ch);
  readCmd(ch);
 
  // Clear read and write buffers
  for(j=0; j<18; j++ ){
    rdata[j] = 0;
    sdata[j] = 0;
  }
}
 
void Select_ISO_IEC_18092_Protocol(unsigned int ch) {
  sdata[0] = 0x04;
  sdata[1] = 0x51;
  writeCmd(ProtocolSelect, 2, ch);
  readCmd(ch);
 
  // Clear read and write buffers
  for(j=0; j<18; j++ ){
    rdata[j] = 0;
    sdata[j] = 0;
  }
}
 
 
void GetNFCTag(unsigned int ch) {
  sdata[0] = 0x00;
  sdata[1] = 0xFF;
  sdata[2] = 0xFF;
  sdata[3] = 0x00;
  sdata[4] = 0x00;
  writeCmd(SendRecv, 5, ch);
  readCmd(ch);
 
  if(res & 0x80){
    for(j=0; j<dataNum; j++){
      ByteToHex(rdata[j], txt_hex);
      strcat(ID, txt_hex);
    }
    NFC_Flag = 1;    
  }
  else {
    NFC_Flag = 0;    
    Select_ISO_IEC_14443_A_Protocol(ch);
  }
}
 
void ByteToHex(char input, char *output)
{
  unsigned int ii,jj;
  
 
  ii=(input>>4)&0x0f;
  if(ii<10)
  {
    ii+=0x30;
  }
  else
  {
    ii+=55;
  }
  jj=input&0x0f;
  if(jj<10)
  {
    jj+=0x30;
  }
  else
  {
    jj+=55;
  }
 
  txt_hex[0]=ii;
  txt_hex[1]=jj;
  txt_hex[2]=0;
}
 
 
void GetTagID(unsigned int ch) {
  sdata[0] = 0x26;
  sdata[1] = 0x07;
  writeCmd(SendRecv , 2, ch);
  readCmd(ch);
 
  sdata[0] = 0x93;
  sdata[1] = 0x20;
  sdata[2] = 0x08;
  writeCmd(SendRecv , 3, ch);
  readCmd(ch);
 
  if(res & 0x80) {
    for(j=1; j<dataNum-3; j++) {
      ByteToHex(rdata[j], txt_hex);
      strcat(ID, txt_hex);
    }
    TAG_Flag = 1;    
  }
  else {
    TAG_Flag = 0;    
    Select_ISO_IEC_14443_A_Protocol(ch);
  }
}
 
void Calibration(unsigned int ch)
{
  // Calibrate CR95HF device
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x00;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0xFC;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x7C;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x3C;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x5C;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x6C;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x74;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
 
  sdata[0] = 0x03;
  sdata[1] = 0xA1;
  sdata[2] = 0x00;
  sdata[3] = 0xF8;
  sdata[4] = 0x01;
  sdata[5] = 0x18;
  sdata[6] = 0x00;
  sdata[7] = 0x20;
  sdata[8] = 0x60;
  sdata[9] = 0x60;
  sdata[10] = 0x00;
  sdata[11] = 0x70;
  sdata[12] = 0x3F;
  sdata[13] = 0x01;
  writeCmd(Idle, 0x0E,ch);
  readCmd(ch);
}

RSing.9
Associate II

int main(void)

{

nrf_gpio_cfg_output(SPI_CS[0]);

 nrf_gpio_cfg_output(SPI_CS[1]);

 nrf_gpio_cfg_output(SPI_CS[2]);

 nrf_gpio_cfg_output(SPI_CS[3]);

 nrf_gpio_cfg_output(SPI_CS[4]);

 nrf_gpio_cfg_output(SPI_CS[5]);

 nrf_gpio_cfg_output(SPI_CS[6]);

 nrf_gpio_cfg_output(SPI_CS[7]);

 nrf_gpio_cfg_output(SPI_CS[8]);

 nrf_gpio_cfg_output(SPI_CS[9]);

 SPI_init();

 nrf_gpio_pin_set(SPI_CS[0]);

 nrf_gpio_pin_set(SPI_CS[1]);

 nrf_gpio_pin_set(SPI_CS[2]);

 nrf_gpio_pin_set(SPI_CS[3]);

 nrf_gpio_pin_set(SPI_CS[4]);

 nrf_gpio_pin_set(SPI_CS[5]);

 nrf_gpio_pin_set(SPI_CS[6]);

 nrf_gpio_pin_set(SPI_CS[7]);

 nrf_gpio_pin_set(SPI_CS[8]);

 nrf_gpio_pin_set(SPI_CS[9]);

 nrf_delay_ms(100);

 reset_cr95hr(0);

 nrf_delay_ms(3);

 while (!EchoResponse(0));

 nrf_delay_ms(3);

 //Calibration(0);

 //nrf_delay_ms(3);

 IndexMod_Gain(0);

 nrf_delay_ms(3);

 AutoFDet(0);

 nrf_delay_ms(3);

 Select_ISO_IEC_14443_A_Protocol(0);

 nrf_delay_ms(3);

 //Clear_Screen(0);

 //string_display("ERR1", 2, 0);

 while(1){

  if (!TAG_Flag)

   GetNFCTag(0);                        // Get NFC ID

  if (!NFC_Flag)

   GetTagID(0);                        // Get Tag ID

  if (ID[0] == 0){                       // If there is no tag present

   flag++;                          // Increment counter flag

  }

  else {                            // If tag is present

   flag = 0;                         // Reset counter flag

   {                  // Compare previous and current tag ID

    //UART1_Write_Text("Tag ID:");

    //UART1_Write_Text(ID);

    //UART1_Write_Text("\r\n");

    ble_send("OK\r\n", strlen("OK\r\n"));

    strcpy(ID_old, ID);                   // Set current ID as previous ID

    nrf_delay_ms(100);     

   }

  }

  if(flag > 2){                        // If counter flag has reached value > 5

   //UART1_Write_Text("Put the Tag over the Antenna\r\n");

   ble_send("NOT\r\n", strlen("NOT\r\n"));

   ID_old[0]= 0;                       // Terminate the old ID string

   flag = 0;                         // Reset counter flag

  }

  ID[0]= 0;                          // Terminate the ID string

  // Clear read and write buffers

  for(j=0; j<18; j++){

   rdata[j] = 0;

   sdata[j] = 0;

  }

 }

}

Brian TIDAL
ST Employee

Hi,

can you share more details about your hardware setup:

  • do you use your own custom board or do you use existing board (such as X-NUCLEO-NFC03A1 connected to an MCU board)
  • how is connected the CH95HF to the MCU: PCB connection or wire jumpers? If wire jumpers are used, verify them
  • what is the setup of the SSI_0 and SSI_1 pins? Can you probe those 2 signals during startup and make sure SSI_0=1 and SSI_1=0
  • can you check that the CR95HF is properly powered

Regarding the startup sequence, before sending the ECHO sequence, can you send a poll command and check that bit 2 is set in the poll answer?

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.