cancel
Showing results for 
Search instead for 
Did you mean: 

CR95HF stuck

qqAnton
Senior

Hello,

I have my own board with stm32f0 and cr95hf

I use SPI to communicate with NFC module,

buy sometimes, like once out of a hundred, CR95HF stuck and the only way to solve the problem is to reset power.

I've tried SPI Reinit, sending reset cmd and etc. but still the same.

void CR95_Init(void) {
//SSI1 - RESET STATE and SSI0 - SET by default
	uint8_t echo = 0;
	IRQ_IN_HIGH();
	osDelay(1);
	IRQ_IN_LOW();
	osDelay(1);
	IRQ_IN_HIGH();
	osDelay(15);
	CHIP_SELECT();
	HAL_SPI_Transmit(&hspi1, (uint8_t *)&CtrlBt_Reset, 1, 100);
	CHIP_UNSELECT();
	osDelay(100);
	echo = NFC_Echo();
	while (echo != 1) {
		echo = NFC_Echo();
		if (echo != 1) {
//Also trying to send to Hibernate state and reinit, but useless 
			Hibernate();
		}
		HAL_GPIO_TogglePin(LED_R_GPIO_Port, LED_R_Pin);
		osDelay(100);
	}
	NFC_ProtocolSelect(Protocol_ISO_14443A,0x00);
	Get_Sound(1, 150);
	osDelay(1000);
}

Maybe I am doing something wrong or there is a solution to make it work without power reset

Thank you,

Anton

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

 X-CUBE-NFC3 is intended for ST25R95/CR95HF. This provides the proper support for the various NFC technologies, NDEF support, etc.. Of course some adaptations may be needed for integration with FreeRTOS (see @Slan​  post on FreeRTOS on this community)

For point 2), on my side I use SPI_POLARITY_LOW/SPI_PHASE_1EDGE an 1.5MHz (48MHz/32). What is the SYSCLK value on your board?

For point 6) if I understand well, sometimes the boot randomly fails due to CR95HF init sequence failing? See the init sequence below from X-CUBE-NFC3.

For point 7) on my side the initial state of IRQ_IN is low (see ioc file for the various pin setup)

Init sequence procedure

  1. st25r95_nIRQ_IN_Pulse
  2. ResetChip
  3. SendEcho
    1. if error and less than 5 attempts, ResetChip and goto 3
    2. if more than 5 attempts return failure
  4. return success

st25r95_nIRQ_IN_Pulse procedure

  • IRQ_IN -> High;
  • delay 1ms
  • IRQ_IN -> low;
  • delay 1ms
  • IRQ_IN -> high
  • delay 11ms

ResetChip procedure

  • SpiDeselect
  • Delay 1ms
  • SpiSelect
  • SpiSend 0x01
  • Delay 1ms
  • SpiDeselect  
  • Delay 3ms
  •   st25r95_nIRQ_IN_Pulse(

SendEcho procedure

  • Send Poll Command and check that bit "Data can be sent to the ST25R95" is set
    • spiSelect
    • send 0x03 0x03
    • read result
    • SpiDeselect
    • if result has "Data can be sent to the ST25R95", return ok else timeout
  • Send the echo command:
    • SpiSelect
    • send 0x00 0x55
    • SpiDeselect
    • Wait for IRQ_OUT
    • SpiSelect
    • read data
    • SpiDeslect
    • return success if data is 0x055, otherwise error

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

3 REPLIES 3
Brian TIDAL
ST Employee

Hi,

 ST provides an NFC communication stack and a driver for ST25R95/CR95HF (see X-CUBE-NFC3 package). Default ports for NUCLEO-L476RG, NUCLEOF401RE or NUCLEO-F103RB are provided but it can easily be ported on STM32F0 series. I would recommend to use X-CUBE-NFC3. With this driver, I've never met a deadlock situation, so I believe the issue is elsewhere.

Regarding your issue, can you share more details:

  • I can see in your code osDelay. I guess your application runs under FreeRTOS? Can the ST25R95/CR95HF communication be interrupted by another task and the CS be modified by another task? Do you have a single task communicating with the ST25R95/CR95HF?
  • what is the SPI configuration (CPHA/CPOL/frequency)
  • Do you use IRQ_OUT or SPI 0x03 poll command mechanism? See caution note in ST25R95 datasheet §5.9 and I personally recommend to use the IRQ_OUT
  • Do you use the Idle command?
  • Do you use the Card Emulation mode?
  • What is the typical sequence that causes your issue? i.e. during data transfer or during boot up?
  • What is the initial state of IRQ_IN?
  • can you check that you never send a SendReceive command before having received the proper answer from the previous SendReceive?

Can you trace the following signals with a logic analyzer and send me the trace:

  • SPI CLOCK/MOSI/MISO/CS
  • IRQ_IN
  • IRQ_OUT
  • SSI0/SSI

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.
qqAnton
Senior

I was thinking that X-CUBE-NFC3 lib is only for new NFC modules, but I will try to use it

1) Only the task communicating with cr95hf

2)

hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;

With CPOL = Low and CPHA = 1Edge it's working too

3) I don't use IRQ_OUT, but I will try

4) I don't use idle command

5) I don't use Card Emulation mode

6) Only during boot up

7) IRQ_IN initial state is HIGH

8) I guess I don't send SendReceive cmd, sorry don't have logic analyzer

I solve the problem, controlling VPS pin on CR95, and as I discovered CR95HF works even without VPS pulled to VCC,

I guess it gets power from SPI and UART.

So, now, with every board reset NFC module resets too (earlier it has stable voltage, even after board reset, NFC module didn't) and now it work's fine.

Thank you for the answer and good advices, I think I should work consider X-CUBE-NFC3 lib

Brian TIDAL
ST Employee

Hi,

 X-CUBE-NFC3 is intended for ST25R95/CR95HF. This provides the proper support for the various NFC technologies, NDEF support, etc.. Of course some adaptations may be needed for integration with FreeRTOS (see @Slan​  post on FreeRTOS on this community)

For point 2), on my side I use SPI_POLARITY_LOW/SPI_PHASE_1EDGE an 1.5MHz (48MHz/32). What is the SYSCLK value on your board?

For point 6) if I understand well, sometimes the boot randomly fails due to CR95HF init sequence failing? See the init sequence below from X-CUBE-NFC3.

For point 7) on my side the initial state of IRQ_IN is low (see ioc file for the various pin setup)

Init sequence procedure

  1. st25r95_nIRQ_IN_Pulse
  2. ResetChip
  3. SendEcho
    1. if error and less than 5 attempts, ResetChip and goto 3
    2. if more than 5 attempts return failure
  4. return success

st25r95_nIRQ_IN_Pulse procedure

  • IRQ_IN -> High;
  • delay 1ms
  • IRQ_IN -> low;
  • delay 1ms
  • IRQ_IN -> high
  • delay 11ms

ResetChip procedure

  • SpiDeselect
  • Delay 1ms
  • SpiSelect
  • SpiSend 0x01
  • Delay 1ms
  • SpiDeselect  
  • Delay 3ms
  •   st25r95_nIRQ_IN_Pulse(

SendEcho procedure

  • Send Poll Command and check that bit "Data can be sent to the ST25R95" is set
    • spiSelect
    • send 0x03 0x03
    • read result
    • SpiDeselect
    • if result has "Data can be sent to the ST25R95", return ok else timeout
  • Send the echo command:
    • SpiSelect
    • send 0x00 0x55
    • SpiDeselect
    • Wait for IRQ_OUT
    • SpiSelect
    • read data
    • SpiDeslect
    • return success if data is 0x055, otherwise error

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.