基于STM32C8T6、ATK-AS608实现指纹的录入、识别与删除
ATK-AS608介绍
ATK-AS608光学指纹识别模块是广州星翼电子科技有限公司(ALIENTEK)推出的光学指纹识别模块。该模块内置 DSP 运算单元,集成了图像处理和指纹识别算法,能快速采集图像并识别指纹特征。
ATK-AS608的引脚描述如下表所示:
引脚名称 | 引脚说明 |
Vi | 模块电源正输入端 |
Tx | 串行数据输出,TTL 逻辑电平 |
Rx | 串行数据输入,TTL 逻辑电平 |
GND | 信号地,内部与电源地连接 |
WAK | 感应信号输出,默认高电平有效 |
Vt | 触摸感应电源输入端,3.3V供电 |
通过上位机软件实现指纹功能
未完待续
通过串口驱动实现指纹功能
通过串口通信驱动ATK-AS608光学指纹识别模块可实现录入、识别和删除指纹等功能。其中,录入与识别指纹分多步操作实现。删除指纹分为删除指定的指纹和删除所有指纹两个功能,均为单一操作。
指纹录入流程
指纹识别流程
生成特征:指纹特征可以存到第一个缓存区也可以存到第二个缓存区,下文的项目存入的是第二个缓存区。
搜索指纹:调用这个指令就会将已经存在Flash里面的指纹模板和缓存区的指纹特征一一比对,如果有搜索到,会返回这个指纹的ID。要注意的是,调用的时候需要指明比对的特征是缓存区1还是缓存区2,要选择第二步生成特征所存储的缓存区。
单一指纹操作
针对该模块的单一操作,只需按照下表所示的指令包、应答包格式进行串口的收发操作,便可驱动该模块完成相关操作。
ATK-AS608指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes | |||
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令 | 参数1 | … | 参数n | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 |
ATK-AS608应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | N bytes | 2bytes |
名称 | 包头 | 模块地址 | 包标识 | 包长度 | 确认码 | 返回参数 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 |
包长度是包长度(不含)至校验和(含)之间的总字节数;校验和是从包标识(含)至校验和(不含)之间的字节之和,超出2字节的进位忽略。
确认码表示指令执行完毕后的情况。0x00表示指令成功执行,其余数值代表了不同的错误类型。鉴于此,判断录入或识别指纹的多步操作是否全部成功,可通过判断“一初值为0的数累加每一步操作得到的确认码”是否依然为0来实现。
在所有的操作中,只有在录入图像时,手指才需要按在模块采集处。
当模块的Vt引脚接3.3V时,WAK引脚会在手指按在模块采集处时输出高电平,此功能可用来判断是否有手指按在模块采集处。
下面将阐述种个操作的具体过程:
录入图像
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0003 | 0x01 | 0x0005 |
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0003 |
确认码含义:
确认码 | 含义 |
0x00 | 录入成功 |
0x01 | 收包有错 |
0x02 | 传感器上无手指 |
0x03 | 录入不成功 |
串口要发送的数据:EF 01 FF FF FF FF 01 00 03 01 00 05
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
生成特征,存在缓冲区
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 缓冲区号 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0004 | 0x02 |
缓冲区号为0x01或0x02,若输入其他值,则以0x02处理
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 模块地址 | 包标识 | 包长度 | 确认码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0003 |
确认码含义:
确认码 | 含义 |
0x00 | 生成特征成功 |
0x01 | 收包有错 |
0x06 | 指纹图像太乱而生不成特征 |
0x07 | 指纹图像正常,但特征点太少而生不成特征 |
0x15 | 图像缓冲区内没有有效原始图而生不成图像 |
生成特征,存入缓存区01:
串口要发送的数据:EF 01 FF FF FF FF 01 00 04 02 01 00 08
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
生成特征,存入缓存区02:
串口要发送的数据:EF 01 FF FF FF FF 01 00 04 02 02 00 09
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
精确比对两枚指纹特征
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0003 | 0x03 | 0x0007 |
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 比对得分 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0005 |
确认码含义:
确认码 | 含义 |
0x00 | 指纹匹配成功 |
0x01 | 收包有错 |
0x08 | 指纹不匹配 |
串口要发送的数据:EF 01 FF FF FF FF 01 00 03 03 00 07
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 05 00 00 F0 00 FC
合并特征并生成模板
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0003 | 0x05 | 0x0009 |
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0003 |
确认码含义:
确认码 | 含义 |
0x00 | 特征合并成功 |
0x01 | 收包有错 |
0x0a | 合并失败(两枚指纹不属于同一根手指) |
串口要发送的数据:EF 01 FF FF FF FF 01 00 03 05 00 09
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
储存模板到缓冲区
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 1bytes | 2bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 缓冲区号 | 指纹ID | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0006 | 0x06 |
缓冲区号为0x01或0x02
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0003 |
确认码含义:
确认码 | 含义 |
0x00 | 储存成功 |
0x01 | 收包有错 |
0x0b | 指纹ID 超出指纹库范围 |
0x18 | 写FLASH出错 |
以储存模板到缓冲区01,并赋予指纹ID = 0x0001为例:
串口要发送的数据:EF 01 FF FF FF FF 01 00 06 06 01 00 01 00 0F
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
搜索指纹
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 1bytes | 2bytes | 2bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 缓冲区号 | 起始ID | 校验和 | |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0008 | 0x04 |
缓冲区号为0x01或0x02
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes | 2bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 匹配ID | 得分 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0007 |
确认码含义:
确认码 | 含义 |
0x00 | 搜索到指纹 |
0x01 | 收包有错 |
0x09 | 未搜索到指纹,此时匹配ID与得分为0 |
以将待识别的指纹录入到缓冲区02并搜索已录入的全部指纹(起始ID = 0,查找数量 = 300)为例:
串口要发送的数据:EF 01 FF FF FF FF 01 00 08 04 02 00 00 01 2C 00 3C
在指令成功执行后(匹配到ID = 0x0005,得分为0x0058的指纹),模块会回复的数据:EF 01 FF FF FF FF 07 00 07 00 00 05 00 58 00 6B
删除指定的指纹
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes | 2bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 起始ID | 删除个数 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0007 | 0x0c |
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0003 |
确认码含义:
确认码 | 含义 |
0x00 | 删除模板成功 |
0x01 | 收包有错 |
0x10 | 删除模板失败 |
以删除ID = 1的指纹(起始ID为1,删除个数为1)为例:
串口要发送的数据:EF 01 FF FF FF FF 01 00 07 0C 00 01 00 01 00 16
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
删除所有指纹
指令包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 指令码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x01 | 0x0003 | 0x0d | 0x11 |
应答包格式:
字节数 | 2bytes | 4bytes | 1bytes | 2bytes | 1bytes | 2bytes |
名称 | 包头 | 芯片地址 | 包标识 | 包长度 | 确认码 | 校验和 |
内容 | 0xEF01 | 0xFFFFFFFF | 0x07 | 0x0003 |
确认码含义:
确认码 | 含义 |
0x00 | 清空成功 |
0x01 | 收包有错 |
0x11 | 清空失败 |
串口要发送的数据:EF 01 FF FF FF FF 01 00 03 0D 00 11
在指令成功执行后,模块会回复的数据:EF 01 FF FF FF FF 07 00 03 00 00 0A
基于STM32C8T6、ATK-AS608实现指纹的录入、识别与删除
元件
接线
STM32 | AS608 | ST-LINK | USB-TTL |
3V3 | Vi(红线) | 3.3V | |
PB11 | Tx(黄线) | ||
PB10 | Rx(白线) | ||
GND | GND(黑线) | GND | GND |
PB1 | WAK(蓝线) | ||
3V3 | Vt(绿线) | ||
SWDIO | SWDIO | ||
SWCLK | SWCLK | ||
PA9 | RX |
代码
工程文件
代码说明
4个注释
多了检测到手指按下,成功条件判断
删除指定的1个指纹
main.c
#include "stm32f10x.h"
#include "AS608.h"
#include "Delay.h"
int main(void)
{
AS608_Init();
//delete_fingerprint(1);
//delete_all_fingerprints();
while(1)
{
//input_fingerprints(1);
//identify_fingerprint (status_ID);
Delay_s(3);
}
}
AS608.c
#include "stm32f10x.h"
#include "AS608.h"
#include "USART3.h"
#include "serial.h"
uint8_t usart3_tx_hex[17];//´®¿Ú3·¢Ë͵ÄÐÅÏ¢
uint8_t usart3_rx_hex[17];//´®¿Ú3½ÓÊÕµÄÐÅÏ¢
uint8_tcheck_code_flag = 0x00;//УÑéºÍ±ê־룬0±íʾУÑéÕýÈ·£¬1±íʾУÑé´íÎó
uint8_t status_ID[2];//״̬ºÍIDºÅ£¬status_ID[0]Ϊ0±íʾʶ±ðÖ¸ÎƳɹ¦£¬Îª1±íʾʶ±ðÖ¸ÎÆʧ°Ü£»status_ID[1]Ϊʶ±ðµ½µÄIDºÅ
void AS608_Init(void)
{
USART3_Init();
Serial_Init();
//ÓÃÓÚÅжÏÊÖÖ¸ÊÇ·ñÒÑ·ÅÖÃÔڲɼ¯´¦
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
//
void input_image(void)//¼ÈëͼÏñ
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x03;
usart3_tx_hex[9] = 0x01;
usart3_tx_hex[10] = 0x00;
usart3_tx_hex[11] = 0x05;
printf("ÕýÔÚ¼ÈëͼÏñ\r\n");
USART3_SendArray(usart3_tx_hex, 12);
//ÔÚ·¢ËÍÓë½ÓÊÕÖ®¼ä²»ÄÜÍ£ÁôÌ«³¤Ê±¼ä£¬±ØÐëÔÚÊý¾Ý·¢¹ýÀ´Ö®Ç°¾ÍÏȽøÈëUSART3_ReceiveArray()£¬È»ºó¿¨ËÀ£¬Ö±µ½ÊÕÍêËùÓд«¹ýÀ´µÄÊý¾Ý
USART3_ReceiveArray(usart3_rx_hex, 12);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("¼ÈëͼÏñ³É¹¦\r\n");
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
void generate_feature_and_store_in_buffer(uint8_t buffer_address)//Éú³ÉÌØÕ÷²¢´æÔÚÖ¸¶¨»º´æÇø
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x04;
usart3_tx_hex[9] = 0x02;
if (buffer_address == 1)
{usart3_tx_hex[10] = 0x01;
usart3_tx_hex[11] = 0x00;
usart3_tx_hex[12] = 0x08;
printf("ÕýÔÚÉú³ÉÌØÕ÷²¢´æÔÚ»º´æÇø1\r\n");
}
if (buffer_address == 2)
{usart3_tx_hex[10] = 0x02;
usart3_tx_hex[11] = 0x00;
usart3_tx_hex[12] = 0x09;
printf("ÕýÔÚÉú³ÉÌØÕ÷²¢´æÔÚ»º´æÇø2\r\n");
}
USART3_SendArray(usart3_tx_hex, 13);
USART3_ReceiveArray(usart3_rx_hex, 12);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
if (buffer_address == 1)
{
printf("Éú³ÉÌØÕ÷²¢´æÔÚ»º´æÇø1³É¹¦\r\n");
}
if (buffer_address == 2)
{
printf("Éú³ÉÌØÕ÷²¢´æÔÚ»º´æÇø2³É¹¦\r\n");
}
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
void accurately_compare_the_characteristics_of_two_fingerprints(void)//¾«È·±È¶ÔÁ½Ã¶Ö¸ÎÆÌØÕ÷
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x03;
usart3_tx_hex[9] = 0x03;
usart3_tx_hex[10] = 0x00;
usart3_tx_hex[11] = 0x07;
printf("ÕýÔÚ¾«È·±È¶ÔÁ½Ã¶Ö¸ÎÆÌØÕ÷\r\n");
USART3_SendArray(usart3_tx_hex, 12);
USART3_ReceiveArray(usart3_rx_hex, 14);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("%02X ", usart3_rx_hex[12]);
printf("%02X ", usart3_rx_hex[13]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("¾«È·±È¶ÔÁ½Ã¶Ö¸ÎÆÌØÕ÷³É¹¦\r\n");
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
void merge_features_and_generate_templates(void)//ºÏ²¢ÌØÕ÷²¢Éú³ÉÄ£°å
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x03;
usart3_tx_hex[9] = 0x05;
usart3_tx_hex[10] = 0x00;
usart3_tx_hex[11] = 0x09;
printf("ÕýÔںϲ¢ÌØÕ÷²¢Éú³ÉÄ£°å\r\n");
USART3_SendArray(usart3_tx_hex, 12);
USART3_ReceiveArray(usart3_rx_hex, 12);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("ºÏ²¢ÌØÕ÷²¢Éú³ÉÄ£°å³É¹¦\r\n");
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
void save_template_to_buffer01_and_give_it_ID(uint8_t ID)//´¢´æÄ£°åµ½»º³åÇø01£¬²¢¸³ÓèID¡£ID²»Òª³¬¹ý241
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x06;
usart3_tx_hex[9] = 0x06;
usart3_tx_hex[10] = 0x01;
usart3_tx_hex[11] = 0x00;
usart3_tx_hex[12] = ID;
usart3_tx_hex[13] = 0x00;
usart3_tx_hex[14] = 0x0E + ID;
printf("ÕýÔÚ´¢´æÄ£°åµ½»º³åÇø01£¬²¢¸³ÓèID:%d\r\n", ID);
USART3_SendArray(usart3_tx_hex, 15);
USART3_ReceiveArray(usart3_rx_hex, 12);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("´¢´æÄ£°åµ½»º³åÇø01£¬²¢¸³ÓèID:%d³É¹¦\r\n", ID);
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
uint8_t search_fingerprint (void)//ËÑË÷Ö¸ÎÆ,·µ»Øʶ±ðµ½µÄID
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x08;
usart3_tx_hex[9] = 0x04;
usart3_tx_hex[10] = 0x02;
usart3_tx_hex[11] = 0x00;
usart3_tx_hex[12] = 0x00;
usart3_tx_hex[13] = 0x01;
usart3_tx_hex[14] = 0x2C;
usart3_tx_hex[15] = 0x00;
usart3_tx_hex[16] = 0x3C;
printf("ÕýÔÚËÑË÷Ö¸ÎÆ\r\n");
USART3_SendArray(usart3_tx_hex, 17);
USART3_ReceiveArray(usart3_rx_hex, 16);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("%02X ", usart3_rx_hex[12]);
printf("%02X ", usart3_rx_hex[13]);
printf("%02X ", usart3_rx_hex[14]);
printf("%02X ", usart3_rx_hex[15]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("ËÑË÷Ö¸ÎƳɹ¦\r\n");
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
return usart3_rx_hex[11];//ʶ±ðµ½µÄID
}
void delete_fingerprint(uint8_t ID)//ɾ³ýÖ¸¶¨IDµÄÖ¸ÎÆ,ID²»Òª³¬¹ý234
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x07;
usart3_tx_hex[9] = 0x0C;
usart3_tx_hex[10] = 0x00;
usart3_tx_hex[11] = ID;
usart3_tx_hex[12] = 0x00;
usart3_tx_hex[13] = 0x01;//ÕâÀïÊÇɾ³ý£¨´ÓÖ¸¶¨µÄÖ¸ÎÆËãÆ𣩸öÊý£¬¿É¸ù¾ÝÐèÒª±äΪº¯ÊýµÄÊäÈë²ÎÊý
usart3_tx_hex[14] = 0x00;
usart3_tx_hex[15] = 0x15 + ID;
printf("ÕýÔÚɾ³ýID:%dµÄÖ¸ÎÆ\r\n", ID);
USART3_SendArray(usart3_tx_hex, 16);
USART3_ReceiveArray(usart3_rx_hex, 12);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("ɾ³ýID:%dµÄÖ¸ÎƳɹ¦\r\n", ID);
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
void delete_all_fingerprints(void)//ɾ³ýËùÓÐÖ¸ÎÆ
{
usart3_tx_hex[0] = 0xEF;
usart3_tx_hex[1] = 0x01;
usart3_tx_hex[2] = 0xFF;
usart3_tx_hex[3] = 0xFF;
usart3_tx_hex[4] = 0xFF;
usart3_tx_hex[5] = 0xFF;
usart3_tx_hex[6] = 0x01;
usart3_tx_hex[7] = 0x00;
usart3_tx_hex[8] = 0x03;
usart3_tx_hex[9] = 0x0D;
usart3_tx_hex[10] = 0x00;
usart3_tx_hex[11] = 0x11;
printf("ÕýÔÚɾ³ýËùÓÐÖ¸ÎÆ\r\n");
USART3_SendArray(usart3_tx_hex, 12);
USART3_ReceiveArray(usart3_rx_hex, 12);
printf("ÊÕµ½µÄÊý¾ÝΪ£º");
printf("%02X ", usart3_rx_hex[0]);
printf("%02X ", usart3_rx_hex[1]);
printf("%02X ", usart3_rx_hex[2]);
printf("%02X ", usart3_rx_hex[3]);
printf("%02X ", usart3_rx_hex[4]);
printf("%02X ", usart3_rx_hex[5]);
printf("%02X ", usart3_rx_hex[6]);
printf("%02X ", usart3_rx_hex[7]);
printf("%02X ", usart3_rx_hex[8]);
printf("%02X ", usart3_rx_hex[9]);
printf("%02X ", usart3_rx_hex[10]);
printf("%02X ", usart3_rx_hex[11]);
printf("\r\n");
if (usart3_rx_hex[9] == 0x00)
{
printf("ɾ³ýËùÓÐÖ¸ÎƳɹ¦\r\n");
}
else
{
check_code_flag = 0x01;
printf("´íÎóÐÅϢΪ£º");
printf("%02X \r\n", usart3_rx_hex[9]);
}
printf("\r\n");
}
/
void input_fingerprints(uint8_t ID)//¼ÈëÖ¸ÎÆ
{
printf("Çë·ÅÊÖÖ¸\r\n\r\n");
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 1)//Èç¹ûÊÖÖ¸ÒÑ·ÅÖÃÔڲɼ¯´¦
{
input_image();//¼ÈëͼÏñ
generate_feature_and_store_in_buffer(1);//Éú³ÉÌØÕ÷£¬´æÔÚ»º´æÇø1
input_image();//ÔٴμÈëͼÏñ
generate_feature_and_store_in_buffer(2);//Éú³ÉÌØÕ÷£¬´æÔÚ»º´æÇø2
accurately_compare_the_characteristics_of_two_fingerprints();//¾«È·±È¶ÔÁ½Ã¶Ö¸ÎÆÌØÕ÷
merge_features_and_generate_templates();//ºÏ²¢ÌØÕ÷²¢Éú³ÉÄ£°å
save_template_to_buffer01_and_give_it_ID(ID);//´¢´æÄ£°åµ½»º³åÇø01£¬²¢¸³ÓèID
if (check_code_flag == 0x00)
{
printf("¼ÈëÖ¸ÎƳɹ¦\r\n");
}
else
{
printf("¼ÈëÖ¸ÎÆʧ°Ü\r\n");
check_code_flag = 0x00;
}
printf("\r\n");
}
}
void identify_fingerprint (uint8_t* status_ID)//ʶ±ðÖ¸ÎÆ,ÒÔÊý×éÐÎʽ·µ»ØÊÇ·ñʶ±ð³É¹¦ÒÔ¼°Ê¶±ðµ½µÄID
{
printf("Çë·ÅÊÖÖ¸\r\n\r\n");
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 1)//Èç¹ûÊÖÖ¸ÒÑ·ÅÖÃÔڲɼ¯´¦
{
input_image();//¼ÈëͼÏñ
generate_feature_and_store_in_buffer(2);//Éú³ÉÌØÕ÷£¬´æÔÚ»º´æÇø2
status_ID[1] = search_fingerprint();//ËÑË÷Ö¸ÎÆ
status_ID[0] = check_code_flag;
if (check_code_flag == 0x00)
{
printf("ʶ±ðÖ¸ÎƳɹ¦\r\n");
}
else
{
printf("ʶ±ðÖ¸ÎÆʧ°Ü\r\n");
check_code_flag = 0x00;
}
printf("\r\n");
}
}
AS608.h
#ifndef __AS608_H
#define __AS608_H
#include "stm32f10x.h"
extern uint8_t status_ID[2];
void AS608_Init(void);
void input_image(void);
void generate_feature_and_store_in_buffer(uint8_t buffer_address);
void accurately_compare_the_characteristics_of_two_fingerprints(void);
void merge_features_and_generate_templates(void);
void save_template_to_buffer01_and_give_it_ID(uint8_t ID);
uint8_t search_fingerprint (void);
void delete_fingerprint(uint8_t ID);
void delete_all_fingerprints(void);
void input_fingerprints(uint8_t ID);
void identify_fingerprint (uint8_t* status_ID);
#endif
USART3.c
//用于stm32和as608之间的通信
#include "stm32f10x.h"
#include <stdio.h>
#include <stdarg.h>
void USART3_Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 57600;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_Init(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
}
void USART3_SendByte(uint8_t Byte)
{
USART_SendData(USART3, Byte);
while (USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
}
void USART3_SendArray(uint8_t *Array, uint16_t Length)
{
uint16_t i;
for (i = 0; i < Length; i ++)
{
USART3_SendByte(Array[i]);
}
}
/*
void USART3_SendString(char *String)
{
uint8_t i;
for (i = 0; String[i] != '\0'; i ++)
{
USART3_SendByte(String[i]);
}
}
uint32_t USART3_Pow(uint32_t X, uint32_t Y)
{
uint32_t Result = 1;
while (Y --)
{
Result *= X;
}
return Result;
}
void USART3_SendNumber(uint32_t Number, uint8_t Length)
{
uint8_t i;
for (i = 0; i < Length; i ++)
{
USART3_SendByte(Number / USART3_Pow(10, Length - i - 1) % 10 + '0');
}
}
void USART3_Printf(char *format, ...)
{
char String[100];
va_list arg;
va_start(arg, format);
vsprintf(String, format, arg);
va_end(arg);
USART3_SendString(String);
}
uint8_t USART3_GetRxFlag(void)
{
if (USART3_RxFlag == 1)
{
USART3_RxFlag = 0;
return 1;
}
return 0;
}
void USART3_IRQHandler(void)
{
static uint8_t RxState = 0;
static uint8_t pRxPacket = 0;
if (USART_GetITStatus(USART3, USART_IT_RXNE) == SET)
{
uint8_t RxData = USART_ReceiveData(USART3);
if (RxState == 0)
{
if (RxData == 0xFF)
{
RxState = 1;
pRxPacket = 0;
}
}
else if (RxState == 1)
{
USART3_RxPacket[pRxPacket] = RxData;
pRxPacket ++;
if (pRxPacket >= 4)
{
RxState = 2;
}
}
else if (RxState == 2)
{
if (RxData == 0xFE)
{
RxState = 0;
USART3_RxFlag = 1;
}
}
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
}
}
*/
uint8_t USART3_ReceiveByte(void)
{
uint8_t Byte;
while (USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);//´®¿Ú3ÊÕµ½Êý¾Ý»á½«ÆäÖÃ1(SET)
Byte = USART_ReceiveData(USART3);
return Byte;
}
uint8_t* USART3_ReceiveArray(uint8_t *Array, uint16_t Length)
{
uint16_t i;
for (i = 0; i < Length; i ++)
{
Array[i] = USART3_ReceiveByte();
}
return Array;
}
USART3.h
#ifndef __USART3_H
#define __USART3_H
#include <stdio.h>
void USART3_Init(void);
void USART3_SendByte(uint8_t Byte);
void USART3_SendArray(uint8_t *Array, uint16_t Length);
void USART3_SendString(char *String);
void USART3_SendNumber(uint32_t Number, uint8_t Length);
void USART3_Printf(char *format, ...);
uint8_t USART3_ReceiveByte(void);
uint8_t* USART3_ReceiveArray(uint8_t *Array, uint16_t Length);
uint8_t USART3_GetRxFlag(void);
#endif
serial.c
//串口1打印提示信息
#include "stm32f10x.h"
#include <stdio.h>
#include <stdarg.h>
void Serial_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_Init(USART1, &USART_InitStructure);
USART_Cmd(USART1, ENABLE);
}
void Serial_SendByte(uint8_t Byte)
{
USART_SendData(USART1, Byte);
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);//µ±ÆäÖÃ1(SET) ±êÖ¾×Å´®¿Ú1½ÓÊÕÍê³É
}
//Öض¨Ïòc¿âº¯Êýprintfµ½´®¿Ú
int fputc(int ch, FILE *f)
{
Serial_SendByte(ch);
return ch;
}
uint8_t Serial_ReceiveByte(void)
{
uint8_t Byte;
Byte = USART_ReceiveData(USART1);
while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET);//µ±ÆäÖÃ1(SET) ±êÖ¾×Å´®¿Ú1·¢ËÍÍê³É
return Byte;
}
//Öض¨Ïòc¿âº¯Êýscanfµ½´®¿Ú£¬ÖØдºó¿ÉʹÓÃscanf¡¢getcharµÈº¯Êý
int fgetc(FILE *f)
{
uint8_t ch;
ch = Serial_ReceiveByte();
return ch;
}
serial.h
//串口1打印提示信息
#ifndef __SERIAL_H
#define __SERIAL_H
#include <stdio.h>
void Serial_Init(void);
void Serial_SendByte(uint8_t Byte);
uint8_t Serial_ReceiveByte(void);
#endif
现象
指纹录入成功现象
指纹识别成功现象
指纹删除成功现象
删除指定指纹
删除全部指纹
原文地址:https://blog.csdn.net/qq_44955826/article/details/144386576
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!