cancel
Showing results for 
Search instead for 
Did you mean: 

ST25DV64KC NDEF text reading via I2C error

WPARK.1
Associate III

Hello,

I am trying to build a NFC project that receives 3 different ADC data from the MCU side (stm32l031k5) to the mobile phone.

However, there is a critical problem that:

  1. NFC reading is too slow. There is a term like few seconds to read new text tag.
  2. The values for the ADCs are not renewed and the text tag stays same. (not always but most time, it happens)

I am sharing my NFC code here.

void MX_NFC7_NDEF_URI_Process(void) {

char s1[200]; 

sprintf(s1, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", vol1[0], vol2[0], vol3[0], vol1[1], vol2[1], vol3[1], vol1[2], vol2[2], vol3[2], vol1[3], vol2[3], vol3[3], vol1[4], vol2[4], vol3[4]);

/* Init ST25DVXXKC driver */

while (NFC07A1_NFCTAG_Init(NFC07A1_NFCTAG_INSTANCE) != NFCTAG_OK);

/* Reset Mailbox enable to allow write to EEPROM */

NFC07A1_NFCTAG_ResetMBEN_Dyn(NFC07A1_NFCTAG_INSTANCE);

NfcTag_SelectProtocol(NFCTAG_TYPE5);

/* Check if no NDEF detected, init mem in Tag Type 5 */

if (NfcType5_NDEFDetection() != NDEF_OK) {

CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;

CCFileStruct.Version = NFCT5_VERSION_V1_0;

CCFileStruct.MemorySize = ( ST25DVXXKC_MAX_SIZE / 8) & 0xFF;

CCFileStruct.TT5Tag = 0x01; //0x05 originally

/* Init of the Type Tag 5 component (M24LR) */

while (NfcType5_TT5Init() != NFCTAG_OK)

;

}

/* write text message to EEPROM */

while (NDEF_WriteText(s1) != NDEF_OK)

;

NDEF_Text_info_t Text;

sRecordInfo_t record;

uint8_t p_ndef_buffer[200];

/* read NDEF file */

NDEF_ReadNDEF(p_ndef_buffer);

/* Extract record info */

NDEF_IdentifyBuffer(&record, p_ndef_buffer);

/* Read Text in record */

NDEF_ReadText(&record, &Text);

}

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

Hi,

some comments

  • make sure to check the return code of HAL_ADC_Start and HAL_ADC_PollForConversion.
  • having a local int i inside the for loop and a top level int i in the main is a source of error... I believe the if (i==9){i =0;} is useless (here the "i" is the top level one which is not modified... and the local 'i" in the for loop is 10 not 9 when exiting the for loop)
  • make sure to check that you application will not exceed the write cycles endurance (see datasheet). Using the Fast Transfer Mode Mailbox could be a better solution for your application rather than NDEF message

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,

"The values for the ADCs are not renewed" ==> I guess this is due to compiler optimization. Make sure to declare vol1, vol2 and vol3 as volatile if it is updated inside an IRQ callback.

"NFC reading is too slow" ==> the writing to the EEPROM should be triggered only when there is new ADC values i.e. as long as the ADC values have not changed, you should not triggered MX_NFC7_NDEF_URI_Process. See §5.3 Interface arbitration in the tag datasheet.

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.

Hello,

Actually, the values for vol1, 2, and 3 are renewed in the while loop. Then, updated to NFC C file using the extern:

extern uint16_t vol1[10], vol2[10], vol3[10];

I believe, the ADC values would be updated periodically so the values should be changed all the time, but in real application, it is not.

This is main.c code for important lines:

uint16_t adcVal[3];

uint16_t vol1[10], vol2[10], vol3[10];

int i = 0;

while (1)

{

for (int i = 0; i < 10; i++){

Data_Collect(i);

}

if (i==9){

i =0;

}

/* USER CODE END WHILE */

MX_NFC7_Process();

/* USER CODE BEGIN 3 */

}

void Data_Collect(int i){

HAL_ADC_Start(&hadc);

HAL_ADC_PollForConversion(&hadc, 10);

adcVal[0] = HAL_ADC_GetValue(&hadc);

HAL_ADC_Start(&hadc);

HAL_ADC_PollForConversion(&hadc, 10);

adcVal[1] = HAL_ADC_GetValue(&hadc);

HAL_ADC_Start(&hadc);

HAL_ADC_PollForConversion(&hadc, 10);

adcVal[2] = HAL_ADC_GetValue(&hadc);

vol1[i] = 3300 * adcVal[0] / 4096;

vol2[i] = 3300 * adcVal[1] / 4096;

vol3[i] = 3300 * adcVal[2] / 4096;

}

Brian TIDAL
ST Employee

Hi,

some comments

  • make sure to check the return code of HAL_ADC_Start and HAL_ADC_PollForConversion.
  • having a local int i inside the for loop and a top level int i in the main is a source of error... I believe the if (i==9){i =0;} is useless (here the "i" is the top level one which is not modified... and the local 'i" in the for loop is 10 not 9 when exiting the for loop)
  • make sure to check that you application will not exceed the write cycles endurance (see datasheet). Using the Fast Transfer Mode Mailbox could be a better solution for your application rather than NDEF message

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.