IC解密MM32SPIN05PT的串口接收字节
| //IC解密端口初始化 void UART1_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBENR_GPIOB, ENABLE); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_0); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_0); //UART1_TX GPIOB.6 GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;//TX GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); //UART1_RX GPIOB.7 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; //RX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); } //-------------------------------------------------- void UART1_9Bit_Init(u32 baudrate) { UART_InitTypeDef UART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_UART1, ENABLE); //UART1 NVIC NVIC_InitStructure.NVIC_IRQChannel = UART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //Baud rate UART_StructInit(&UART_InitStructure); UART_InitStructure.BaudRate = baudrate; //The word length is in 8-bit data format. UART_InitStructure.WordLength = UART_WordLength_8b; UART_InitStructure.StopBits = UART_StopBits_1; //No even check bit. UART_InitStructure.Parity = UART_Parity_No; //No hardware data flow control. UART_InitStructure.HWFlowControl = UART_HWFlowControl_None; UART_InitStructure.Mode = UART_Mode_Rx | UART_Mode_Tx; UART_Init(UART1, &UART_InitStructure); UART_ClearITPendingBit( UART1, UART_IT_RXIEN);//上电清除一次标志位 UART_ITConfig(UART1, UART_IT_RXIEN, ENABLE); UART_Enable9bit(UART1, ENABLE); UART_Set9bitLevel(UART1, DISABLE); UART_Set9bitAutomaticToggle(UART1, ENABLE); // UART_Set9bitPolarity(UART1,ENABLE); UART_Cmd(UART1, ENABLE); UART1_GPIO_Init(); } //---------------------------------------- extern u16 MODE[10];//状态存储 u8 USART_RX_BUF[USART_REC_LEN]={0x00}; //接收缓冲,最大USART_REC_LEN个字节.末字节为换行符 u8 USART_RX_STA=0; //接收状态标记 void UART1_IRQHandler(void) { u8 res; if(UART_GetITStatus(UART1, UART_IT_RXIEN)!= RESET) { //Receiving interrupts (data received must end at 0x0D 0x0a) //read receive data. res = UART_ReceiveData(UART1); USART_RX_BUF[USART_RX_STA]=res ; if(USART_RX_STA<(USART_REC_LEN-1)) { USART_RX_STA++; } else { USART_RX_STA=0; } UART_ClearITPendingBit(UART1, UART_IT_RXIEN); } |

芯片解密