2023-04-13 08:39 PM
I want to read the sensor signal with NDEF_WriteText function,How do you read a temperature signal instead of a temperature text?
NDEF_WriteText funtion is printf funtion,so what should I do to read signal?
Solved! Go to Solution.
2023-05-23 12:26 AM
Hi,@Rene Lenerve
I found that the problem is caused by incorrect SPI initialization settings, which causes the data to be garbled.
2023-04-14 12:15 AM
Hello,
which demo are you looking at?
BR, Ulysses
2023-04-17 04:56 AM - edited 2023-11-20 08:15 AM
Hi,@Ulysses HERNIOSUS_O
I am currently using ST25 to collect sensor information with NDEF, and I have written the code of temperature collection. For NDEF, how can I write the signal acquired by MCU into the label and read the real-time signal through NFC? What functions do we need?
2023-04-17 07:36 AM
Hi,
of course you could create a text message "It has 27degC. Have a nice day!" out of the temperature of the sensor.
Or you look for a good NDEF record or mime or external type into which you want to code your data. This is up to you.
For some ideas you can look at https://developer.android.com/reference/android/nfc/NdefRecord
Best Regards, Ulysses
2023-04-17 07:44 PM
Hi,@Ulysses HERNIOSUS_O
OK, first of all, I would like to take your opinion.But this link doesn't seem to open.
2023-04-18 12:52 AM
Hi,
the link is working - but I think in China google resources including android.com may be blocked.
Please look for some other resources to define how you want to package the temperature data.
BR, Ulysses
2023-04-18 07:22 PM
Hi,
I can understand what you mean, and I gave my relevant code on how to write temperature data to NDEF instead of temperature characters.
void MX_NFC7_NDEF_URI_Init(void)
{
/******************************************************************************/
/* Configuration of X-NUCLEO-NFC02A1 */
/******************************************************************************/
/* Init of the Leds on X-NUCLEO-NFC07A1 board */
NFC07A1_LED_Init(GREEN_LED );
NFC07A1_LED_Init(BLUE_LED );
NFC07A1_LED_Init(YELLOW_LED );
NFC07A1_LED_On( GREEN_LED );
HAL_Delay( 300 );
NFC07A1_LED_On( BLUE_LED );
HAL_Delay( 300 );
NFC07A1_LED_On( YELLOW_LED );
HAL_Delay( 300 );
MAX6675_Init(); //K型热电�?��?始化
/* 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 = 0x05;
/* Init of the Type Tag 5 component (M24LR) */
while( NfcType5_TT5Init( ) != NFCTAG_OK );
}
/* Init done */
NFC07A1_LED_Off( GREEN_LED );
HAL_Delay( 300 );
NFC07A1_LED_Off( BLUE_LED );
HAL_Delay( 300 );
NFC07A1_LED_Off( YELLOW_LED );
HAL_Delay( 300 );
/* write text message to EEPROM */
K_Temperature = MAX6675_ReadTemperature(); //读�?�热电�?�温度值
uint8_t data[] = "K_Temperature";
// 创建NDEF消�?�
NDEF_WriteNDEF(strlen((char *)data), data);
//读�?�NDEF消�?�
NDEF_ReadNDEF(data);
/* Set the LED3 on to indicate Programing done */
NFC07A1_LED_On( YELLOW_LED );
}
2023-05-10 01:34 AM - edited 2023-11-20 08:15 AM
Hi @帅 罗,
Please use the code snippet button to insert your code :This button is available below the "Write an answer" frame. This will facilitate readers' understanding and discussion.
Now about your question, you get the information from the MAX6675 that you store in the variable K_Temperature (this variable is not defined in the sample code you provided, so let's assume it is defined as an int32).
You want to write it to the EEPROM of the ST25DV as an NDEF Text message using the NfcTag_WriteNDEF function. To do that you need first to convert it from int to char before.
But your code
uint8_t data[] = "K_Temperature";
will not do the job.
One possible way to convert could be the following code for example:
char temperaturebuffer[30] = { 0xD1, 0x01, 0x1B, 0x54, 0x02, 0x65, 0x6E }; /* Header for NDEF Text */
/* Test Record Header */
/************************************/
/* 7 | 6 | 5 | 4 | 3 | 2 1 0 */
/*----------------------------------*/
/* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type, MB=1 and ME=1 1record only */
/*----------------------------------*/
/* TYPE LENGTH */ /* <---- Type length = 1 */
/*----------------------------------*/
/* PAYLOAD LENGTH 0 */ /* <---- Text message length */
/*----------------------------------*/
/* TYPE */ /* <---- Type = "T" */
/*----------------------------------*/
/* PAYLOAD */
/************************************/
K_Temperature = MAX6675_ReadTemperature(); //For example may return 10 for 10 degrees
sprintf(&temperaturebuffer[7], "Temperature = %d", K_Temperature);
NfcTag_WriteNDEF(sizeof(temperaturebuffer) + 1, (uint8_t *)temperaturebuffer);
With it you should be able to read the ST25DVKC tag with a reader retrieving the information of the temperature, or reading with the MCU through the I²C.
Hope this can help you.
Kind Regards.
2023-05-10 07:07 AM - edited 2023-11-20 08:15 AM
Hi,@Rene Lenerve
I used the code as suggested by you,but my ST25 tap app only read temperature=0,please continue to help me to check the problem.
void MX_SPI2_Init(void)
{
/* USER CODE BEGIN SPI2_Init 0 */
/* USER CODE END SPI2_Init 0 */
/* USER CODE BEGIN SPI2_Init 1 */
/* USER CODE END SPI2_Init 1 */
/* SPI2 parameter configuration*/
hspi2.Instance = SPI2;
hspi2.Init.Mode = SPI_MODE_MASTER;
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
hspi2.Init.DataSize = SPI_DATASIZE_16BIT;
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi2.Init.NSS = SPI_NSS_SOFT;
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi2.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE END 0 */
void HAL_MspInit(void)
{
/* USER CODE BEGIN MspInit 0 */
/* USER CODE END MspInit 0 */
__HAL_RCC_SYSCFG_CLK_ENABLE();
__HAL_RCC_PWR_CLK_ENABLE();
/* System interrupt init*/
/* USER CODE BEGIN MspInit 1 */
/* USER CODE END MspInit 1 */
}
/**
* @brief SPI MSP Initialization
* This function configures the hardware resources used in this example
* @PAram hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(spiHandle->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspInit 0 */
/* USER CODE END SPI2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI2_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**SPI2 GPIO Configuration
PB13 ------> SPI2_SCK
PB14 ------> SPI2_MISO
PB15 ------> SPI2_MOSI*/
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15|GPIO_PIN_14;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Pull=GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN SPI2_MspInit 1 */
/* USER CODE END SPI2_MspInit 1 */
}
}
/**
* @brief SPI MSP De-Initialization
* This function freeze the hardware resources used in this example
* @PAram hspi: SPI handle pointer
* @retval None
*/
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
{
if(spiHandle->Instance==SPI2)
{
/* USER CODE BEGIN SPI2_MspDeInit 0 */
/* USER CODE END SPI2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI2_CLK_DISABLE();
/**SPI2 GPIO Configuration
PB13 ------> SPI2_SCK
PB14 ------> SPI2_MISO
PB15 ------> SPI2_MOSI
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15);
/* USER CODE BEGIN SPI2_MspDeInit 1 */
/* USER CODE END SPI2_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
//MAX6675 片选引脚�?始化
void GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_WritePin(GPIOB, MAX6675_CS_Pin, GPIO_PIN_SET);
/*引脚�?置 */
GPIO_InitStruct.Pin = MAX6675_CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/**
* @brief max66675模�?��?始化
* @PAram None
* @retval None
*/
void MAX6675_Init(void)
{
GPIO_Init(); //片选引脚�?始化
MX_SPI2_Init(); //spi总线�?始化
}
/**
* @brief max6675模�?�读写一个字节的数�?�
* @PAram txData:�?�?��?的数�?�
* @retval 接收到的数�?�
*/
uint8_t MAX6675_ReadWriteByte(uint8_t txData)
{
unsigned char txdata,rxdata;
txdata = txData;
HAL_SPI_TransmitReceive(&hspi2,&txdata,&rxdata,1,1000);
return rxdata;
}
/**
* @brief max6675模�?�读�?�测得的原始数�?�
* @PAram None
* @retval 温度的原始数�?�
*/
uint16_t MAX6675_ReadRawValue(void)
{
uint16_t tmp=0;
MAX6675_CS(0);
tmp = MAX6675_ReadWriteByte(0XFF); //read MSB
tmp <<= 8;
tmp |= MAX6675_ReadWriteByte(0XFF); //read LSB
MAX6675_CS(1);
if (tmp & 4)
{
// thermocouple open
tmp = 4095; //未检测到热电�?�
}
else
{
tmp = tmp >> 3;
}
tmp=tmp&0x0FFF; //12bit
return tmp;
}
/**
* @brief max6675模�?�读�?�温度
* @PAram None
* @retval 温度值(�?��?:℃)
*/
float MAX6675_ReadTemperature(void)
{
return (MAX6675_ReadRawValue() * 1024.0 / 4096);
}
//MAX6675 片选控制
void MAX6675_CS(unsigned char choose)
{
if(choose == 1)
{
HAL_GPIO_WritePin(GPIOB, MAX6675_CS_Pin, GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOB, MAX6675_CS_Pin, GPIO_PIN_RESET);
}
}
void MX_NFC7_NDEF_URI_Init(void)
{
/******************************************************************************/
/* Configuration of X-NUCLEO-NFC02A1 */
/******************************************************************************/
/* Init of the Leds on X-NUCLEO-NFC07A1 board */
NFC07A1_LED_Init(GREEN_LED );
NFC07A1_LED_Init(BLUE_LED );
NFC07A1_LED_Init(YELLOW_LED );
NFC07A1_LED_On( GREEN_LED );
HAL_Delay( 300 );
NFC07A1_LED_On( BLUE_LED );
HAL_Delay( 300 );
NFC07A1_LED_On( YELLOW_LED );
HAL_Delay( 300 );
/* 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 = 0x05;
/* Init of the Type Tag 5 component (M24LR) */
while( NfcType5_TT5Init( ) != NFCTAG_OK );
}
/* Init done */
NFC07A1_LED_Off( GREEN_LED );
HAL_Delay( 300 );
NFC07A1_LED_Off( BLUE_LED );
HAL_Delay( 300 );
NFC07A1_LED_Off( YELLOW_LED );
MAX6675_Init(); //K型热电�?��?始化
/* write text message to EEPROM */
HAL_Delay(500);
K_Temperature= MAX6675_ReadTemperature(); //读�?�热电�?�温度值
sprintf(&temperaturebuffer[7], "Temperature = %d", K_Temperature);
NfcTag_WriteNDEF(sizeof(temperaturebuffer) + 1, (uint8_t *)temperaturebuffer);
/* Set the LED3 on to indicate Programing done */
NFC07A1_LED_On( YELLOW_LED );
}
2023-05-10
08:10 AM
- last edited on
2023-12-06
05:06 AM
by
Laurids_PETERSE
Hi @帅罗.1 (Customer),
Please edit your message and use the code snippet button to insert your code (your message is not really readable)
:
You handled to write an NDEF Text message into the ST25DV, your issue is now around the MAX6675 by reading raw value and converting it into temperature. One thing to check is if your variable K_Temperature is correctly declared. I can't see it's definition in the extract of your code or maybe missed as message is not correctly formatted.
One precision, this forum is about ST products, so if you have any question on how to use the MAX6675, please consider to post on MAXIM's forum your question.
Hope this help you
Kind Regards