实例介绍
【实例截图】
【核心代码】
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * <h2><center>© Copyright (c) 2021 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f0xx_usart.h" #include "stdtypes.h" #include <stdlib.h> #include <string.h> #include <stdio.h> /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ /* USER CODE END PV */ UART_HandleTypeDef huart1; UART_HandleTypeDef huart4; UART_HandleTypeDef huart3; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); static void MX_USART4_UART_Init(void); static void MX_USART3_UART_Init(void); /* USER CODE BEGIN PFP */ //#define OID_DEBUG_INFO(str,...) printf("OIDParser: "str"\r\n",__VA_ARGS__) /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ uint8_t max_buffer[256] = {0x00}; uint8_t LED_Flag[5] = {0}; uint8_t OID_Test_Flag = 0; /* USER CODE BEGIN PFP */ uint8_t aaaa[] = {0xF9 ,0x74 ,0x00 ,0x01 ,0x00 , 0x00 ,0x00 ,0x36 ,0x00 ,0x07 , 0x00 ,0x05 ,0x00 ,0x64 ,0x01 , 0x7E ,0x4D ,0x5E ,0x2B ,0x01 , 0x00 ,0x3A ,0x02 ,0x02 ,0x00 , 0xC7 ,0x00 ,0x0E ,0x00 ,0xF4 , 0x01 ,0xFB ,0x04 ,0x00 ,0x0A , 0x00 ,0x9F ,0x00 ,0x0A ,0x00 , 0x14 ,0x00 ,0x64 ,0x00 ,0xE1 , 0x00 ,0x63 ,0x01 ,0x0E ,0x01 , 0x09 ,0x00 ,0x00 ,0x20 ,0x00 , 0x00 ,0xE2 ,0x18 ,0x1A ,0x27 , 0x9F ,0x00 ,0x01 ,0x00 ,0x3E , 0x06 ,0x25 ,0x00 ,0x33 ,0x00 , 0x41 ,0x00 ,0x4F ,0x00 ,0x5E , 0x00 ,0x64 ,0x00 ,0x14 ,0x00 , 0x01 ,0x00 ,0xEE ,0x27 ,0x4F , 0x1A ,0xE9 ,0x13 ,0xA4 ,0x0F , 0x00 ,0x40 ,0x3E ,0x29 ,0x94 , 0x1E ,0xE3 ,0x18 ,0x03 ,0x00 , 0x00 ,0x00 ,0x03 ,0x00 ,0x04 , 0x00 ,0x05 ,0x00 ,0x02 ,0x00 , 0x02 ,0x00 ,0x02 ,0x00 ,0x02 , 0x00 ,0x04 ,0x00 ,0x53 ,0x92 }; uint8_t step1[] = {0xF9, 0x08, 0x00, 0x02, 0x00, 0x08, 0x16, 0x01, 0x00, 0xE3, 0xCD}; uint8_t step2[] = {0xF9, 0x08, 0x00, 0x02, 0x00, 0x00, 0x16, 0x01, 0x00, 0xE1, 0xAD}; uint8_t step3[] = {0xF9, 0x08, 0x00, 0x02, 0x00, 0x15, 0x16, 0x01, 0x00, 0xE5, 0xA1}; uint8_t step4[] = {0xF9, 0x0A, 0x00, 0x01, 0x00, 0x40, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8E, 0xFB, 0x00}; uint8_t step5[] = {0xF9, 0x0A, 0x00, 0x01, 0x00, 0x3F, 0x00, 0x01, 0x00, 0x01, 0x00, 0x84, 0xA4}; uint8_t step6[] = {0xF9, 0x0A, 0x00, 0x03, 0x00, 0xCA, 0x16, 0x01, 0x00, 0x21, 0x03, 0x01, 0xDA}; uint8_t step7[] = {0xF9, 0x0C, 0x00, 0x07, 0x00, 0x00, 0x00, 0x02, 0x00, 0xBB, 0xC6, 0xE9, 0x90, 0x4B, 0x1A}; uint8_t step8[] = {0xF9, 0x0A, 0x00, 0x01, 0x00, 0x36, 0x00, 0x01, 0x00, 0x00, 0x00, 0x85, 0xAD}; uint8_t step9[] = {0xF9, 0x0A, 0x00, 0x01, 0x00, 0x37, 0x00, 0x01, 0x00, 0x0C, 0x00, 0x81, 0x7C}; uint8_t step10[] = {0xfd, 0xff, 0xff}; uint8_t setLed1[] = {0xF9, 0x0A, 0x00, 0x03, 0x00, 0x08, 0x16, 0x01, 0x00, 0xB8, 0x0B, 0x7A, 0xAE}; uint8_t setLed2[] = {0xF9, 0x0A, 0x00, 0x03, 0x00, 0x09, 0x16, 0x01, 0x00, 0xB8, 0x0B, 0x7B, 0x7F}; uint8_t setLed3[] = {0xF9, 0x08, 0x00, 0x02, 0x00, 0x00, 0x16, 0x01, 0x00, 0xE1, 0xAD}; static OIDParser_code_t *mp_code = NULL; OIDParser_code_t aaal; OIDParser_analog_t aaaan[10] = {0}; //OIDParser_digital_t aaadi[10] = {0}; OIDParser_radius_t radiusTable[5]; OIDParser_analog_t analogTable[10]; OIDParser_analog_t analogTable_check[10]; //static uint8_t mb_codeReceived = 0; uint8_t setLed4[] = {0xF9, 0x0A, 0x00, 0x03, 0x00, 0x00, 0x16, 0x01, 0x00, 0xB0, 0x00, 0x3D, 0xE1}; /* USER CODE END PFP */ uint8_t ddd[] = {0xF9, 0x32, 0x00, 0x17, 0x00, 0x9D, 0x11, 0x01, 0x01, 0x7D, 0xFB, 0x04, 0x03, 0x00, 0x00, 0x00, 0x01, 0x01, 0xF1, 0x38, 0x1F, 0x00, 0x00, 0x00, 0x01, 0x01, 0xF0, 0x71, 0xFB, 0x04, 0x01, 0x00, 0x00, 0x01, 0x01, 0x20, 0xAB, 0xFB, 0x04, 0x0F, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x00, 0x00, 0x00, 0x43, 0x7C, 0xB8, 0x00, 0x04, 0x00, 0x52, 0x18}; /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ uint8_t aaa[200] = {0}; uint8_t aaa4[200] = {0}; uint8_t aab[256] = {0}; static int analogComp (const void * elem1, const void * elem2) { OIDParser_analog_t f = *((OIDParser_analog_t*)elem1); OIDParser_analog_t s = *((OIDParser_analog_t*)elem2); if (f.value > s.value) return 1; if (f.value < s.value) return -1; return 0; } static void sortAnalogValues(OIDParser_analog_t *p_data, uint8_t len) { qsort (p_data, len, sizeof(OIDParser_analog_t), analogComp); } static float convertToAngle (const uint16_t raw) { return raw / 182.0; } void OIDParser_resetCode (void) { uint8_t nbAnalog = 0U; uint8_t nbDigital = 0U; uint8_t idx; // mb_codeReceived = false; for (idx = 0; idx < mp_code->nbRadius; idx ) { nbAnalog = mp_code->p_radiusTable[idx].maxNbAnalog; nbDigital = mp_code->p_radiusTable[idx].maxNbAnalog; } memset(mp_code->p_analogTable, 0, nbAnalog * sizeof(OIDParser_analog_t)); memset(&mp_code->digital, 0, sizeof(OIDParser_digital_t)); } void OID_Init() { // fill the code structure with specific patern mp_code = &aaal; aaal.nbRadius = 5; aaal.luminance = 2; aaal.p_radiusTable = radiusTable; aaal.p_analogTable = analogTable; //aaal. aaadi // total 10 analog and 3 digital on 5 radius radiusTable[0].maxNbAnalog = 2; radiusTable[0].nbDigital = 1; radiusTable[1].maxNbAnalog = 4; radiusTable[1].nbDigital = 0; radiusTable[2].maxNbAnalog = 1; radiusTable[2].nbDigital = 0; radiusTable[3].maxNbAnalog = 0; radiusTable[3].nbDigital = 2; radiusTable[4].maxNbAnalog = 3; radiusTable[4].nbDigital = 0; memset(analogTable, 3, sizeof(analogTable)); aaal.digital.value = 4; OIDParser_resetCode(); memset(analogTable_check, 0, sizeof(analogTable_check)); } static void MX_USART1_UART_Init(void) { /* USER CODE BEGIN USART1_Init 0 */ /* USER CODE END USART1_Init 0 */ /* USER CODE BEGIN USART1_Init 1 */ /* USER CODE END USART1_Init 1 */ huart1.Instance = USART1; huart1.Init.BaudRate = 115200; huart1.Init.WordLength = UART_WORDLENGTH_8B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart1) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART1_Init 2 */ /* USER CODE END USART1_Init 2 */ } FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint32_t USART_FLAG) { FlagStatus bitstatus = RESET; /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(USARTx)); assert_param(IS_USART_FLAG(USART_FLAG)); if ((USARTx->ISR & USART_FLAG) != (uint16_t)RESET) { bitstatus = SET; } else { bitstatus = RESET; } return bitstatus; } void USART_ClearFlag(USART_TypeDef* USARTx, uint32_t USART_FLAG) { /* Check the parameters */ assert_param(IS_USART_ALL_PERIPH(USARTx)); assert_param(IS_USART_CLEAR_FLAG(USART_FLAG)); USARTx->ICR = USART_FLAG; } uint16_t str_cut_out(uint8_t* buff, uint8_t* array_slice, uint16_t start_addr, uint16_t stop_addr) { uint16_t cnt = 0; for(uint16_t cut_addr = start_addr; cut_addr <= stop_addr; cut_addr ) { buff[cnt] = array_slice[cut_addr]; cnt ; } return cnt; } uint8_t uart_send(USART_TypeDef * p_uart, uint8_t * data, uint16_t data_len) { USART_TypeDef* uart_port = p_uart; str_cut_out(max_buffer, data, 0, data_len); for(uint16_t tx_len = 0; tx_len < data_len; tx_len ) { /* 堵塞判断串口是否发送完成 */ while((uart_port->ISR & 0X40) == 0); //bit7: TXE /* 串口发送完成,将该字符发送 */ uart_port->TDR = (uint8_t) max_buffer[tx_len]; } return 0; } #if 1 //串口打印数据重定向 int fputc(int ch, FILE *stream) { /* 堵塞判断串口是否发送完成 */ while((USART1->ISR & 0X40) == 0); /* 串口发送完成,将该字符发送 */ USART1->TDR = (uint8_t) ch; return ch; } void oid_printf(uint8_t *p_data1) { uint32_t tmp; tmp = *(p_data1 ); tmp = (uint16_t)(*(p_data1 )) << 8; mp_code->orientation = tmp; printf("orientation: %f \r\n", convertToAngle(mp_code->orientation)); tmp = *(p_data1 ); tmp = (uint16_t)(*p_data1 ) << 8; mp_code->nbPoints = tmp; printf("nb points: %u\r\n", mp_code->nbPoints); tmp = *(p_data1 ); tmp = (uint16_t)(*(p_data1 )) << 8; mp_code->nbCenters = tmp; printf("nb centers: %u\r\n", mp_code->nbCenters); } #endif int8_t parseCode (uint8_t *p_data, const uint16_t len) { uint8_t radius; uint8_t idx; uint8_t m,n; uint32_t tmp; OIDParser_analog_t *p_analog; mp_code->nbCenters = 0; mp_code->nbPoints = 0; tmp = *p_data ; tmp = (uint16_t)(*p_data ) << 8; mp_code->luminance = tmp; printf("luminance: %d", mp_code->luminance); p_analog = mp_code->p_analogTable; //printf("mp_code->nbRadius: %u\r\n", mp_code->nbRadius); for (radius = 0; radius < mp_code->nbRadius; radius ) { m = *(p_data ); n = *(p_data ); printf("radius: %u | %u analog | %u digital\r\n", radius, m, n); if (m > 4)// (mp_code->p_radiusTable[radius].maxNbAnalog)) { printf("Too much analog data\r\n",NULL); return -1; } if (n > 1) { printf("Too much analog data_2\r\n",NULL); return -1; } // parse the analog values 解析模拟值 mp_code->p_radiusTable[radius].nbAnalog = m; for (idx = 0; idx < m; idx ) { if(idx > 4) { return -1; } tmp = *(p_data ); tmp = (uint16_t)(*p_data ) << 8; printf("analog %u.%u = %f, %04X, %d\r\n", radius, idx, convertToAngle(tmp), tmp, (uint16_t)((&p_analog[idx]) - mp_code->p_analogTable)); p_analog[idx].value = tmp; } if (mp_code->p_radiusTable[radius].nbAnalog > 1) { sortAnalogValues(p_analog, mp_code->p_radiusTable[radius].nbAnalog); } p_analog = mp_code->p_radiusTable[radius].maxNbAnalog; // printf("NNNNNNNNNN = %u", n); // parse the digital values //if(n != 0) //{ for (idx = 0u; idx < n; idx ) { tmp = *p_data ; tmp = (uint32_t)(*p_data ) << 8; tmp = (uint32_t)(*p_data ) << 16; tmp = (uint32_t)(*p_data ) << 24; printf("digital %u.%u = %08X \r\n", radius, idx, tmp); // VENUS only if (radius == 0) { mp_code->digital.value = tmp & 0x0003; // bits 1..0 } else if (radius == 1) { mp_code->digital.value = ((tmp & 0x003F)<< 2); // bits 7..2 } else if (radius == 5) { mp_code->digital.value = ((tmp & 0x000F) << 8); // bits 11..9 } } //} } oid_printf(p_data); return 0; } /* void OIDParser_receiveFrame (uint8_t *p_data, const uint16_t len) { printf("new frame (%u)", len); if (len > 4) { int8_t ret = parseCode(p_data, len); } } */ void delay(uint32_t aa) { uint32_t Temp = 10000; while(aa--) { while(Temp--); Temp = 10000; } } extern uint8_t rx_offset; extern uint8_t rx_offset4; uint8_t Oid_State1 = 0; static uint8_t test_cnd2 = 0; static uint8_t test_cnd = 0; void oid_discern4() { static uint8_t oid1_Cnd2 = 0; if(oid1_Cnd2 > 5) { LED_Flag[2 test_cnd2] = 1; test_cnd2 ; if(test_cnd2 == 2) { test_cnd2 = 0; } if(test_cnd2 == 1) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_RESET); } oid1_Cnd2 = 0; return; } if((test_cnd2 > test_cnd) && (test_cnd2 != 0)) { return; } switch(Oid_State1) { case 0: { rx_offset4 = 0; HAL_UART_Receive_IT(&huart4, aab, 250); uart_send(USART4, aaaa, sizeof(aaaa)); delay(50); HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); //HAL_UART_Receive_IT(&huart2, aaa, 4); //uart_read(USART2, aaa, 4); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 1; } } break; case 1: { rx_offset4 = 0; uart_send(USART4, step1, sizeof(step1)); delay(10); //uart_read(USART2, aaa, 4); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { //Temp = aaa[8] << 8 aaa[7]; if(aaa4[8] < 7) { uart_send(USART4, setLed1, sizeof(setLed1)); delay(29); uart_send(USART4, setLed2, sizeof(setLed2)); delay(29); uart_send(USART4, setLed3, sizeof(setLed3)); delay(29); uart_send(USART2, setLed4, sizeof(setLed4)); oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 1; } else { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 2; } } } break; case 2: { rx_offset4 = 0; uart_send(USART4, step2, sizeof(step2)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 3; } } break; case 3: { rx_offset4 = 0; uart_send(USART4, step3, sizeof(step3)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 4; } } break; case 4: { rx_offset4 = 0; uart_send(USART4, step4, sizeof(step4)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 5; } } break; case 5: { rx_offset4 = 0; uart_send(USART4, step5, sizeof(step5)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 6; } } break; case 6: { rx_offset4 = 0; uart_send(USART4, step6, sizeof(step6)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 7; } } break; case 7: { rx_offset4 = 0; uart_send(USART4, step7, sizeof(step7)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 8; } } break; case 8: { rx_offset4 = 0; uart_send(USART4, step8, sizeof(step8)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 9; } } break; case 9: { rx_offset4 = 0; uart_send(USART4, step9, sizeof(step9)); delay(10); oid1_Cnd2 ; if(aaa4[0] == 0xf9) { oid1_Cnd2 = 0; aaa4[0] = 0; Oid_State1 = 10; } } break; case 10: { rx_offset4 = 0; uart_send(USART4, step10, sizeof(step10)); delay(40); HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); delay(40); HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); oid1_Cnd2 ; if(aaa4[0] == 0xf9 && rx_offset4 > 0x10) { if(aaa4[1] == 0x32) { // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_SET); // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET); if(-1 != parseCode(&aaa4[5], 46)) //parseCode(&ddd[5], 46); //if(0 == strncmp(&aaa4[5], &ddd[5], 46)) { } LED_Flag[2 test_cnd2] = 2; test_cnd2 ; if(test_cnd2 == 2) { test_cnd2 = 0; } /* } else if(oid1_Cnd2 > 6) { LED_Flag[2 test_cnd2] = 1; test_cnd2 ; if(test_cnd2 == 2) { test_cnd2 = 0; } } */ } else { // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_SET); // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET); LED_Flag[2 test_cnd2] = 1; test_cnd2 ; if(test_cnd2 == 2) { test_cnd2 = 0; } } } } oid1_Cnd2 = 0; aaa[0] = 0; Oid_State1 = 3; break; } } /** * @brief The application entry point. * @retval int */ uint8_t Oid_State = 0; void oid_discern() { static uint8_t oid1_Cnd = 0; if(oid1_Cnd > 5) { LED_Flag[test_cnd] = 1; test_cnd ; if(test_cnd == 2) { test_cnd = 0; } oid1_Cnd = 0; return; } if((test_cnd == 0) && (test_cnd2 == 0)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); } else if((test_cnd == 1) && (test_cnd2 == 1)) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); } if((test_cnd2 < test_cnd) && (test_cnd != 0)) { return; } switch(Oid_State) { case 0: { rx_offset = 0; HAL_UART_Receive_IT(&huart3, aab, 250); uart_send(USART3, aaaa, sizeof(aaaa)); delay(50); HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); //HAL_UART_Receive_IT(&huart2, aaa, 4); //uart_read(USART2, aaa, 4); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 1; } } break; case 1: { rx_offset = 0; uart_send(USART3, step1, sizeof(step1)); delay(10); //uart_read(USART2, aaa, 4); oid1_Cnd ; if(aaa[0] == 0xf9) { //Temp = aaa[8] << 8 aaa[7]; if(aaa[8] < 7) { uart_send(USART3, setLed1, sizeof(setLed1)); delay(29); uart_send(USART3, setLed2, sizeof(setLed2)); delay(29); uart_send(USART3, setLed3, sizeof(setLed3)); delay(29); uart_send(USART3, setLed4, sizeof(setLed4)); aaa[0] = 0; oid1_Cnd = 0; Oid_State = 1; } else { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 2; } } } break; case 2: { rx_offset = 0; uart_send(USART3, step2, sizeof(step2)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 3; } } break; case 3: { rx_offset = 0; uart_send(USART3, step3, sizeof(step3)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 4; } } break; case 4: { rx_offset = 0; uart_send(USART3, step4, sizeof(step4)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 5; } } break; case 5: { rx_offset = 0; uart_send(USART3, step5, sizeof(step5)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 6; } } break; case 6: { rx_offset = 0; uart_send(USART3, step6, sizeof(step6)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 7; } } break; case 7: { rx_offset = 0; uart_send(USART3, step7, sizeof(step7)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 8; } } break; case 8: { rx_offset = 0; uart_send(USART3, step8, sizeof(step8)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 9; } } break; case 9: { rx_offset = 0; uart_send(USART3, step9, sizeof(step9)); delay(10); oid1_Cnd ; if(aaa[0] == 0xf9) { oid1_Cnd = 0; aaa[0] = 0; Oid_State = 10; } } break; case 10: { rx_offset = 0; uart_send(USART3, step10, sizeof(step10)); delay(40); HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); delay(40); HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); oid1_Cnd ; if(aaa[0] == 0xf9 && rx_offset > 0x10) { if(aaa[1] == 0x32) { // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET); // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); if(-1 != parseCode(&aaa[5], 46)) { } LED_Flag[test_cnd] = 2; test_cnd ; if(test_cnd == 2) { test_cnd = 0; } /*} else if(oid1_Cnd > 6) { LED_Flag[test_cnd] = 1; test_cnd ; if(test_cnd == 2) { test_cnd = 0; } }*/ } else { // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET); LED_Flag[test_cnd] = 1; test_cnd ; if(test_cnd == 2) { test_cnd = 0; } } oid1_Cnd = 0; aaa[0] = 0; Oid_State = 3; } } break; } } int main(void) { /* USER CODE BEGIN 1 */ // static uint32_t Temp = 0; /* 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 */ OID_Init(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_USART3_UART_Init(); MX_USART4_UART_Init(); /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ delay(30); if(OID_Test_Flag == 0) { if(0 == HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5)) { for(int i = 0; i < 5; i ) { LED_Flag[i] = 0; } OID_Test_Flag = 1; HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET); test_cnd2 = 0; test_cnd = 0; //printf("test start... %d", Oid_State); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); } } else { if(LED_Flag[0] != 0 && LED_Flag[1] != 0 && LED_Flag[2] != 0 && LED_Flag[3] != 0) { if(LED_Flag[2] == 1) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_SET); } else if(LED_Flag[2] == 2) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); } if(LED_Flag[3] == 1) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); } else if(LED_Flag[3] == 2) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); } if(LED_Flag[0] == 1) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_SET); } else if(LED_Flag[0] == 2) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET); } if(LED_Flag[1] == 1) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_SET); } else if(LED_Flag[1] == 2) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET); } if(LED_Flag[2] == 2 && LED_Flag[3] == 2) { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET); } if(LED_Flag[0] == 2 && LED_Flag[1] == 2) { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_SET); } else { HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET); } HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0, GPIO_PIN_SET); OID_Test_Flag = 0; HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET); Oid_State = 0; Oid_State1 = 0; //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_SET); } else { HAL_GPIO_TogglePin(GPIOF, GPIO_PIN_0); oid_discern(); oid_discern4(); } } // USART2->TDR = 0x88; /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK) { Error_Handler(); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } } /** * @brief USART2 Initialization Function * @param None * @retval None */ static void MX_USART2_UART_Init(void) { /* USER CODE BEGIN USART2_Init 0 */ /* USER CODE END USART2_Init 0 */ /* USER CODE BEGIN USART2_Init 1 */ /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; huart2.Init.BaudRate = 115200; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart2.Init.OverSampling = UART_OVERSAMPLING_16; huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart2) != HAL_OK) { //Error_Handler(); } /* USER CODE BEGIN USART2_Init 2 */ /* USER CODE END USART2_Init 2 */ /* USART2 interrupt Init */ HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); // NVIC_Config(USART2_IRQn); } static void MX_USART3_UART_Init(void) { /* USER CODE BEGIN USART3_Init 0 */ /* USER CODE END USART3_Init 0 */ /* USER CODE BEGIN USART3_Init 1 */ /* USER CODE END USART3_Init 1 */ huart3.Instance = USART3; huart3.Init.BaudRate = 115200; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; huart3.Init.Mode = UART_MODE_TX_RX; huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart3.Init.OverSampling = UART_OVERSAMPLING_16; huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart3) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART3_Init 2 */ /* USER CODE END USART3_Init 2 */ } static void MX_USART4_UART_Init(void) { /* USER CODE BEGIN USART2_Init 0 */ /* USER CODE END USART2_Init 0 */ /* USER CODE BEGIN USART2_Init 1 */ /* USER CODE END USART2_Init 1 */ huart4.Instance = USART4; huart4.Init.BaudRate = 115200; huart4.Init.WordLength = UART_WORDLENGTH_8B; huart4.Init.StopBits = UART_STOPBITS_1; huart4.Init.Parity = UART_PARITY_NONE; huart4.Init.Mode = UART_MODE_TX_RX; huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart4.Init.OverSampling = UART_OVERSAMPLING_16; huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart4) != HAL_OK) { Error_Handler(); } } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOF_CLK_ENABLE(); // NVIC_InitTypeDef NVIC_InitStruct; /*Configure GPIO pin Output Level */ // HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ // HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_14; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_13; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_7, GPIO_PIN_RESET); /*Configure GPIO pin : PB12 */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_14; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_14, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_15; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_1, GPIO_PIN_RESET); GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_0, GPIO_PIN_SET); GPIO_InitStruct.Pin = GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET); GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Configure PC.13 pin as input floating */ // GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; // GPIO_InitStruct.Pull = GPIO_NOPULL; // GPIO_InitStruct.Pin = GPIO_PIN_5; // HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Enable and set EXTI line 4_15 Interrupt to the lowest priority */ // HAL_NVIC_SetPriority(EXTI4_15_IRQn, 2, 0); // HAL_NVIC_EnableIRQ(EXTI4_15_IRQn); } /* USER CODE BEGIN 4 */ /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(char *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
标签: id
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论