取出STM32芯片内部全球独一无二的ID号码
本帖最后由 czvmkl 于 2021-7-11 15:21 编辑最近研究成了一下STM32芯片内部刊唯一ID的资料,终于读取了芯片内部的96位唯一ID号码, 直接上干货
/*读取STM32F1系列内部唯一ID号码96位,通过上位机串口软件显示*/
#include"stm32f10x.h"
#include"sys.h"
#include"usart.h"
void RCC_Configuration(void);//时钟配置函数声明
void GPIO_Configuration(void); //GPIO端口初始化函数声明
void USART_Configuration(void);//串口初始化函数声明
int main(void)
{
u8 Sys_ID,i;
RCC_Configuration();
GPIO_Configuration();
USART_Configuration();
for(i=0;i<12;i++) //按字节读取,读12次 刚好12*8等于96位
{ Sys_ID=*(u8*)(0x1FFFF7E8+i);
printf("%0.2X ",Sys_ID);
}
printf("\n");
}
void RCC_Configuration(void)
{ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);//使能PA端口时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//使能串口USART1时钟
}
void GPIO_Configuration(void) // USART1对应的引脚PA9 PA10初始化配置
{ GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //配置PA9为USART1_TX
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化GPIOA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //配置PA10为USART1_RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化GPIOA.10
}
void USART_Configuration(void)//USART1初始化配置
{ USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = 9600;//串口波特率 9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART1, &USART_InitStructure); //初始化串口1
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接收中断
USART_Cmd(USART1, ENABLE); //使能串口1
USART_ClearFlag(USART1,USART_FLAG_TC);//清空发送完成中断标志位
} 看着好厉害的样子,有空试试学习学习 有什么实际意义? 用这个ID可以加密程序
页:
[1]