Ejemplo n.º 1
0
/*
*@功能:蓝牙MAC地址查询
*
*				将MAC地址写入外部flash中
*/
uint8_t bluetooth_mac(void)
{
	uint8_t j=0,t=0,count=0;
	uint8_t try_num=1;
	uint8_t char_buf[100];
	uint8_t MAC[6];
	uint8_t MAC_NULL[6]={0,0,0,0,0,0};

	UART3Reset(3);

	for(t=0;t<try_num;t++)				//至多尝试3次
	{
			UART3nSendChar(3,"TTM:RST-SYSTEMRESET",20);		//蓝牙串口AT指令
			delay_ms(50);
		
			UART3nSendChar(3,"TTM:MAC-?",10);		//蓝牙串口AT指令
			delay_ms(50);		//延时等待蓝牙回复
		
			count=UART3GetCount(3);
			UART3nReadChar(3,char_buf,count);			//读缓冲区数据到char_buf
		
			//for debug
// 			UART1nSendChar(1,char_buf,count);		//发送读到的所有数据
// 			delay_ms(100);					
		
			for(j=0;j<count-1;j++)		//从for循环退出的话,j=buf_len-1
				if(char_buf[j]=='0'&&char_buf[j+1]=='x')
						break;								//从break退出的话,j<buf_len-1
				

			if(j<count-1-12)							//如果提前成功
			{
				//for debug
				//UART1nSendChar(1,char_buf+j,12);		//已字符形式发送MAC地址
				//delay_ms(100);
				
				j=j+2;
				CharToHex(char_buf+j,MAC,12);		
				
				SPI_FLASH_Write(MAC,BLUETOOTH_MAC,6);
							
				return 1;//不用再尝试了
				
			}

			
	}
	
	//失败
	if(t>=try_num)
	{
		
		SPI_FLASH_Write(MAC_NULL,BLUETOOTH_MAC,6);
		return 0;
	}

}
Ejemplo n.º 2
0
/*
*@功能:2字节用户编号+4字节RFID+6字节时间+1字节开锁结果,存入记录区
*
*				每条长度为13字节
*/
void save_rfid_result(void)  //操作钥匙
{
	uint32_t record_addr;
	uint32_t Lock_number_addr;
	uint32_t total_row;
	uint8_t  temp_Lock_number[4];
	
	 
	
	IWDG_Feed();
  record_addr= SPI_FLASH_ReadWord(RECORD_POINT);   //已存储的组数
	
	
	
	SPI_FLASH_Write(User_Num,record_addr,2);				 		//写查找到的授权的用户编号到记录中,如果没有找到则编号为零
	
	SPI_FLASH_Write(Lock_number,record_addr+2,4);		 		//写读到的RFID到记录中
	
	read_time();  																 			//读取实时时间,放到time_buff中
	SPI_FLASH_Write(time_buff,record_addr+6,6);			 		//写实时时间到time记录中

	SPI_FLASH_Write(&unlock_result,record_addr+12,1);		//写开锁结果到记录中

	//for debug	
	SPI_FLASH_Read(item,record_addr,13);
	UART1nSendChar(1,item,13);
	delay_ms(1000);		
	
	
	record_addr=record_addr+RECORD_LEN;   //每条授权RECORD_LEN=13字节
	//更改授权用户信息指针的位置
	SPI_FLASH_WriteWord(RECORD_POINT,record_addr);		


	//for debug
	point=SPI_FLASH_ReadWord(RECORD_POINT);		//RECORD_POINT=RECORD_START
	UART1SendwordHex(1, point);
	delay_ms(1000);	



	//要区分宏地址里存放的内容到底是表示地址还是数据
	total_row= SPI_FLASH_ReadWord(RECORD_ROW);   		
	total_row=total_row+1;		//授权信息条数加一
	SPI_FLASH_WriteWord(RECORD_ROW,total_row);					


	//for debug
	row=SPI_FLASH_ReadWord(RECORD_ROW);
	UART1SendwordHex(1, row);
	delay_ms(1000);


}
Ejemplo n.º 3
0
//SPIFLASH 质量测试函数
static void SPIFLASH_Test(void)
{
    uint32_t i;
    uint8_t test_buffer[SPIFLASH_TEST_SIZE];
    SPI_FLASH_Read(test_buffer, SPIFLASH_TEST_ADDR, sizeof(test_buffer));
    UART_printf("Read data form 0x%x:\r\n", SPIFLASH_TEST_ADDR);
    for(i = 0; i < SPIFLASH_TEST_SIZE; i++)
    {
        UART_printf("[%x]:0x%x ", i, test_buffer[i]);
    }
		//写入测试数据
		for(i = 0; i < SPIFLASH_TEST_SIZE; i++)
		{
        test_buffer[i] = i;
		}
		UART_printf("\r\n");
		//写入数据
		SPI_FLASH_Write(test_buffer, SPIFLASH_TEST_ADDR, sizeof(test_buffer));
		UART_printf("Write data completed\r\n");
		memset(test_buffer, 0, sizeof(test_buffer));
		SPI_FLASH_Read(test_buffer, SPIFLASH_TEST_ADDR, sizeof(test_buffer));
    UART_printf("Read data form 0x%x:\r\n", SPIFLASH_TEST_ADDR);
		//打印数据
    for(i = 0; i < SPIFLASH_TEST_SIZE; i++)
    {
        UART_printf("[%x]:0x%x ", i, test_buffer[i]);
    }
}