void Hardware_Configuration() { //Config RCC(clock PLL flash periph_clock) RCC_Configuration(); //Config GPIO GPIO_Configuration(); //Config EXTI //EXTI_Configuration(); //Config TIM //TIM_Configuration(); //Config USART USART_Configuration(); //Config NVIC NVIC_Configuration(); //Config DMA DMA_Configuration(); //Config I2C I2C_Configuration(); }
/*=====================================================================================================*/ int main(void) { SystemInit(); //USART_Configuration(38400); Led_Config(); //BLDC_Config(); delay_ms(1000); I2C_Configuration(); delay_ms(1000); MPU6050_Initialize();//LSB gyro = 32.8 LSB acc = 2048 delay_ms(1000); HMC5883L_Initialize(); delay_ms(1000);//delay to avoid hating IMU_Get_Offset();//read MPU6050 to calib gyro delay_ms(1000);//wait for MPU to stabilize IMU_Get_Start(); delay_ms(1000);//delay to avoid hating TIMBase_Config(); //Rx_Configuration();//Configuration interrupt to calculate dutycycle received from Rx //PID_Init_Start(); //SysTick_Config(SystemCoreClock / 999);//start to read MPU each 1 ms //start PWM to test //BasicThr = 800; //printf(" Quadcopter Project\r\n"); while (1) { } /*=====================================================================================================*/ /*=====================================================================================================*/ }
/******************************************************************************* * Function Name : Sensor_Init * Description : Sensor初始化 * Input : None * Output : None * Return : None * Attention : 返回1成功,返回0失败 *******************************************************************************/ int Sensor_Init(void) { uint16_t i=0; uint8_t Sensor_IDCode = 0; I2C_Configuration(); if( 0 == I2C_WriteByte ( 0x12, 0x80 , ADDR_OV7670 ) ) /* Reset SCCB */ { return 0 ; } Delay(1500); if( 0 == I2C_ReadByte( &Sensor_IDCode, 1, 0x0b, ADDR_OV7670 ) ) /* read ID */ { return 0; /* error*/ } if(Sensor_IDCode == OV7670) /* ID = OV7670 */ { for( i=0 ; i < OV7670_REG_NUM ; i++ ) { if( 0 == I2C_WriteByte( OV7670_Reg[i][0], OV7670_Reg[i][1] , ADDR_OV7670 ) ) { return 0; } } } else /* NO ID */ { return 0; } return 1; }
void I2CHW_Reset(void) { __IO uint32_t Timeout; //uint8_t i; GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOB, &GPIO_InitStructure); I2C_DeInit(I2C1); RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE); RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, DISABLE); // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8; // GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // GPIO_Init(GPIOB, &GPIO_InitStructure); // // GPIO_SetBits(GPIOB,GPIO_Pin_9); // GPIO_SetBits(GPIOB,GPIO_Pin_8); // Timeout=0x1ff; // while(Timeout--); I2C_Configuration(); Timeout=0x1ff; while(Timeout--); }
/* * Application entry point. */ int main(void) { /* Shell thread */ Thread *shelltp = NULL; /* UART Configuration Structure */ SerialConfig sc; // Dummy ADC Configuration structure ADCConfig adc_conf; /* * System initializations. * - HAL initialization, this also initializes the configured device drivers * and performs the board-specific initializations. * - Kernel initialization, the main() function becomes a thread and the * RTOS is active. */ halInit(); chSysInit(); GPIO_Configuration(); //ADC_Configuration(); I2C_Configuration(); /* Start Serial Driver */ sc.sc_speed = 115200; sc.sc_cr1 = 0; sc.sc_cr2 = USART_CR2_STOP1_BITS | USART_CR2_LINEN; sc.sc_cr3 = 0; sdStart(&SD1, &sc); /* Shell manager initialization. */ shellInit(); /* * Creates the example thread. */ chThdCreateStatic(waThread1, sizeof(waI2CThread), NORMALPRIO, I2CThread, NULL); /* * Normal main() thread activity, in this demo it does nothing except * sleeping in a loop and check the button state, when the button is * pressed the test procedure is launched with output on the serial * driver 1. */ while (TRUE) { if(!shelltp) { shelltp = shellCreate( &shell_cfg, THD_WA_SIZE(2048), NORMALPRIO); } else if(chThdTerminated(shelltp)) { // Recovers memory of the previous shell. chThdRelease(shelltp); shelltp = NULL; } } }
int main() { DBG_Configuration(); SystemClock_Configuration(); DelayManager::DelayMs(150); RCC_Configuration(); GPIO_Configuration(); EXTI_Configuration(); NVIC_Configuration(); I2C_Configuration(&i2c); USART_Configuration(&uart); DMA_I2C_TX_Configuration(&i2cDmaTx); //__HAL_LINKDMA(&i2c, hdmatx, i2cDmaTx); MX_USB_DEVICE_Init(); systemMode = LOADING; graphMode = SECONDS; display.initDisplay(&i2c); display.setFont(font5x7); display.clearScreen(); display.printf(12, 50, logoStr); display.drawLine(0, 44, 127, 44); display.printf(12, 15, ".... LOADING ...."); display.drawFramebuffer(); sensorOk = co2sensor.initSensor(&uart); systemMode = ACTIVE; if (!sensorOk) { display.clearScreen(); display.printf(12, 50, logoStr); display.drawLine(0, 44, 127, 44); display.printf(12, 15, errorStr); display.drawFramebuffer(); errorHandler(NULL); } osThreadDef(processSensorThread, processSensorTask, osPriorityNormal, 0, 128); processSensorTaskHandle = osThreadCreate(osThread(processSensorThread), NULL); osThreadDef(processKeysThread, processKeysTask, osPriorityLow, 0, configMINIMAL_STACK_SIZE); processKeysTaskHandle = osThreadCreate(osThread(processKeysThread), NULL); osThreadDef(drawDataThread, drawDataTask, osPriorityHigh, 0, 256); drawDataTaskHandle = osThreadCreate(osThread(drawDataThread), NULL); osKernelStart(); while (true) { } }
int main() { uint16_t Addr; uint8_t WriteBuffer[256]={0}; uint8_t ReadBuffer[256]={0}; init_uart(); printf("\r\n****************************************************************\r\n"); I2C_Configuration(); for(Addr=0; Addr<256; Addr++){ WriteBuffer[Addr]=Addr+100; /* 填充WriteBuffer */ } //全部擦出,每个字节置0xff //I2C_Erase(); //printf("Erase ok\r\n"); /* 开始向EEPROM写数据 */ printf("\r\n EEPROM 24C64 Write Test \r\n"); for(Addr=0;Addr<sizeof(WriteBuffer);Addr++){ printf("%d ",WriteBuffer[Addr]); } printf("\r\n"); I2C_Write(I2C,ADDR_24L64,0x0,WriteBuffer,sizeof(WriteBuffer) ); printf("\r\n EEPROM 24C64 Write Test OK \r\n"); /* EEPROM读数据 */ printf("\r\n EEPROM 24C64 Read Test \r\n"); I2C_Read(I2C,ADDR_24L64,0x0,ReadBuffer,sizeof(ReadBuffer) ); for(Addr=0;Addr<sizeof(ReadBuffer);Addr++){ printf("%d ",ReadBuffer[Addr]); } printf("\r\n"); if(strcmp((const char *)ReadBuffer,(const char *)WriteBuffer)==0){ printf("\r\n EEPROM 24C64 Read Test ok \r\n"); } while (1) { } }
/***************************************************************************//** * @brief Initializes peripherals used by the I2C EEPROM driver. ******************************************************************************/ void I2C_EE_Init() { /* I2C Periph clock enable */ RCC_APB1PeriphClockCmd(I2C_EE_CLK, ENABLE); /* GPIO Periph clock enable */ RCC_APB2PeriphClockCmd(I2C_EE_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE); /* GPIO configuration */ GPIO_Configuration(); /* I2C configuration */ I2C_Configuration(); /* Select the EEPROM address according to the state of E0, E1, E2 pins */ EEPROM_ADDRESS = EEPROM_HW_ADDRESS; }
/** * @file main * @brief Main program. * @param None * @retval None */ int main(void) { SYSTICK_Init(); USART1_Config(); LED_GPIO_Config(); I2C_Configuration(); printf("\r\n 这是一个I2C外设(AT24C08)读写测试例程 \r\n"); I2C_Test(); while (1) { LEDXToggle(LED1); LEDXToggle(LED2); LEDXToggle(LED3); delay_ms(500); } }
/** * @brief Initializes peripherals used by the I2C EEPROM driver. * @param None * @retval None */ static void I2C_EE_Init() { /* I2C Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); /* GPIO Periph clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* GPIO configuration */ GPIO_Configuration(); /* I2C configuration */ I2C_Configuration(); #if defined (EE_M24C64_32) /* Select the EEPROM address according to the state of E0, E1, E2 pins */ EEPROM_ADDRESS = EEPROM_HW_ADDRESS; #elif defined (EE_M24C08) /* depending on the EEPROM Address selected in the i2c_ee.h file */ #ifdef EEPROM_Block0_ADDRESS /* Select the EEPROM Block0 to write on */ EEPROM_ADDRESS = EEPROM_Block0_ADDRESS; #endif #ifdef EEPROM_Block1_ADDRESS /* Select the EEPROM Block1 to write on */ EEPROM_ADDRESS = EEPROM_Block1_ADDRESS; #endif #ifdef EEPROM_Block2_ADDRESS /* Select the EEPROM Block2 to write on */ EEPROM_ADDRESS = EEPROM_Block2_ADDRESS; #endif #ifdef EEPROM_Block3_ADDRESS /* Select the EEPROM Block3 to write on */ EEPROM_ADDRESS = EEPROM_Block3_ADDRESS; #endif EEPROM_ADDRESS = EEPROM_HW_ADDRESS; #elif defined (EE_24LC02) EEPROM_ADDRESS = EEPROM_Block0_ADDRESS; #endif /* EE_M24C64_32 */ }
/** * @brief Main program * @param None * @retval None */ int main(void) { uint16_t Addr; uint8_t WriteBuffer[256],ReadBuffer[256]; Open207_LEDInit(); USART_Configuration(); I2C_Configuration(); printf("\r\n****************************************************************\r\n"); for(Addr=0; Addr<256; Addr++) WriteBuffer[Addr]=Addr; /* 填充WriteBuffer */ /* 开始向EEPROM写数据 */ printf("\r\n EEPROM 24C02 Write Test \r\n"); I2C_Write(Open207Z_I2Cx,ADDR_24LC02,0,WriteBuffer,sizeof(WriteBuffer) ); printf("\r\n EEPROM 24C02 Write Test OK \r\n"); /* EEPROM读数据 */ printf("\r\n EEPROM 24C02 Read Test \r\n"); I2C_Read(Open207Z_I2Cx,ADDR_24LC02,0,ReadBuffer,sizeof(WriteBuffer) ); if(memcmp(WriteBuffer,ReadBuffer,sizeof(WriteBuffer)) == 0 ) /* 匹配数据 */ printf("\r\n EEPROM 24C02 Read Test OK\r\n"); else printf("\r\n EEPROM 24C02 Read Test False\r\n"); /* Infinite loop */ while (1) { GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED1); GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2); GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3); GPIO_SetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4); Delay(0x5fffff); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED1); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED2); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED3); GPIO_ResetBits(Open207Z_LED_GPIO , Open207Z_GPIO_Pin_LED4); Delay(0x5fffff); } }
/** * @file main * @brief Main program. * @param None * @retval None */ int main(void) { SYSTICK_Init(); USART1_Config(); LED_GPIO_Config(); I2C_Configuration(); BMP180_Init(); while (1) { LEDXToggle(LED1); LEDXToggle(LED2); LEDXToggle(LED3); delay_ms(1000); BMP180_TEST(); } }
/******************************************************************************* * Function Name : I2C_EE_Init * Description : Initializes peripherals used by the I2C EEPROM driver. * Input : None * Output : None * Return : None *******************************************************************************/ void I2C_EE_Init() { /* I2C configuration */ I2C_Configuration(); /* depending on the EEPROM Address selected in the i2c_ee.h file */ #ifdef EEPROM_Block0_ADDRESS /* Select the EEPROM Block0 to write on */ EEPROM_ADDRESS = EEPROM_Block0_ADDRESS; #endif #ifdef EEPROM_Block1_ADDRESS /* Select the EEPROM Block1 to write on */ EEPROM_ADDRESS = EEPROM_Block1_ADDRESS; #endif #ifdef EEPROM_Block2_ADDRESS /* Select the EEPROM Block2 to write on */ EEPROM_ADDRESS = EEPROM_Block2_ADDRESS; #endif #ifdef EEPROM_Block3_ADDRESS /* Select the EEPROM Block3 to write on */ EEPROM_ADDRESS = EEPROM_Block3_ADDRESS; #endif }
/** * @brief Main program. * @param None * @retval None */ int main(void) { int i; RCC_Configuration(); GPIO_Configuration(); I2C_Configuration(); i=0; /* Enable I2C2 */ I2C_Enable(BOARD_I2C,ENABLE); /* Enable Acknowledge */ I2C_Acknowledge_Enable(BOARD_I2C,ENABLE); /* Send a NACK for the next data byte which will be received into the shift register */ I2C_NACKPosition_Enable(BOARD_I2C,I2C_NACKPOSITION_NEXT); /* Wait until I2C Bus is idle */ while(I2C_GetBitState(BOARD_I2C, I2C_FLAG_I2CBSY)); /* Send a start condition to I2C bus */ I2C_StartOnBus_Enable(BOARD_I2C, ENABLE); /* Wait until SBSEND bit is set */ while(!I2C_StateDetect(BOARD_I2C, I2C_PROGRAMMINGMODE_MASTER_SBSEND)); /* Send slave address to I2C bus */ I2C_AddressingDevice_7bit(BOARD_I2C, SLAVE_ADDRESS7, I2C_DIRECTION_RECEIVER); /* Disable ACK before clearing ADDSEND bit */ I2C_Acknowledge_Enable(BOARD_I2C, DISABLE); /* Wait until ADDSEND bit is set and clear it */ while(!I2C_StateDetect(BOARD_I2C, I2C_PROGRAMMINGMODE_MASTER_RECEIVER_ADDSEND)); /* Wait until the last data byte is received into the shift register */ while(!I2C_GetBitState(BOARD_I2C, I2C_FLAG_BTC)); /* Send a stop condition */ I2C_StopOnBus_Enable(BOARD_I2C, ENABLE); /* Wait until the reception data register is not empty */ while(!I2C_GetBitState(BOARD_I2C, I2C_FLAG_RBNE)); /* Read a data from I2C_DTR */ BOARD_I2C_Buf_Read[i++]=I2C_ReceiveData(BOARD_I2C); /* Wait until the reception data register is not empty */ while(!I2C_GetBitState(BOARD_I2C, I2C_FLAG_RBNE)); /* Read a data from I2C_DTR */ BOARD_I2C_Buf_Read[i++]=I2C_ReceiveData(BOARD_I2C); while(BOARD_I2C->CTLR1&0x0200); I2C_NACKPosition_Enable(BOARD_I2C,I2C_NACKPOSITION_CURRENT); /* Enable Acknowledge */ I2C_Acknowledge_Enable(BOARD_I2C, ENABLE); while(1); }
void init(void) { SystemInit(); //Setup SystickTimer if (SysTick_Config(SystemCoreClock / 1000)){ColorfulRingOfDeath();} GPIO_Configuration(); #ifdef USE_MICROUSB USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); #endif #ifdef USE_SDIO UB_Fatfs_Init(); #endif #ifdef USE_ADC ADC_Configuration(); #endif #ifdef USE_I2C I2C_Configuration(); #endif #ifdef USE_SPI SPI_Configuration(); #endif #ifdef USE_ENCODER TIM_encoder_Configuration(); #endif #ifdef USE_USART1 USART1_Configuration(); #endif #ifdef USE_USART2 USART2_Configuration(); #endif #ifdef USE_USART3 USART3_Configuration(); #endif #ifdef USE_CAN CAN_Configuration(); #endif #ifdef USE_PWM TIM_pwm_Configuration(); #endif #ifdef USE_EXTI EXTI_Configuration(); #endif NVIC_Configuration(); }
/******************************************************************************* * Function Name : I2C_SetState * Description : Set state of I2Cx and try to solve problem after errors * Input : I2C TypeDef, new state * Output : None * Return : None *******************************************************************************/ void I2C_SetState(I2C_TypeDef* I2Cx, enum I2CState state) { static u8 countFault = 0; u32 timeout; GPIO_TypeDef * I2Cx_GPIO; u16 I2Cx_PIN_SDA, I2Cx_PIN_SCL; // Set new state if(I2Cx == I2C1) { I2C1_state = state; } else if(I2Cx == I2C2) { I2C2_state = state; } // count faults switch(state) { case NONE: case ADNM: countFault = 0; break; case SCF: case B1NT: case B2NT: case B3NT: case B4NT: case BxNT: case B1NR: case B2NR: case B3NR: case B4NR: case BxNR: countFault++; break; case BTF: case BRF: countFault = 0; break; } // If 5 or more faults occurred if(5 < countFault) { // Enable I2Cx Software Reset I2C_SoftwareResetCmd(I2Cx, ENABLE); // Define GPIO and Pins for I2Cx if(I2Cx == I2C1) { I2Cx_GPIO = I2C1_GPIO; #if defined(USE_I2C1_Remap) I2Cx_PIN_SCL = I2C1_REMAP_GPIO_PIN_SCL; I2Cx_PIN_SDA = I2C1_REMAP_GPIO_PIN_SDA; // Configure SCL and SDA as open drain output I2Cx_GPIO->CRH &= ~0x00000088; I2Cx_GPIO->CRH |= 0x00000077; #else I2Cx_PIN_SCL = I2C1_GPIO_PIN_SCL; I2Cx_PIN_SDA = I2C1_GPIO_PIN_SDA; // Configure SCL and SDA as open drain output I2Cx_GPIO->CRL &= ~0x88000000; I2Cx_GPIO->CRL |= 0x77000000; #endif } else if(I2Cx == I2C2) { I2Cx_GPIO = I2C2_GPIO; I2Cx_PIN_SCL = I2C2_GPIO_PIN_SCL; I2Cx_PIN_SDA = I2C2_GPIO_PIN_SDA; // Configure SCL and SDA as open drain output I2Cx_GPIO->CRH &= ~0x00008800; I2Cx_GPIO->CRH |= 0x00007700; } // Release SDA I2Cx_GPIO->ODR |= I2Cx_PIN_SDA; // Toggle CLK until SDA and SCL released or timeout exceeded timeout = TIMEOUT; while((I2Cx_GPIO->IDR ^ (I2Cx_PIN_SDA | I2Cx_PIN_SCL)) && timeout--) { I2Cx_GPIO->ODR ^= I2Cx_PIN_SCL; } // Configure SCL and SDA as alternate function open drain if(I2Cx == I2C1) { #if defined(USE_I2C1_Remap) I2Cx_GPIO->CRH |= 0x000000FF; #else I2Cx_GPIO->CRL |= 0xFF000000; #endif } else if(I2Cx == I2C2) { I2Cx_GPIO->CRH |= 0x0000FF00; } // If SDA released if(0 < (I2Cx_GPIO->IDR & I2Cx_PIN_SDA)) { // Close the I2C Bus I2C_DeInit(I2Cx); //Configure the I2C Bus I2C_Configuration(I2Cx); } // Reset countFault countFault = 0; } }
int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this i s done through SystemInit() function which is called from startup file (startup_stm32f10x_xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f10x.c file */ //GPIO_InitTypeDef GPIO_InitStructure; //uint32_t irq; //test IRQ /* System clocks configuration ---------------------------------------------*/ SystemInit(); RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); GPIO_WriteBit(PWR_LED, Bit_RESET); GPIO_WriteBit(ALARM_LED, Bit_SET); GPIO_WriteBit(RUNSTAT_LED, Bit_SET); GPIO_WriteBit(ETH_RESET, Bit_RESET);//拉低DM9000 nRST, 延时复位启动 DataBase_Init(DevIPAddressTab); #ifndef TEST /* com1 configuration ------------------------------------------------------*/ COM1_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< COM1 config complete <<<<<<<\r\n\r\n"); /* com2 configuration ------------------------------------------------------*/ //COM2_Configuration(); #endif /* i2c configuration ------------------------------------------------------*/ printf(" >>>>>>> I2C config begin >>>>>>>\r\n"); I2C_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< I2C config complete <<<<<<<\r\n\r\n"); #ifndef TEST /* RTC configuration--------------------------------------------------------*/ printf(" >>>>>>> RTC config begin >>>>>>>\r\n"); RTC_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< RTC config complete <<<<<<<\r\n\r\n"); #endif #ifdef CAN_APP /* can configuration ------------------------------------------------------*/ printf(" >>>>>>> CAN config begin >>>>>>>\r\n"); CAN_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< CAN config complete <<<<<<<\r\n\r\n"); #endif #ifndef TEST /*temperature configuration------------------------------------------------------*/ printf(" >>>>>>> TEMPMEA config begin >>>>>>>\r\n"); TEMPMEA_Confitguration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< TEMPMEA config complete <<<<<<<\r\n\r\n"); #endif /* SysTick configuration ------------------------------------------------------*/ printf(" >>>>>>> SysTick config begin >>>>>>>\r\n"); SysTick_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_RESET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< SysTick config complete <<<<<<<\r\n\r\n"); /* NVIC configuration ------------------------------------------------------*/ printf(" >>>>>>> NVIC config begin >>>>>>>\r\n"); NVIC_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_RESET); #endif printf(" <<<<<<< NVIC config complete <<<<<<<\r\n\r\n"); /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */ /* The Localtime should be updated during the Ethernet packets processing */ NVIC_SetPriority (SysTick_IRQn, 1); /* test IRQ*/ // irq = NVIC_GetPriority(SysTick_IRQn); // irq = NVIC_GetPriority(ETH_IRQn); // irq = NVIC_GetPriority(I2C1_ER_IRQn); // irq = NVIC_GetPriority(I2C1_EV_IRQn); /* ethernet configuration ------------------------------------------------------*/ //可添加延时, 用以确保DM9000启动时电压满足芯片要求 //"nRST must not go high until after the VDDIO and VDD_CORE supplies are stable" 手册P51 GPIO_WriteBit(ETH_RESET, Bit_SET); //拉高DM9000 nRST, 复位启动 printf(" >>>>>>> ETH config begin >>>>>>>\r\n"); Ethernet_Configuration(); #ifdef TEST_PARTS GPIO_WriteBit(CANTX_LED, Bit_RESET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_RESET); GPIO_WriteBit(COMRX_LED, Bit_SET); #endif printf(" <<<<<<< ETH config complete <<<<<<<\r\n\r\n"); #ifdef WATCHDOG /* WATCHDOG configuration ------------------------------------------------------*/ IWDG_Configuration(); #endif //判断是否有以太网链接 if(EthInitState) { CommunicationInit(); } printf(" ******* 输入'$'将触发串口控制台!*******\r\n\r\n"); GPIO_WriteBit(CANTX_LED, Bit_SET); GPIO_WriteBit(CANRX_LED, Bit_SET); GPIO_WriteBit(COMTX_LED, Bit_SET); GPIO_WriteBit(COMRX_LED, Bit_SET); //启动完成, 进入常规流程 #ifdef _TEST uint8_t test = 0; #endif while (1) { Di_PostWork(); LwIP_Periodic_Handle(LocalTime); Task_Periodic_Handle(LocalTime); //判断以太网状态, 决定是否要复位以太网 EthStateCheck(); reset_flag = Get_eth_reset_flag(); if(reset_flag == Ethernet_SWRST_FLAG) Ethernet_SWRST(); else if(reset_flag == Ethernet_HWRST_FLAG) Ethernet_HWRST(); #ifdef _TEST //tyh:20130407 eth reset test if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1)) { //eth_reg = ETH_ReadPHYRegister(0x1F, 17); Ethernet_HWRST(); } test = DiStatus_DI[1].Value; #endif // else // { // if( EthLinkCheck() ) // { // //tyh:20130403 send udp test_message // if((DiStatus_DI[1].Value != test)&&(DiStatus_DI[1].Value == 1)) // { // Udp_timing_test(); // } // // test = DiStatus_DI[1].Value; // } // } #ifdef WATCHDOG WDGFeeding(); #endif } }
void BSP_Init (void) { // Clock Config: HSE 72 MHz #if __RTC_ENABLE == ON RTC_Configuration(); #else RCC_Configuration(); #endif #if __USART1_ENABLE == ON // USART1 Config ==> FTDI USART1_Configuration(); #endif #if __USART3_ENABLE == ON // USART3 Config ==> Trypano support card USART3_Configuration(); #endif #if __SRAM_ENABLE == OFF && __LED_ENABLE == ON // LED Config LED_Configuration(); #endif #if __SWITCH_ENABLE == ON // SWITCH Config SWITCH_Configuration(); #endif // I2C Config #if __I2C_ENABLE == ON I2C_Configuration(); #endif #if __POT_ENABLE == ON // Pot / ADC Config ADC_POT_Configuration(); #endif #if __USB_ENABLE == ON //USB Config USB_Configuration(); #endif #if __DAC1_ENABLE == ON //DAC Config and start DAC1_Configuration(); #endif #if __SRAM_ENABLE == ON // RAM Config SRAM_Configuration(); #endif #if __SDCARD_ENABLE == ON // SDCard Config SDCARD_Configuration(); #endif #if __DAC2_ENABLE == ON DAC2_Configuration(); #endif #if __ADCe1_ENABLE == ON ADCe1_Configuration(); #endif }
int main(void) { unsigned char i; unsigned char str_len; char string_disp[10] = {0}; //RCC_Configuration(); delay_init(); sys_gpio_init(); I2C_Configuration(); led_5x7_time_init(); led_5x7_print_pic(6, 2); while(1) { if(flag_data_receive) { copyArray(RxBuffer, buffer, BUFFER_SIZE); switch(buffer[0]) { case DISP_CHAR_5X7: MovingTime = ((unsigned int)buffer[2]) << 8; MovingTime += buffer[3]; led_5x7_print_ascii(buffer[1], MovingTime); if(MovingTime == 0)break; if(MovingTime != 0) { clearBuffer(buffer, BUFFER_SIZE); flag_data_receive = 0; clearBuffer(RxBuffer, I2C_BUFFER_MAX); } break; case DISP_STRING: str_len = buffer[1]; for(i = 0;i < str_len;i ++) { string_disp[i] = (char)buffer[i+2]; } MovingTime = ((unsigned int)buffer[2+str_len])<<8; MovingTime += buffer[3+str_len]; led_5x7_print_string(string_disp, MovingTime); if(MovingTime == 0)break; clearBuffer(buffer, BUFFER_SIZE); flag_data_receive = 0; clearBuffer(RxBuffer, I2C_BUFFER_MAX); break; case SET_DISP_ORIENTATION: led_5x7_set_orientation(buffer[1]); clearBuffer(buffer, BUFFER_SIZE); flag_data_receive = 0; clearBuffer(RxBuffer, I2C_BUFFER_MAX); break; case DISP_PIC: MovingTime = ((unsigned int)buffer[2]) << 8; MovingTime += buffer[3]; led_5x7_print_pic(buffer[1], MovingTime); if(MovingTime == 0)break; if(buffer[1] == 7) { clearBuffer(buffer, BUFFER_SIZE); flag_data_receive = 0; clearBuffer(RxBuffer, I2C_BUFFER_MAX); } else if(MovingTime != 0) { clearBuffer(buffer, BUFFER_SIZE); flag_data_receive = 0; clearBuffer(RxBuffer, I2C_BUFFER_MAX); } break; case DISP_DATA: MovingTime = ((unsigned int)buffer[6]) << 8; MovingTime += buffer[7]; led_5x7_print_data(&buffer[1], MovingTime); if(MovingTime == 0)break; if(MovingTime != 0) { clearBuffer(buffer, BUFFER_SIZE); flag_data_receive = 0; clearBuffer(RxBuffer, I2C_BUFFER_MAX); } break; default: break; } } GPIO_Test_for_TE(); } }