//初始化24L01的IO口 void NRF24L01_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_NRF24L01_CE, ENABLE); //使能GPIO的时钟 GPIO_InitStructure.GPIO_Pin = NRF24L01_CE; //NRF24L01 模块片选信号 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_NRF24L01_CE, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_NRF24L01_CSN, ENABLE); //使能GPIO的时钟 GPIO_InitStructure.GPIO_Pin = NRF24L01_CSN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_NRF24L01_CSN, &GPIO_InitStructure); Set_NRF24L01_CE; //初始化时先拉高 Set_NRF24L01_CSN; //初始化时先拉高 //配置NRF2401的IRQ GPIO_InitStructure.GPIO_Pin = NRF24L01_IRQ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU ; //上拉输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_NRF24L01_IRQ, &GPIO_InitStructure); GPIO_SetBits(GPIO_NRF24L01_IRQ,NRF24L01_IRQ); SPI_Configuration(); //初始化SPI Clr_NRF24L01_CE; //使能24L01 Set_NRF24L01_CSN; //SPI片选取消 }
/*************************************************************************** Declaration : void init_mcu (void) Function : Initializes ATmega88 MCU ***************************************************************************/ void init_mcu (void) { #ifdef DEBUG debug(); #endif /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Configure EXTI Line9 to generate an interrupt on falling edge */ EXTI_Configuration(); /* SPI the GPIO ports */ SPI_Configuration(); /* USART Configuration as SPI */ USART1_Configuration(); /* TIM2 Configuration */ TIM2_Configuration(); /* TIM3 Configuration */ TIM3_Configuration(); /* TIM4 Configuration */ TIM4_Configuration(); /* Configure RTC clock source and prescaler */ RTC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); }
/*********************************************************** * Function: * Description: * Input: * Input: * Output: * Return: * Others: ***********************************************************/ static void rt_thread_entry_sd_test( void* parameter ) { FRESULT res; char tempbuf[64]; rt_sem_take( &sem_dataflash, RT_TICK_PER_SECOND * FLASH_SEM_DELAY ); SPI_Configuration(); res = SD_Init(); if(0 == res) { rt_kprintf("\r\n SD CARD INIT OK!"); memset(tempbuf,0,sizeof(tempbuf)); SD_GetCID(tempbuf); rt_kprintf("\r\n CID="); printf_hex_data(tempbuf, 16); SD_GetCSD(tempbuf); rt_kprintf("\r\n SID="); printf_hex_data(tempbuf, 16); rt_kprintf("\r\n SD 容量=%d",SD_GetCapacity()); } else { rt_kprintf("\r\n SD CARD INIT ERR = %d",res); } if(0 == f_mount(MMC, &fs)) { rt_kprintf("\r\n f_mount SD OK!"); } rt_sem_release(&sem_dataflash); while( 1 ) { rt_thread_delay( RT_TICK_PER_SECOND / 20 ); } }
void AD7687_Configuration (void) { SPI_Configuration (); // GPIO_Configuration (); // while(1){ // AD7687_ResetConverPin (); // STK_delay10ms (1); // AD7687_SetConverPin (); // STK_delay10ms (200); // } //PIT_Configuration (); FTM_Configuration (); }
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(); }
int main(void) { int flag; int i; //only for sd testing extern u8 sd_recv_buf[512]; extern u8 sd_send_buf[512]; u8 ret = 1; // only for sd testing RCC_Configuration(); RTC_Configuration(); GPIO_Configuration(); SPI_Configuration(); NVIC_Configuration(); USART_Configuration(); EXTI_cfg(); //only for sd testing ret = MSD_Init(); ret = MSD_GetMediumCharacteristics(); MSD_EarseBlock(0,Mass_Block_Count); //only for sd testing //system start working GPIO_SetBits(GPIOC,GPIO_Pin_14); //wait for the moment that the device has been fxed into the rocket // for (i=0;i<6*5;i++) {delay();} //delay 10 minutes //self-testing //first, test wireless data transmition Timedisplay=0; while (Timedisplay<10) { USART_SendData(USART3, 'A'); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); if ((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) && (USART_ReceiveData(USART3)==66)) //except "B" { //static char Responce[]="Wireless data transmition test completed"; for (i=0;i<strlen(Responce);i++) { USART_SendData(USART3, Responce[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } break; } //USART_ClearFlag(USART3, USART_FLAG_RXNE); } if (Timedisplay==10) { GPIO_ResetBits(GPIOC,GPIO_Pin_14); //Write into SD:ERROR in data transmition //only for testing for (i=0;i<strlen(errorDatatransmition);i++) { sd_send_buf[i]=errorDatatransmition[i]; } ret = MSD_WriteBlock(sd_send_buf,0,512); //only for testing return(0); } //waiting for the continue order for (i=0;i<4000;i++); while (1) { if ((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) && (USART_ReceiveData(USART3)==78)) //except "N" { break; } //USART_ClearFlag(USART3, USART_FLAG_RXNE); } //second,test GPS Timedisplay=0; flag=1; while ((Timedisplay<60*5) && (!((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) && (USART_ReceiveData(USART3)==71)))) //except "G" { if ((USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET)) { flag=1; USART_SendData(USART3, USART_ReceiveData(USART1)); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } //USART_ClearFlag(USART1, USART_FLAG_RXNE); } if (flag==0) { GPIO_ResetBits(GPIOC,GPIO_Pin_14); for (i=0;i<strlen(errorGPS);i++) { USART_SendData(USART3, errorGPS[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } //Write into SD:ERROR in GPS for (i=0;i<strlen(errorGPS);i++) { sd_send_buf[i]=errorGPS[i]; } ret = MSD_WriteBlock(sd_send_buf,1,512); return(0); } //static char Responce2[]="GPS test completed"; for (i=0;i<strlen(Responce2);i++) { USART_SendData(USART3, Responce2[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } //waiting for the continue order for (i=0;i<4000;i++); while (1) { if ((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) && (USART_ReceiveData(USART3)==78)) //except "N" { break; } //USART_ClearFlag(USART3, USART_FLAG_RXNE); } //third, test clock USART_SendData(USART3, 'C'); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); Timedisplay=0; flag=0; while ((Timedisplay<20) && (!((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) && (USART_ReceiveData(USART3)==69)))); //except "E" if ((abs(Timedisplay-10)>2) && (USART_ReceiveData(USART3)==69)) { GPIO_ResetBits(GPIOC,GPIO_Pin_14); for (i=0;i<strlen(errorclock);i++) { USART_SendData(USART3, errorclock[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } //Write into SD:ERROR in timing //only for testing for (i=0;i<strlen(errorclock);i++) { sd_send_buf[i]=errorclock[i]; } ret = MSD_WriteBlock(sd_send_buf,2,512); //only for testing return(0); } //static char Responce3[]="clock test completed"; for (i=0;i<strlen(Responce3);i++) { USART_SendData(USART3, Responce3[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } //static char Responce4[]="ALL test completed,wait for launching signal"; for (i=0;i<strlen(Responce4);i++) { USART_SendData(USART3, Responce4[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } while (!((USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == SET) && (USART_ReceiveData(USART3)==76))); //except for "L" //delay(); //static char Responce5[]="Go! Good Luck!"; for (i=0;i<strlen(Responce5);i++) { USART_SendData(USART3, Responce5[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } /* Enable the USART Receive interrupt: this interrupt is generated when the USART1 receive data register is not empty */ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); //USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); Timedisplay=0; while(1) { if (Timedisplay>=OPEN_Parachute) { GPIO_SetBits(GPIOC,GPIO_Pin_6); //static char Responce6[]="The parachute is open@"; for (i=0;i<strlen(Responce6);i++) { USART_SendData(USART3, Responce6[i]); while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); } } } return(0); }
void vidInit(void) { SPI_Configuration(); TIMER_Configuration(); vidClearScreen(); }
int main(void) { int i; Systick_Configuration(); LED_Configuration(); button_Configuration(); usart1_Configuration(9600); SPI_Configuration(); TIM4_PWM_Init(); Encoder_Configration(); buzzer_Configuration(); ADC_Config(); //curSpeedX = 0; //curSpeedW = 0; //shortBeep(2000, 8000); while(1) { readSensor(); readGyro(); readVolMeter(); printf("LF %d RF %d DL %d DR %d aSpeed %d angle %d voltage %d lenc %d renc %d\r\n", LFSensor, RFSensor, DLSensor, DRSensor, aSpeed, angle, voltage, getLeftEncCount(), getRightEncCount()); displayMatrix("UCLA"); setLeftPwm(100); setRightPwm(100); delay_ms(1000); } //forwardDistance(4000,0,0,true); //displayMatrix("Sped"); //targetSpeedX = 100; //delay_ms(2000); // //targetSpeedX = 100; //delay_ms(2000); //printf("==============================================\n\r=======================================================\r\n"); //delay_ms(1000); //displayMatrix("Wat"); //delay_ms(1000); //displayMatrix("STOP"); //displayMatrix("GO"); turnRightAngle(LEFT); targetSpeedW = 0; delay_ms(1000); turnRightAngle(RIGHT); targetSpeedW = 0; delay_ms(1000); displayMatrix("STOP"); delay_ms(3000); targetSpeedX = 0; // targetSpeedW = 10; delay_ms(1000); targetSpeedX = 0; targetSpeedW = 0; return 0; }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Configure the SPI */ SPI_Configuration(); /* USARTy configuration ------------------------------------------------------*/ /* USARTy configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled - USART Clock Enabled - USART CPOL: Clock is active High - USART CPHA: Data is captured on the second edge - USART LastBit: The clock pulse of the last data bit is output to the SCLK pin */ USART_ClockInitStructure.USART_Clock = USART_Clock_Enable; USART_ClockInitStructure.USART_CPOL = USART_CPOL_High; USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge; USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable; USART_ClockInit(USARTy, &USART_ClockInitStructure); USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; 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(USARTy, &USART_InitStructure); /* Configure the USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); while(NbrOfDataToRead2--) { /* Write one byte in the USARTy Transmit Data Register */ USART_SendData(USARTy, TxBuffer1[TxCounter1++]); /* Wait until end of transmit */ while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET) { } /* Wait the byte is entirtly received by SPIy */ while(SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer2 */ RxBuffer2[RxCounter2++] = SPI_I2S_ReceiveData(SPIy); } /* Clear the USARTy Data Register */ USART_ReceiveData(USARTy); while(NbrOfDataToRead1--) { /* Wait until end of transmit */ while(SPI_I2S_GetFlagStatus(SPIy, SPI_I2S_FLAG_TXE)== RESET) { } /* Write one byte in the SPIy Transmit Data Register */ SPI_I2S_SendData(SPIy, TxBuffer2[TxCounter2++]); /* Send a Dummy byte to generate clock to slave */ USART_SendData(USARTy, DYMMY_BYTE); /* Wait until end of transmit */ while(USART_GetFlagStatus(USARTy, USART_FLAG_TC) == RESET) { } /* Wait the byte is entirtly received by USARTy */ while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer1 */ RxBuffer1[RxCounter1++] = USART_ReceiveData(USARTy); } /* Check the received data with the send ones */ TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1); /* TransferStatus = PASSED, if the data transmitted from USARTy and received by SPIy are the same */ /* TransferStatus = FAILED, if the data transmitted from USARTy and received by SPIy are different */ TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); /* TransferStatus = PASSED, if the data transmitted from SPIy and received by USARTy are the same */ /* TransferStatus = FAILED, if the data transmitted from SPIy and received by USARTy are different */ while (1) { } }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int SD_Test(void) { u16 i; FIL file; char data[512]; UINT number=0; char *s="hello,lightjpu\n"; //Init_Device(); //RTC_Start(); SPI_Configuration(); res = f_mount(0, &fs); //res = f_mkfs(0,0,0); // if(res!=FR_OK) // { // while(1); // } res = f_open(&file, "data.txt", FA_CREATE_ALWAYS | FA_READ | FA_WRITE); if(res!=FR_OK) { while(1); } for(i=0;i<512;i++) { data[i] = 0x38; } res = f_write(&file, data, 512, &number); if(res!=FR_OK) { while(1); } while(1) { //if(fgets(data, sizeof(data), &file)==NULL) //{ break; //} //prints(data); } f_close(&file); // write_time = Time_GetUnixTime(); res = f_open(&file, "331.txt", FA_CREATE_ALWAYS | FA_WRITE); for(i=0;i<3;i++) { res = f_write(&file, s, 14, &br); if(br<14) //判断是否磁盘写满 { break; } } // write_time = Time_GetUnixTime() - write_time; f_close(&file); SD_PWR_OFF(); while(1) { /* if(TimeDisplay) { current_time = Time_GetUnixTime(); time_now = Time_GetCalendarTime(); USART_SendData(USART1, 0x0c); while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET); printf("\r\nUNIX时间:%d", current_time); printf("\t当前时间:%d-%d-%d %d %02d:%02d:%02d\t", time_now.tm_year, \ time_now.tm_mon+1, time_now.tm_mday, time_now.tm_wday+1,\ time_now.tm_hour, time_now.tm_min, time_now.tm_sec); TimeDisplay = 0; } */ } }
void System_Configuration(void) { __disable_interrupt(); /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Unlock the Flash Program Erase controller */ FLASH_Unlock(); /* USART Configuration */ USART_Configuration(USART_DXL,Baudrate_DXL); //dxl_initialize(USART_DXL,Baudrate_DXL); zgb_initialize(0); //USART_Configuration(USART_ZIGBEE,Baudrate_ZIGBEE); //USART_Configuration(USART_PC,1000000); //USART_Configuration(USART_PC,3000000); USART_Configuration(USART_PC,Baudrate_PC); /* ADC Configuration */ ADC_Configuration(); SysTick_Configuration(); Timer_Configuration(); SPI_Configuration(); Buzzer_Configuration(); GPIO_ResetBits(PORT_ENABLE_TXD, PIN_ENABLE_TXD); // TX Disable GPIO_SetBits(PORT_ENABLE_RXD, PIN_ENABLE_RXD); // RX Enable GPIO_SetBits(PORT_SIG_ACC_CS,PIN_SIG_ACC_CS); GPIO_SetBits(PORT_SIG_GYRO_CS,PIN_SIG_GYRO_CS); __enable_interrupt(); Gyro_Configuration(); ACC_Configuration(); }
/** * @brief . * @param None * @retval None */ void ILI_Configuration (void) { GPIO_Configuration (); SPI_Configuration (); ILI_Initial (); }