int main3(void) { //test_lcd(); //return 0; //test_adc(); /* Initialize system */ //SystemInit(); //TM_RCC_InitSystem(); //HAL_Init(); TM_DELAY_Init(); //GPIO_setup(); int i = 0; #ifdef DISCOVERY // GPIO_SetBits(GPIOD, GPIO_Pin_12); //Подаем «1» на PD12 //main2(); //return 0; //GPIO_SetBits(GPIOD, GPIO_Pin_13); //Подаем «1» на PD12 while(1) { //Если кнопка нажата, то… if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)==1) { char sz[32]; sprintf(sz, "%d", i); lcd_print(sz, 0); //delay(1000); int tm = 500; GPIO_SetBits(GPIOD, GPIO_Pin_12); //Подаем «1» на PD12 delay(tm); //Функция задержки GPIO_SetBits(GPIOD, GPIO_Pin_13); //Подаем «1» на PD13 delay(tm); GPIO_SetBits(GPIOD, GPIO_Pin_14); //Подаем «1» на PD14 delay(tm); //GPIO_SetBits(GPIOD, GPIO_Pin_15); //Подаем «1» на PD15 delay(tm); GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14/*|GPIO_Pin_15*/); //Сбрасываем все пины в «0» delay(tm); } //delay(1000); // ~3sec delay(100); // ~.3sec if(i % 2 == 0) GPIO_SetBits(GPIOD, GPIO_Pin_15); //Подаем «1» на PD15 else GPIO_ResetBits(GPIOD, GPIO_Pin_15); //Подаем «1» на PD15 i++; } return 0; #endif //Если кнопка нажата, то… /* GPIO_setup(); button_setup(); GPIO_ResetBits(GPIOD, GPIO_Pin_12 | GPIO_Pin_13 |GPIO_Pin_14 |GPIO_Pin_15 ); initTimer(); startTimer(1000); while(1) { } */ set_port(GPIOA,GPIO_Pin_5); // shotin set_port(GPIOC, GPIO_Pin_5); // shotout set_port(GPIOA, GPIO_Pin_3); // switch 1 reset_port(GPIOC, GPIO_Pin_13); // left reset_port(GPIOC, GPIO_Pin_14); // right reset_port(GPIOA, GPIO_Pin_4); // switch 2 while(1) { if (get_port(GPIOC,GPIO_Pin_13)==1) // left { lcd_print("left", 0); set_port(GPIOA,GPIO_Pin_3); // sw1 } else reset_port(GPIOA,GPIO_Pin_3); if (get_port(GPIOC,GPIO_Pin_14)==1) // right { set_port(GPIOA, GPIO_Pin_4); // switch 2 lcd_print("right", 0); } else reset_port(GPIOA, GPIO_Pin_4); if(i % 2 == 0) set_port(GPIOC, GPIO_Pin_5); // shotout else reset_port(GPIOC, GPIO_Pin_5); Delayms(3); i++; } return 0; }
void reset_port(PortType port, int id) { GPIO_ResetBits(port, id); // sw2 }
u16 sampleADC(u8 ADCnum) { u16 ADCres = 0; switch(ADCnum) { case NUM_ADC1: //TxDString("starting ADC\n\r"); GPIO_SetBits(ADC_1_PORT_SIG_MOT, ADC_1_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_1_PORT_SIG_MOT, ADC_1_PIN_SIG_MOT1M); GPIO_ResetBits(PORT_ADC_SELECT0,PIN_ADC_SELECT0); GPIO_ResetBits(PORT_ADC_SELECT1,PIN_ADC_SELECT1); ADC_RegularChannelConfig(ADC1, SIG_ADC_0, 1 , ADC_SampleTime_239Cycles5); uDelay(30); /* Start ADC1,ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC2, ENABLE); uDelay(5); ADCres = (ADC_GetConversionValue(ADC1)); ADCres = isZero(ADCres); GPIO_ResetBits(ADC_1_PORT_SIG_MOT, ADC_1_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_1_PORT_SIG_MOT, ADC_1_PIN_SIG_MOT1M); break; case NUM_ADC2: GPIO_SetBits(ADC_2_PORT_SIG_MOT, ADC_2_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_2_PORT_SIG_MOT, ADC_2_PIN_SIG_MOT1M); GPIO_SetBits(PORT_ADC_SELECT0,PIN_ADC_SELECT0); GPIO_ResetBits(PORT_ADC_SELECT1,PIN_ADC_SELECT1); ADC_RegularChannelConfig(ADC1, SIG_ADC_0, 1 , ADC_SampleTime_239Cycles5); uDelay(30); /* Start ADC1,ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC2, ENABLE); uDelay(5); ADCres = (ADC_GetConversionValue(ADC1)); ADCres = isZero(ADCres); GPIO_ResetBits(ADC_2_PORT_SIG_MOT, ADC_2_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_2_PORT_SIG_MOT, ADC_2_PIN_SIG_MOT1M); break; case NUM_ADC3: GPIO_SetBits(ADC_3_PORT_SIG_MOT, ADC_3_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_3_PORT_SIG_MOT, ADC_3_PIN_SIG_MOT1M); GPIO_ResetBits(PORT_ADC_SELECT0,PIN_ADC_SELECT0); GPIO_SetBits(PORT_ADC_SELECT1,PIN_ADC_SELECT1); ADC_RegularChannelConfig(ADC1, SIG_ADC_0, 1 , ADC_SampleTime_239Cycles5); uDelay(30); /* Start ADC1,ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC2, ENABLE); uDelay(5); ADCres = (ADC_GetConversionValue(ADC1)); ADCres = isZero(ADCres); GPIO_ResetBits(ADC_3_PORT_SIG_MOT, ADC_3_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_3_PORT_SIG_MOT, ADC_3_PIN_SIG_MOT1M); break; case NUM_ADC4: GPIO_SetBits(ADC_4_PORT_SIG_MOT, ADC_4_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_4_PORT_SIG_MOT, ADC_4_PIN_SIG_MOT1M); GPIO_ResetBits(PORT_ADC_SELECT0,PIN_ADC_SELECT0); GPIO_ResetBits(PORT_ADC_SELECT1,PIN_ADC_SELECT1); ADC_RegularChannelConfig(ADC1, SIG_ADC_1, 1 , ADC_SampleTime_239Cycles5); uDelay(30); /* Start ADC1,ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC2, ENABLE); uDelay(5); ADCres = (ADC_GetConversionValue(ADC1)); ADCres = isZero(ADCres); GPIO_ResetBits(ADC_4_PORT_SIG_MOT, ADC_4_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_4_PORT_SIG_MOT, ADC_4_PIN_SIG_MOT1M); break; case NUM_ADC5: GPIO_SetBits(ADC_5_PORT_SIG_MOT, ADC_5_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_5_PORT_SIG_MOT, ADC_5_PIN_SIG_MOT1M); GPIO_SetBits(PORT_ADC_SELECT0,PIN_ADC_SELECT0); GPIO_ResetBits(PORT_ADC_SELECT1,PIN_ADC_SELECT1); ADC_RegularChannelConfig(ADC1, SIG_ADC_1, 1 , ADC_SampleTime_239Cycles5); uDelay(30); /* Start ADC1,ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC2, ENABLE); uDelay(5); ADCres = (ADC_GetConversionValue(ADC1)); ADCres = isZero(ADCres); //GPIO_ResetBits(ADC_5_PORT_SIG_MOT, ADC_5_PIN_SIG_MOT1P); //GPIO_ResetBits(ADC_5_PORT_SIG_MOT, ADC_5_PIN_SIG_MOT1M); break; case NUM_ADC6: GPIO_SetBits(ADC_6_PORT_SIG_MOT, ADC_6_PIN_SIG_MOT1P); GPIO_ResetBits(ADC_6_PORT_SIG_MOT, ADC_6_PIN_SIG_MOT1M); GPIO_ResetBits(PORT_ADC_SELECT0,PIN_ADC_SELECT0); GPIO_SetBits(PORT_ADC_SELECT1,PIN_ADC_SELECT1); ADC_RegularChannelConfig(ADC1, SIG_ADC_1, 1 , ADC_SampleTime_239Cycles5); uDelay(30); /* Start ADC1,ADC2 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); //ADC_SoftwareStartConvCmd(ADC2, ENABLE); uDelay(7); ADCres = (ADC_GetConversionValue(ADC1)); // if(ADCres>1023) // { // ADCres = MAX_SPEED; // } // GPIO_ResetBits(ADC_6_PORT_SIG_MOT, ADC_6_PIN_SIG_MOT1P); // GPIO_ResetBits(ADC_6_PORT_SIG_MOT, ADC_6_PIN_SIG_MOT1M); break; default: break; } return ADCres; }
void CheckICInsert(void) { unsigned char write_flag=0; u8 result0=0,result1=0,result2=0,result3=0,result4=0,result5=0;//i=0; u8 FLagx=0;//,len=0; unsigned char reg_record[32]; u32 DriveCode32=0; //===================测试IC卡读写================================================== if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7)) { IC_Check_Count++; if(IC_Check_Count>=10) { IC_Check_Count=0; //带卡上电开8024的电 if(flag_8024off==1) { R_Flag|=b_CardEdge; Init8024Flag=2; flag_8024off=0; } //8024的off从低变高 if(Init8024Flag==1) { Init8024Flag=2; R_Flag|=b_CardEdge; //rt_kprintf("pc7 为 高,R_Flag=1\r\n"); } //检测到卡后初始化ic卡 if((R_Flag&b_CardEdge)&&(Init8024Flag==2)) { Init8024Flag=3; _CardCMDVCC_LOW; for(DelayCheckIc=0; DelayCheckIc<500; DelayCheckIc++) DELAY5us(); _CardSetPower_HIGH; _CardSetRST_LOW; for(DelayCheckIc=0; DelayCheckIc<15; DelayCheckIc++) { _CardSetCLK_LOW; DELAY5us(); DELAY5us(); DELAY5us(); _CardSetCLK_HIGH; DELAY5us(); DELAY5us(); DELAY5us(); _CardSetCLK_LOW; } R_Flag&=~b_CardEdge; write_flag=1; //rt_kprintf("只执行1次\r\n"); } } } else { IC_Check_Count=0; _CardSetRST_HIGH; _CardSetPower_LOW; _CardCMDVCC_HIGH; if(Init8024Flag==0) { Init8024Flag=1; //rt_kprintf("pc7 为 低\r\n"); } } if(write_flag==1) { write_flag=0; Rx_4442(241,13,reg_record); //管理员卡 if(strncmp((char *)reg_record,"administrator",13)==0) { rt_kprintf("\r\n管理员卡"); administrator_card=1; } else { memset(DriverCardNUM,0,sizeof(DriverCardNUM)); memset(DriverName,0,sizeof(DriverName)); //memset(JT808Conf_struct.Driver_Info,0,sizeof(JT808Conf_struct.Driver_Info)); result0=Rx_4442(70,10,(unsigned char *)DriverName); //读驾驶员姓名 rt_kprintf("\r\n驾驶员姓名:%s,result0=%d",DriverName,result0); result1=Rx_4442(52,18,(unsigned char *)DriverCardNUM); //读驾驶证号码 rt_kprintf("\r\n驾驶证代码:%s,result1=%d",DriverCardNUM,result1); memset(JT808Conf_struct.Driver_Info.DriveCode,0,sizeof(JT808Conf_struct.Driver_Info.DriveCode)); result2=Rx_4442(49,3,(unsigned char *)JT808Conf_struct.Driver_Info.DriveCode); //读驾驶员代码 DriveCode32=(JT808Conf_struct.Driver_Info.DriveCode[0]<<16)+(JT808Conf_struct.Driver_Info.DriveCode[1]<<8)+JT808Conf_struct.Driver_Info.DriveCode[2]; rt_kprintf("\r\n驾驶员代码:%d,result2=%d",DriveCode32,result2); memset(JT808Conf_struct.Driver_Info.Driver_ID,0,sizeof(JT808Conf_struct.Driver_Info.Driver_ID)); result3=Rx_4442(80,20,(unsigned char *)JT808Conf_struct.Driver_Info.Driver_ID); //身份证号码 rt_kprintf("\r\n身份证号码:%s,result3=%d",JT808Conf_struct.Driver_Info.Driver_ID,result3); memset(JT808Conf_struct.Driver_Info.Drv_CareerID,0,sizeof(JT808Conf_struct.Driver_Info.Drv_CareerID)); result4=Rx_4442(100,40,(unsigned char *)JT808Conf_struct.Driver_Info.Drv_CareerID); //从业资格证 rt_kprintf("\r\n从业资格证:%s,result4=%d",JT808Conf_struct.Driver_Info.Drv_CareerID,result4); memset(JT808Conf_struct.Driver_Info.Comfirm_agentID,0,sizeof(JT808Conf_struct.Driver_Info.Comfirm_agentID)); result5=Rx_4442(140,41,(unsigned char *)institution); //发证机构 memcpy(JT808Conf_struct.Driver_Info.Comfirm_agentID,&institution[1],40); rt_kprintf("\r\n发证机构:%s,result5=%d",JT808Conf_struct.Driver_Info.Comfirm_agentID,result5); if((result0==0)&&(result1==0)&&(result2==0)&&(result3==0)&&(result4==0)&&(result5==0))//读结果正确 { IC_CardInsert=1;//IC 卡插入正确 FLagx=0; //前18位为驾驶证号码-------------疲劳驾驶相关------看是否更换了卡 -------------- if(strncmp((char*)DriverCardNUM,(char*)JT808Conf_struct.Driver_Info.DriverCard_ID,18)!=0) { memset(JT808Conf_struct.Driver_Info.DriverCard_ID,0,sizeof(JT808Conf_struct.Driver_Info.DriverCard_ID)); memcpy(JT808Conf_struct.Driver_Info.DriverCard_ID,DriverCardNUM,18); FLagx=1; } //后20位为驾驶员姓名-------------疲劳驾驶相关------看是否更换了卡 -------------- if(strncmp((char*)DriverName,(char*)JT808Conf_struct.Driver_Info.DriveName,20)!=0) { memset(JT808Conf_struct.Driver_Info.DriveName,0,sizeof(JT808Conf_struct.Driver_Info.DriveName)); memcpy((u8*)JT808Conf_struct.Driver_Info.DriveName,DriverName,strlen((const char*)DriverName)); FLagx=2; } if(FLagx)//更换了IC 卡 清除疲劳驾驶相关 { TIRED_Drive_Init(); //清除疲劳驾驶的状态 GPIO_ResetBits(Buzzer_IO_Group,Buzzer_Group_Num); // 关闭蜂鸣器 Api_Config_Recwrite_Large(jt808,0,(u8*)&JT808Conf_struct,sizeof(JT808Conf_struct)); FLagx=0;//clear } BuzzerFlag=1;//响一声提示 pMenuItem=&Menu_2_5_DriverInfor; pMenuItem->show(); } else { BuzzerFlag=11;//响一声提示 IC_CardInsert=2;//IC 卡插入错误 } } Init8024Flag=0; GpsIo_Init(); } //===================测试IC卡读写完成================================================== }
void codec_init() { GPIO_InitTypeDef PinInitStruct; GPIO_StructInit(&PinInitStruct); I2S_InitTypeDef I2S_InitType; I2C_InitTypeDef I2C_InitType; //Reset pin as GPIO PinInitStruct.GPIO_Pin = CODEC_RESET_PIN; PinInitStruct.GPIO_Mode = GPIO_Mode_OUT; PinInitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; PinInitStruct.GPIO_OType = GPIO_OType_PP; PinInitStruct.GPIO_Speed = GPIO_Speed_50MHz; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOB, ENABLE); GPIO_Init(GPIOD, &PinInitStruct); // I2C pins PinInitStruct.GPIO_Mode = GPIO_Mode_AF; PinInitStruct.GPIO_OType = GPIO_OType_OD; PinInitStruct.GPIO_Pin = I2C_SCL_PIN | I2C_SDA_PIN; PinInitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; PinInitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &PinInitStruct); GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1); GPIO_PinAFConfig(GPIOB, GPIO_PinSource9, GPIO_AF_I2C1); //enable I2S and I2C clocks //RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 | RCC_APB1Periph_SPI3, ENABLE); RCC_PLLI2SCmd(ENABLE); // I2S pins PinInitStruct.GPIO_OType = GPIO_OType_PP; PinInitStruct.GPIO_Pin = I2S3_SCLK_PIN | I2S3_SD_PIN | I2S3_MCLK_PIN; GPIO_Init(GPIOC, &PinInitStruct); PinInitStruct.GPIO_Pin = I2S3_WS_PIN; GPIO_Init(GPIOA, &PinInitStruct); //prepare output ports for alternate function GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3); //keep Codec off for now GPIO_ResetBits(GPIOD, CODEC_RESET_PIN); // configure I2S port SPI_I2S_DeInit(CODEC_I2S); I2S_InitType.I2S_AudioFreq = 24000;//12000//Normal 10000 I2S_InitType.I2S_MCLKOutput = I2S_MCLKOutput_Enable; I2S_InitType.I2S_DataFormat = I2S_DataFormat_16b; I2S_InitType.I2S_Mode = I2S_Mode_MasterTx; I2S_InitType.I2S_Standard = I2S_Standard_Phillips; I2S_InitType.I2S_CPOL = I2S_CPOL_Low; I2S_Init(CODEC_I2S, &I2S_InitType); //I2S_Cmd(CODEC_I2S, ENABLE); // configure I2C port I2C_DeInit(CODEC_I2C); I2C_InitType.I2C_ClockSpeed = 100000; I2C_InitType.I2C_Mode = I2C_Mode_I2C; I2C_InitType.I2C_OwnAddress1 = CORE_I2C_ADDRESS; I2C_InitType.I2C_Ack = I2C_Ack_Enable; I2C_InitType.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitType.I2C_DutyCycle = I2C_DutyCycle_2; I2C_Cmd(CODEC_I2C, ENABLE); I2C_Init(CODEC_I2C, &I2C_InitType); }
void led_off(uint16_t led) { GPIO_ResetBits(GPIOB, led); }
void LED_OFF(){ for(i=0;i<led_num;++i) { GPIO_ResetBits(LED,led[i]); } }
int main(void) { SystemInit(); // Init SysTick. SystemCoreClockUpdate(); if (SysTick_Config(SystemCoreClock / 1000) != 0) { /* Capture error */ while (1); } /* ----------------------------------------------- */ /* "Normal" Enumerator Usage */ // Usage of Mode enumeration: enum Mode mode0 = OUT; enum Mode mode1 = IN; enum Mode mode3 = 0x03; // Same as AN. int mode_var = OUT; // Same as 0x01. enum Mode mode4 = mode_var; // Same as OUT. enum Mode mode5 = 0x0A; // Not a valid Mode, but a valid cast. /* ----------------------------------------------- */ /* "Mixed" Enumerator Usage */ enum Mode mode6 = NOPULL; // Mode variable gets a PuPd value. enum PuPd pupd0 = OUT; // PuPd variable gets a Mode value. /* ----------------------------------------------- */ /* Variable Names: */ int OUT = DOWN; // OUT == 2 enum Mode mode7 = OUT; // mode7 ?= OUT or AF. // Mode_TypeDef mode6 = AN; // Mode_TypeDef mode7 = IN; // Mode_TypeDef mode8 = 0x0B; // Not a valid Mode. // Mode_TypeDef mode9 = 0x0C; // Not a valid Mode. // Enable the GPIOE Clock. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE); // Initialize GPIOE.9 as output (pin is connected to LED3): GPIO_InitTypeDef InitStructure; InitStructure.GPIO_Mode = GPIO_Mode_OUT; InitStructure.GPIO_OType = GPIO_OType_PP; InitStructure.GPIO_PuPd = GPIO_PuPd_UP; InitStructure.GPIO_Speed = GPIO_Speed_50MHz; InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_Init(GPIOE, &InitStructure); while(1) { GPIO_SetBits(GPIOE, GPIO_Pin_9); Delay(500); GPIO_ResetBits(GPIOE, GPIO_Pin_9); Delay(200); } }
//------------------------------------------------------------------ void GPS_ANTENNA_status(void) // 天线开短路状态检测 { // 2013-4-20 更改PCB 用PD4 : GPS 天线开路 PB6 : GPS 天线短路 if(GPIO_ReadOutputDataBit(GPS_PWR_PORT, GPS_PWR_PIN )) // 在GPS 有电时有效 { if(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_4))//开路检测 1:天线开路 { if(OutGPS_Flag==0) { if((Warn_Status[3]&0x20)==0) rt_kprintf("\r\n 检测到 天线开路"); Warn_Status[3]|=0x20; Warn_Status[3]&=~0x40; GpsStatus.Antenna_Flag=1; Gps_Exception.GPS_circuit_short_couter=0; } } else if(!GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_6))//短路检测 0:天线短路 { if(( Warn_Status[3]&0x40)==0) { Gps_Exception.GPS_short_keepTimer++; if( Gps_Exception.GPS_short_keepTimer>200) { Gps_Exception.GPS_short_keepTimer=0; // clear rt_kprintf("\r\n 检测到 天线短路"); rt_kprintf("\r\n 发现短路,立即断开GPS电源"); GPIO_ResetBits( GPS_PWR_PORT, GPS_PWR_PIN ); //------------------------------------------ Gps_Exception.GPS_circuit_short_couter++; if(Gps_Exception.GPS_circuit_short_couter>=4) { Gps_Exception.GPS_short_checkFlag=2; Gps_Exception.GPS_short_timer=0; // clear rt_kprintf("\r\n 短路检测大于3次 ,一直断开GPS 电源\r\n"); // 断开 GPS 电源后,得启动 本地定时 ,否则人家说丢包.NND /* */ } else { Gps_Exception.GPS_short_checkFlag=1; } //----------------------------------------------------- // set flag Warn_Status[3]&=~0x20; Warn_Status[3]|=0x40; //------------------------------------------ } } } else { if(Warn_Status[3]&0x20) rt_kprintf("\r\n 检测到 天线恢复正常"); Warn_Status[3]&=~0x20; Warn_Status[3]&=~0x40; GpsStatus.Antenna_Flag=0; Gps_Exception.GPS_circuit_short_couter=0; } } }
/*初始化*/ static rt_err_t dev_gps_init( rt_device_t dev ) { GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC, ENABLE ); RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOD, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART5, ENABLE ); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPS_PWR_PIN; GPIO_Init( GPS_PWR_PORT, &GPIO_InitStructure ); GPIO_ResetBits( GPS_PWR_PORT, GPS_PWR_PIN ); if(Module_3017A!=GPS_MODULE_TYPE) { //#ifdef HC_595_CONTROL // 2013-4-20 更改PCB 用PD4 : GPS 天线开路 PB6 : GPS 天线短路 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; // IN //------------------- PD4 ----------------------------- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //GPS 天线开路 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(GPIOD, &GPIO_InitStructure); //------------------- PB6 ----------------------------- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; //GPS 天线短路 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_Init(GPIOB, &GPIO_InitStructure); //#endif } /*uart5 管脚设置*/ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_Init( GPIOC, &GPIO_InitStructure ); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_Init( GPIOD, &GPIO_InitStructure ); GPIO_PinAFConfig( GPIOC, GPIO_PinSource12, GPIO_AF_UART5 ); GPIO_PinAFConfig( GPIOD, GPIO_PinSource2, GPIO_AF_UART5 ); /*NVIC 设置*/ NVIC_InitStructure.NVIC_IRQChannel = UART5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( &NVIC_InitStructure ); gps_baud( 9600 ); USART_Cmd( UART5, ENABLE ); USART_ITConfig( UART5, USART_IT_RXNE, ENABLE ); GPIO_ResetBits( GPIOD, GPIO_Pin_10 ); return RT_EOK; }
/*********************************************************** * Function: * Description: * Input: * Input: * Output: * Return: * Others: ***********************************************************/ static rt_err_t dev_gps_close( rt_device_t dev ) { GPIO_ResetBits( GPS_PWR_PORT, GPS_PWR_PIN ); return RT_EOK; }
void nRF24L01_SPI_NSS_L(void){ GPIO_ResetBits(GPIOB,GPIO_Pin_12); }
void setup_gpio(){ #if isUsingDevBoard /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOI, ENABLE); /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */ GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOH, &GPIO_InitStructure); /* Connect PXx to USARTx_Tx*/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_UART4); /* Connect PXx to USARTx_Rx*/ GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_UART4); /* Configure USART Tx as alternate function */ GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART Rx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure DAC GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; //DAC Channel 1, A4 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); //Configure ADC GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOC, &GPIO_InitStructure); //configure SPI for LCD GPIO_PinAFConfig(GPIOI, GPIO_PinSource1, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOI, GPIO_PinSource3, GPIO_AF_SPI2); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOI, &GPIO_InitStructure); //configure other pins for LCD //Set the parallel/serial pin GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_ResetBits(GPIOF, GPIO_Pin_15); //Sets LCD screen to operate in serial //set CS1 pin GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_SetBits(GPIOG, GPIO_Pin_1); //Set A0 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_Init(GPIOF, &GPIO_InitStructure); //Set Reset GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_SetBits(GPIOG, GPIO_Pin_0); #else #endif }
/** * \fn initCAN * \brief initialize the can interface * * \param[in] app_rx_funktion pointer to callback function * \return None */ void initCAN(CANRxCatch_t app_rx_funktion) { /* variable for CAN init */ GPIO_InitTypeDef CAN_gpio; CAN_InitTypeDef CAN_InitStructure; CAN_FilterInitTypeDef CAN_FilterInitStructure; uint8_t filter_count; /* pins configuration */ CAN_gpio.GPIO_Pin = CAN_PIN_TX | CAN_PIN_RX; CAN_gpio.GPIO_Mode = CAN_PINS_MODE; CAN_gpio.GPIO_OType = CAN_PINS_TYPE; CAN_gpio.GPIO_Speed = CAN_PINS_SPEED; CAN_gpio.GPIO_PuPd = CAN_PINS_PUPD; /* enable the CAN-interface interrupt */ rx_function = app_rx_funktion; initCANInterrupt(CAN_INTERFACE); /* Enable GPIO clock */ RCC_AHB1PeriphClockCmd(CAN_PORT_RCC,ENABLE); #if defined(CAN_PIN_EN_NUMBER) && defined(CAN_EN_PORT_LETTER) && defined(CAN_PIN_EN_MODE) && defined(CAN_LEVEL_ACTIVE) RCC_AHB1PeriphClockCmd(CAN_EN_PORT_RCC,ENABLE); /* EN Pin */ #endif /* Enable CAN clock */ RCC_APB1PeriphClockCmd(CAN_PIN_RCC, ENABLE); /* Connect PXx to CANTx_Tx*/ GPIO_PinAFConfig(CAN_PORT, CAN_PIN_TX_SOURCE, CAN_PIN_AF); /* Connect PXx to CANRx_Rx*/ GPIO_PinAFConfig(CAN_PORT, CAN_PIN_RX_SOURCE, CAN_PIN_AF); /* Init Tx- and Rx-pins */ GPIO_Init(CAN_PORT,&CAN_gpio); /* CAN EN Pin */ #if defined(CAN_PIN_EN_NUMBER) && defined(CAN_EN_PORT_LETTER) && defined(CAN_PIN_EN_MODE) && defined(CAN_LEVEL_ACTIVE) CAN_gpio.GPIO_Pin = CAN_PIN_EN; CAN_gpio.GPIO_Mode = CAN_PIN_EN_MODE; GPIO_Init( CAN_EN_PORT, &CAN_gpio ); #if CAN_LEVEL_ACTIVE == 'L' GPIO_ResetBits(CAN_EN_PORT,CAN_PIN_EN); /* set the RS pin of the CAN-transceiver to low -> no sleep-mode */ #else GPIO_SetBits(CAN_EN_PORT,CAN_PIN_EN); /* set the RS pin of the CAN-transceiver to low -> no sleep-mode */ #endif #endif /* CAN register reset */ CAN_DeInit(CAN_INTERFACE); /* CAN cell init */ CAN_InitStructure.CAN_TTCM = DISABLE; /* Time Triggered Communication Mode */ CAN_InitStructure.CAN_ABOM = DISABLE; /* Automatic Bus-Off Management */ CAN_InitStructure.CAN_AWUM = DISABLE; /* Automatic Wakeup Mode */ CAN_InitStructure.CAN_NART = ENABLE; /* No Automatic Retransmission */ CAN_InitStructure.CAN_RFLM = DISABLE; /* Receive FIFO Locked Mode */ CAN_InitStructure.CAN_TXFP = DISABLE; /* Transmit FIFO Priority */ CAN_InitStructure.CAN_Mode = CAN_Mode_Normal; CAN_InitStructure.CAN_SJW = CAN_SJW_1tq; /* CAN Baudrate */ CAN_InitStructure.CAN_BS1 = CAN_TIME_BS1; CAN_InitStructure.CAN_BS2 = CAN_TIME_BS2; CAN_InitStructure.CAN_Prescaler = CAN_PRESCALER; CAN_Init(CAN_INTERFACE, &CAN_InitStructure); /* CAN filter init */ for(filter_count = 0; filter_count < filter_bank_number + 1; filter_count++) { CAN_FilterInitStructure.CAN_FilterNumber = filter_count; CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdList; CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit; CAN_FilterInitStructure.CAN_FilterFIFOAssignment = 0; CAN_FilterInitStructure.CAN_FilterActivation = ENABLE; CAN_FilterInitStructure.CAN_FilterIdLow = filter_bank[filter_count][0]; /* lower 16bit CAN_FxR1 */ CAN_FilterInitStructure.CAN_FilterMaskIdLow = filter_bank[filter_count][1]; /* upper 16bit CAN_FxR1 */ CAN_FilterInitStructure.CAN_FilterIdHigh = filter_bank[filter_count][2]; /* lower 16bit CAN_FxR2 */ CAN_FilterInitStructure.CAN_FilterMaskIdHigh = filter_bank[filter_count][3]; /* upper 16bit CAN_FxR2 */ CAN_FilterInit(&CAN_FilterInitStructure); } /* Enable FIFO 0 message pending Interrupt */ CAN_ITConfig(CAN_INTERFACE, CAN_IT_FMP0, ENABLE); }
void ANO_SPI2::CE_L(void) { GPIO_ResetBits(ANO_GPIO_CE2, SPI2_Pin_CE2); }
int main(void) { #if defined(DEBUG) /* * Send a greeting to the standard output (the semi-hosting debug channel * on Debug, ignored on Release). */ printf("Hello ARM World!\n"); #endif /* * At this stage the microcontroller clock setting is already configured, * this is done through SystemInit() function which is called from startup * file (startup_cm.c) before to branch to application main. * To reconfigure the default setting of SystemInit() function, refer to * system_stm32f10x.c file */ /* Use SysTick as reference for the timer */ SysTick_Config(SystemCoreClock / SYSTICK_FREQUENCY_HZ); /* GPIO Periph clock enable for LED */ RCC_AHBPeriphClockCmd(LD_GPIO_PORT_CLK, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; /* Configure the GPIO_LED pins LD3 & LD4*/ GPIO_InitStructure.GPIO_Pin = LD_GREEN_GPIO_PIN | LD_BLUE_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(LD_GPIO_PORT, &GPIO_InitStructure); GPIO_ResetBits(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); GPIO_ResetBits(LD_GPIO_PORT, LD_BLUE_GPIO_PIN); /* GPIO Periph clock enable for MCO */ RCC_AHBPeriphClockCmd(MCO_GPIO_PORT_CLK, ENABLE); GPIO_InitStructure.GPIO_Pin = MCO_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz; GPIO_Init(MCO_GPIO_PORT, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_MCO); RCC_MCOConfig(RCC_MCOSource_SYSCLK , RCC_MCODiv_8); int seconds = 0; /* Infinite loop */ while (1) { /* Assume the LED is active low */ /* Turn on led by setting the pin low */ GPIO_ResetBits(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); Delay(BLINK_TICKS); /* Turn off led by setting the pin high */ GPIO_SetBits(LD_GPIO_PORT, LD_GREEN_GPIO_PIN); Delay(BLINK_TICKS); ++seconds; #if defined(DEBUG) /* * Count seconds on the debug channel. */ printf("Second %d\n", seconds); #endif } }
void ANO_SPI2::CSN_L(void) { GPIO_ResetBits(ANO_GPIO_SPI2, SPI2_Pin_CSN); }
/************************************************************* * GPIOB Initialization **************************************************************/ void GPIOB_Init() { #if(STRCMP($pin0Used$, DISABLE) == 0 || STRCMP($pin1Used$, DISABLE) == 0 || STRCMP($pin2Used$, DISABLE)== 0 ||\ STRCMP($pin3Used$, DISABLE) == 0 || STRCMP($pin4Used$, DISABLE) == 0 || STRCMP($pin5Used$, DISABLE)== 0 || \ STRCMP($pin6Used$, DISABLE) == 0 || STRCMP($pin7Used$, DISABLE) == 0 || STRCMP($pin8Used$, DISABLE)== 0 || \ STRCMP($pin9Used$, DISABLE) == 0 || STRCMP($pin10Used$, DISABLE) == 0 || STRCMP($pin11Used$, DISABLE)== 0 || \ STRCMP($pin12Used$, DISABLE) == 0 || STRCMP($pin13Used$, DISABLE) == 0 || STRCMP($pin14Used$, DISABLE)== 0 || \ STRCMP($pin15Used$, DISABLE) == 0) GPIO_InitTypeDef GPIO_InitStructure; #endif #if($pLockEn0$ || $pLockEn1$ || $pLockEn2$ || $pLockEn3$ || \ $pLockEn4$ || $pLockEn5$ || $pLockEn6$ || $pLockEn7$ || \ $pLockEn8$ || $pLockEn9$ || $pLockEn10$ || $pLockEn11$ || \ $pLockEn12$ || $pLockEn13$ || $pLockEn14$ || $pLockEn15$) uint16_t GPIO_LOCK_PIN; // // The locked pins of GPIOB // GPIO_LOCK_PIN = $pLockEn0$ | $pLockEn1$ << 1 | $pLockEn2$ << 2 | $pLockEn3$ << 3 | \ $pLockEn4$ << 4 | $pLockEn5$ << 5 | $pLockEn6$ << 6 | $pLockEn7$ << 7 | \ $pLockEn8$ << 8 | $pLockEn9$ << 9 | $pLockEn10$ << 10 | $pLockEn11$ << 11 |\ $pLockEn12$ << 12 | $pLockEn13$ << 13 | $pLockEn14$ << 14 | $pLockEn15$ << 15; #endif // // Enable GPIOB APB2PeriphClock // RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); #if(STRCMP($pin0Used$, DISABLE) == 0) // // Set PB0 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = $pin0Mode$; GPIO_InitStructure.GPIO_Speed = $pin0Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin0Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin0Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin0Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin0Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData0$, RESET) == 0) // // Set or Reset PB0 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_0); #endif #if(STRCMP($pinData0$, SET) == 0) // // Set or Reset PB0 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_0); #endif #endif #endif #if(STRCMP($pin1Used$, DISABLE) == 0) // // Set PB1 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = $pin1Mode$; GPIO_InitStructure.GPIO_Speed = $pin1Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin1Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin1Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin1Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin1Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData1$, RESET) == 0) // // Set or Reset PB1 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_1); #endif #if(STRCMP($pinData1$, SET) == 0) // // Set or Reset PB1 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_1); #endif #endif #endif #if(STRCMP($pin2Used$, DISABLE) == 0) // // Set PB2 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; GPIO_InitStructure.GPIO_Mode = $pin2Mode$; GPIO_InitStructure.GPIO_Speed = $pin2Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin2Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin2Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin2Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin2Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData2$, RESET) == 0) // // Set or Reset PB2 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_2); #endif #if(STRCMP($pinData2$, SET) == 0) // // Set or Reset PB2 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_2); #endif #endif #endif #if(STRCMP($pin3Used$, DISABLE) == 0) // // Set PB3 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = $pin3Mode$; GPIO_InitStructure.GPIO_Speed = $pin3Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin3Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin3Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin3Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin3Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData3$, RESET) == 0) // // Set or Reset PB3 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_3); #endif #if(STRCMP($pinData3$, SET) == 0) // // Set or Reset PB3 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_3); #endif #endif #endif #if(STRCMP($pin4Used$, DISABLE) == 0) // // Set PB4 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Mode = $pin4Mode$; GPIO_InitStructure.GPIO_Speed = $pin4Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin4Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin4Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin4Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin4Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData4$, RESET) == 0) // // Set or Reset PB4 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_4); #endif #if(STRCMP($pinData4$, SET) == 0) // // Set or Reset PB4 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_4); #endif #endif #endif #if(STRCMP($pin5Used$, DISABLE) == 0) // // Set PB5 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = $pin5Mode$; GPIO_InitStructure.GPIO_Speed = $pin5Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin5Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin5Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin5Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin5Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData5$, RESET) == 0) // // Set or Reset PB5 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_5); #endif #if(STRCMP($pinData5$, SET) == 0) // // Set or Reset PB5 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_5); #endif #endif #endif #if(STRCMP($pin6Used$, DISABLE) == 0) // // Set PB6 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = $pin6Mode$; GPIO_InitStructure.GPIO_Speed = $pin6Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin6Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin6Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin6Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin6Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData6$, RESET) == 0) // // Set or Reset PB6 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_6); #endif #if(STRCMP($pinData6$, SET) == 0) // // Set or Reset PB6 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_6); #endif #endif #endif #if(STRCMP($pin7Used$, DISABLE) == 0) // // Set PB7 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = $pin7Mode$; GPIO_InitStructure.GPIO_Speed = $pin7Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin7Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin7Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin7Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin7Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData7$, RESET) == 0) // // Set or Reset PB7 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_7); #endif #if(STRCMP($pinData7$, SET) == 0) // // Set or Reset PB7 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_7); #endif #endif #endif #if(STRCMP($pin8Used$, DISABLE) == 0) // // Set PB8 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = $pin8Mode$; GPIO_InitStructure.GPIO_Speed = $pin8Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin8Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin8Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin8Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin8Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData8$, RESET) == 0) // // Set or Reset PB8 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_8); #endif #if(STRCMP($pinData8$, SET) == 0) // // Set or Reset PB8 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_8); #endif #endif #endif #if(STRCMP($pin9Used$, DISABLE) == 0) // // Set PB9 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = $pin9Mode$; GPIO_InitStructure.GPIO_Speed = $pin9Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin9Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin9Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin9Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin9Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData9$, RESET) == 0) // // Set or Reset PB9 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_9); #endif #if(STRCMP($pinData9$, SET) == 0) // // Set or Reset PB9 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_9); #endif #endif #endif #if(STRCMP($pin10Used$, DISABLE) == 0) // // Set PB10 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = $pin10Mode$; GPIO_InitStructure.GPIO_Speed = $pin10Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin10Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin10Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin10Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin10Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData10$, RESET) == 0) // // Set or Reset PB10 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_10); #endif #if(STRCMP($pinData10$, SET) == 0) // // Set or Reset PB10 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_10); #endif #endif #endif #if(STRCMP($pin11Used$, DISABLE) == 0) // // Set PB11 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = $pin11Mode$; GPIO_InitStructure.GPIO_Speed = $pin11Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin11Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin11Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin11Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin11Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData11$, RESET) == 0) // // Set or Reset PB11 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_11); #endif #if(STRCMP($pinData11$, SET) == 0) // // Set or Reset PB11 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_11); #endif #endif #endif #if(STRCMP($pin12Used$, DISABLE) == 0) // // Set PB12 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = $pin12Mode$; GPIO_InitStructure.GPIO_Speed = $pin12Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin12Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin12Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin12Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin12Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData12$, RESET) == 0) // // Set or Reset PB12 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_12); #endif #if(STRCMP($pinData12$, SET) == 0) // // Set or Reset PB12 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_12); #endif #endif #endif #if(STRCMP($pin13Used$, DISABLE) == 0) // // Set PB13 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = $pin13Mode$; GPIO_InitStructure.GPIO_Speed = $pin13Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin13Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin13Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin13Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin13Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData13$, RESET) == 0) // // Set or Reset PB13 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_13); #endif #if(STRCMP($pinData13$, SET) == 0) // // Set or Reset PB13 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_13); #endif #endif #endif #if(STRCMP($pin14Used$, DISABLE) == 0) // // Set PB14 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = $pin14Mode$; GPIO_InitStructure.GPIO_Speed = $pin14Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin14Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin14Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin14Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin14Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData14$, RESET) == 0) // // Set or Reset PB14 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_14); #endif #if(STRCMP($pinData14$, SET) == 0) // // Set or Reset PB14 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_14); #endif #endif #endif #if(STRCMP($pin15Used$, DISABLE) == 0) // // Set PB15 Pin Mode // GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = $pin15Mode$; GPIO_InitStructure.GPIO_Speed = $pin15Speed$; GPIO_Init(GPIOB, &GPIO_InitStructure); #if(STRCMP($pin15Mode$, GPIO_Mode_Out_OD) != 0 || STRCMP($pin15Mode$, GPIO_Mode_Out_PP) != 0 || \ STRCMP($pin15Mode$, GPIO_Mode_AF_OD) != 0 || STRCMP($pin15Mode$, GPIO_Mode_AF_PP) != 0) #if(STRCMP($pinData15$, RESET) == 0) // // Set or Reset PB15 bits of output data // GPIO_SetBits(GPIOB, GPIO_Pin_15); #endif #if(STRCMP($pinData15$, SET) == 0) // // Set or Reset PB15 bits of output data // GPIO_ResetBits(GPIOB, GPIO_Pin_15); #endif #endif #endif #if($pLockEn0$ | $pLockEn1$ | $pLockEn2$ | $pLockEn3$ | \ $pLockEn4$ | $pLockEn5$ | $pLockEn6$ | $pLockEn7$ | \ $pLockEn8$ | $pLockEn9$ | $pLockEn10$ | $pLockEn11$ | \ $pLockEn12$ | $pLockEn13$ | $pLockEn14$ | $pLockEn15$) //PUT_A_NEW_LINE_HERE // // Lock configuration of GPIO pins. // GPIO_PinLockConfig($GPIO_PORT$, GPIO_LOCK_PIN); #endif }
void ThreadSPIXCallback (void const *argument) { uint8_t u8Data = 0, u8ExtData = 0; // End of TX part. //============================================================================== // Recovery NSS after sent data. if(u8Nss1Low == 0) { //============================================================================== // Send cmd first then data if(IS_DATA_EXIST(SPI1_TXCmdBuffer)) { if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == SET) //If it's free to send data. { GET_EXT(SPI1_TXCmdBuffer, u8Data, u8ExtData); // Get data from ring buffer. switch(u8ExtData) { case SPI1_CMD_PIN: GPIO_ResetBits(GPIOA, GPIO_Pin_8);// PA8:D/C command = 0 break; case SPI1_NRF24CSN_PIN: GPIO_ResetBits(GPIOC, GPIO_Pin_4);// PC4: NRF24L01 CSN = 0 default: GPIO_SetBits(GPIOA, GPIO_Pin_8);// PA8:D/C data = 1 break; } GPIO_ResetBits(GPIOA, GPIO_Pin_4); // PA4:Turn on NSS.--> Normal high, active low. SPI_I2S_SendData(SPI1, u8Data); // Send data u8Nss1Low = 1; } } } else { if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_BSY) == RESET) //If it's free to send data. { GPIO_SetBits(GPIOA, GPIO_Pin_4); u8Nss1Low = 0; } } //============================================================================== // Recovery NSS after sent data. if(u8Nss2Low == 0) { //============================================================================== // Send cmd first then data if(IS_DATA_EXIST(SPI2_TXCmdBuffer)) { if(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == SET) //If it's free to send data. { GET_EXT(SPI2_TXCmdBuffer, u8Data, u8ExtData); // Get data from ring buffer. switch(u8ExtData) { case SPI2_CMD_PIN: GPIO_ResetBits(GPIOB, GPIO_Pin_10);// PA10:D/C command = 0 break; default: GPIO_SetBits(GPIOB, GPIO_Pin_10);// PA10:D/C data = 1 break; } GPIO_ResetBits(GPIOB, GPIO_Pin_12); // PA12:Turn on NSS.--> Normal high, active low. SPI_I2S_SendData(SPI2, u8Data); // Send data u8Nss2Low = 1; } } } else { if(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == RESET) //If it's free to send data. { GPIO_SetBits(GPIOB, GPIO_Pin_12); u8Nss2Low = 0; } } //============================================================================== // Get data if(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == SET) //If there is data need to received. { u8Data = SPI_I2S_ReceiveData(SPI1); PUT(SPI1_RXBuffer, u8Data); } if(SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == SET) //If there is data need to received. { u8Data = SPI_I2S_ReceiveData(SPI2); PUT(SPI2_RXBuffer, u8Data); } }