2023-03-21 12:52 AM
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:
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);
}
Solved! Go to Solution.
2023-03-22 06:28 AM
Hi,
some comments
Rgds
BT
.
2023-03-21 11:02 AM
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
2023-03-22 04:28 AM
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;
}
2023-03-22 06:28 AM
Hi,
some comments
Rgds
BT
.