在60*60cm的地图上,放置最多10个NFC接收器,每个接收器绑定一个ID卡,当关联的卡贴合时,播放对应的语音 10个NFC接收器和ID卡绑定后,接收器在感应到关联ID卡后,输出指示信号,接收器指示引脚接到stm32mcu,mcu收到指示信号,播放和mcu相连的语音播放模块相应语音,语音播放模块内部语音文件需手动导入并按顺序命名
1、项目简介
2、实现逻辑
#单片机端的逻辑比较简单,检测到对应引脚的中断触发,播放对应的声音,复杂的部分模块给做了
#在声音播放模块中按顺序按规定命名规则放好声音,单片机通过串口选择声音
#nfc模块提前设置好响应哪个卡片,响应到卡片触发中断
3、应用场景
#幼儿园益智玩具
#商场衣物趣味展示
4、核心代码梳理
uint8_t tx_sound[17] = {0xAA, 0x08, 0x0D, 0x02, 0x2F, 0x30, 0x30, 0x30, 0x30, 0x33, 0x20, 0x20, 0x20, 0x4D, 0x50, 0x33, 0x13};
uint8_t send_flag = 0;
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
uint16_t id10_num;
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_Delay(100);
if(send_flag)
{
send_flag = 0;
HAL_UART_Transmit(&huart1, (uint8_t *)&tx_sound, 17, 0xFFFF);
HAL_Delay(100);
}
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
if(HAL_GPIO_ReadPin(ID10_GPIO_Port, ID10_Pin))
id10_num++;
else
id10_num = 0;
if(id10_num == 5)
{
uint16_t sum = 0;
tx_sound[8] = 1 + 0x30;
tx_sound[9] = 0 + 0x30;
for(uint8_t i=0; i<16; i++)
sum += tx_sound[i];
tx_sound[16] = sum&0xff;
send_flag = 1;
}
else if(id10_num > 5)
id10_num = 6;
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
uint8_t num;
if(GPIO_Pin == ID1_Pin)
num = 1;
else if(GPIO_Pin == ID2_Pin)
num = 2;
else if(GPIO_Pin == ID3_Pin)
num = 3;
else if(GPIO_Pin == ID4_Pin)
num = 4;
else if(GPIO_Pin == ID5_Pin)
num = 5;
else if(GPIO_Pin == ID6_Pin)
num = 6;
else if(GPIO_Pin == ID7_Pin)
num = 7;
else if(GPIO_Pin == ID8_Pin)
num = 8;
else if(GPIO_Pin == ID9_Pin)
num = 9;
else if(GPIO_Pin == ID10_Pin)
num = 10;
else if(GPIO_Pin == ID11_Pin)
num = 11;
uint16_t sum = 0;
tx_sound[8] = num / 10 + 0x30;
tx_sound[9] = num % 10 + 0x30;
for(uint8_t i=0; i<16; i++)
sum += tx_sound[i];
tx_sound[16] = sum&0xff;
send_flag = 1;
}
5、部分参考资料
#注意选择好nfc模块和声音播放设备
#原理图和pcb见资料包
6、注意事项
#注意接线