/** * @brief Main program * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); #ifndef USE_STM3210C_EVAL /* Initialize JoyStick Button mounted on STM3210X-EVAL board */ STM_EVAL_PBInit(Button_UP, Mode_GPIO); STM_EVAL_PBInit(Button_DOWN, Mode_GPIO); STM_EVAL_PBInit(Button_LEFT, Mode_GPIO); STM_EVAL_PBInit(Button_RIGHT, Mode_GPIO); STM_EVAL_PBInit(Button_SEL, Mode_GPIO); #else /* Configure the IO Expander */ if (IOE_Config()) { /* IO Expander config error */ while(1); } #endif /* 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_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; /* Configure the USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Set the USARTy prescaler */ USART_SetPrescaler(USARTy, 0x1); /* Configure the USARTy IrDA mode */ USART_IrDAConfig(USARTy, USART_IrDAMode_Normal); /* Enable the USARTy IrDA mode */ USART_IrDACmd(USARTy, ENABLE); while (1) { /* Read Key */ MyKey = ReadKey(); switch(MyKey) { case JOY_UP: USART_SendData(USARTy, JOY_UP); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_DOWN: USART_SendData(USARTy, JOY_DOWN); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_LEFT: USART_SendData(USARTy, JOY_LEFT); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_RIGHT: USART_SendData(USARTy, JOY_RIGHT); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_CENTER: USART_SendData(USARTy, JOY_CENTER); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; case JOY_NONE: USART_SendData(USARTy, JOY_NONE); while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } break; default: break; } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* TIM1 and Timers(TIM3 and TIM4) synchronisation in parallel mode ----------- 1/TIM1 is configured as Master Timer: - PWM Mode is used - The TIM1 Update event is used as Trigger Output 2/TIM3 and TIM4 are slaves for TIM1, - PWM Mode is used - The ITR0(TIM1) is used as input trigger for both slaves - Gated mode is used, so starts and stops of slaves counters are controlled by the Master trigger output signal(update event). o For Low-density, Medium-density, High-density and Connectivity line devices: The TIMxCLK is fixed to 72 MHz, Prescaler = 0 so the TIM1 counter clock is 72 MHz. The Master Timer TIM1 is running at: TIM1 frequency = TIM1 counter clock / (TIM1_Period + 1) = 281.250 KHz and the duty cycle is equal to: TIM1_CCR1/(TIM1_ARR + 1) = 50% The TIM3 is running at: (TIM1 frequency)/ ((TIM3 period +1)* (Repetion_Counter+1)) = 18.750 KHz and a duty cycle equal to TIM3_CCR1/(TIM3_ARR + 1) = 33.3% The TIM4 is running at: (TIM1 frequency)/ ((TIM4 period +1)* (Repetion_Counter+1)) = 28.125 KHz and a duty cycle equal to TIM4_CCR1/(TIM4_ARR + 1) = 50% o For Low-Density Value line and Medium-Density Value line devices: The TIMxCLK is fixed to 24 MHz, Prescaler = 0 so the TIM1 counter clock is 24 MHz. TIM1 frequency = 93.75 KHz TIM3 frequency = 6.25 KHz TIM4 frequency = 9.375 KHz --------------------------------------------------------------------------- */ /* TIM3 Peripheral Configuration ----------------------------------------*/ /* TIM3 Slave Configuration: PWM1 Mode */ TIM_TimeBaseStructure.TIM_Period = 2; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 1; TIM_OC1Init(TIM3, &TIM_OCInitStructure); /* Slave Mode selection: TIM3 */ TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Gated); TIM_SelectInputTrigger(TIM3, TIM_TS_ITR0); /* TIM4 Peripheral Configuration ----------------------------------------*/ /* TIM4 Slave Configuration: PWM1 Mode */ TIM_TimeBaseStructure.TIM_Period = 1; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 1; TIM_OC1Init(TIM4, &TIM_OCInitStructure); /* Slave Mode selection: TIM4 */ TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Gated); TIM_SelectInputTrigger(TIM4, TIM_TS_ITR0); /* TIM1 Peripheral Configuration ----------------------------------------*/ /* Time Base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 255; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 4; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* Channel 1 Configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = 127; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OC1Init(TIM1, &TIM_OCInitStructure); /* Automatic Output enable, Break, dead time and lock configuration*/ TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1; TIM_BDTRInitStructure.TIM_DeadTime = 5; TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable; TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_High; TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable; TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure); /* Master Mode selection */ TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Update); /* Select the Master Slave Mode */ TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable); /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); /* TIM enable counter */ TIM_Cmd(TIM3, ENABLE); TIM_Cmd(TIM4, ENABLE); /* Main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); while (1) {} }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Initialize Leds mounted on STM3210X-EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); /* 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_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; /* Configure the USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Set the USARTy prescaler */ USART_SetPrescaler(USARTy, 0x1); /* Configure the USARTy IrDA mode */ USART_IrDAConfig(USARTy, USART_IrDAMode_Normal); /* Enable the USARTy IrDA mode */ USART_IrDACmd(USARTy, ENABLE); while (1) { /* Wait until a byte is received */ while(USART_GetFlagStatus(USARTy, USART_FLAG_RXNE) == RESET) { } /* Read the received byte */ ReceivedData = (JOYState_TypeDef)USART_ReceiveData(USARTy); switch(ReceivedData) { case JOY_UP: STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); break; case JOY_DOWN: STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); break; case JOY_LEFT: STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED4); break; case JOY_RIGHT: STM_EVAL_LEDOn(LED4); STM_EVAL_LEDOff(LED1); STM_EVAL_LEDOff(LED2); STM_EVAL_LEDOff(LED3); break; case JOY_SEL: STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOn(LED3); STM_EVAL_LEDOn(LED4); break; case JOY_NONE: break; default: break; } } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* Enable I2C1 and I2C2 ----------------------------------------------------*/ I2C_Cmd(I2C1, ENABLE); I2C_Cmd(I2C2, ENABLE); /* I2C1 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = ClockSpeed; I2C_Init(I2C1, &I2C_InitStructure); /* I2C2 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS7; I2C_Init(I2C2, &I2C_InitStructure); I2C_CalculatePEC(I2C1, ENABLE); I2C_CalculatePEC(I2C2, ENABLE); /* Enable I2C1 event and buffer interrupts */ I2C_ITConfig(I2C1, I2C_IT_EVT | I2C_IT_BUF, ENABLE); /* Enable I2C1 event and buffer interrupts */ I2C_ITConfig(I2C2, I2C_IT_EVT | I2C_IT_BUF, ENABLE); /*----- Transmission Phase -------------------------------------------------*/ /* Set data direction to transmitter */ Direction = Transmitter; /* Send I2C1 START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* Wait until all data and the PEC value are received */ /* I2C2_Buffer_Rx buffer will contain the data plus the PEC value */ while(Rx2_Idx < Tx1BufferSize) { } /* Check the corectness of the I2C1 transmitted data */ TransferStatus1 = Buffercmp(I2C1_Buffer_Tx, I2C2_Buffer_Rx, Tx1BufferSize); /* TransferStatus1 = PASSED, if the transmitted and received data are equal */ /* TransferStatus1 = FAILED, if the transmitted and received data are different */ /*----- Reception Phase --------------------------------------------------*/ /* Re-configure and enable I2C1 event interrupt to have the higher priority */ NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* Wait until end of Slave transmission */ while(Rx1_Idx < Tx2BufferSize) { } /* Check the corectness of the I2C1 received data */ TransferStatus2 = Buffercmp(I2C2_Buffer_Tx, I2C1_Buffer_Rx, Tx2BufferSize); /* TransferStatus2 = PASSED, if the transmitted and received data are equal */ /* TransferStatus2 = FAILED, if the transmitted and received data are different */ while(1) { } }
int main(void) { u32 rx=0, ry=0, fx, fy, ff; RCC_Configuration(); GPIO_Configuration(); test.caption= "WINDOWS 0.1"; test.rc.x=20; test.rc.y=20; test.rc.h=40; test.rc.w=80; test.style=GDI_WINCAPTION|GDI_WINCAPTION_LEFT; vidInit(); sysInitSystemTimer(); vidClearScreen(); //CRT_Draw_Ring(100, VID_PIXELS_X/2, VID_PIXELS_Y/2,1, 2*3.1415/12); //sysDelayMs(2000); //CRT_Draw_Ring(100, VID_PIXELS_X/2, VID_PIXELS_Y/2,1, 2*3.1415/12); //CRT_Draw_Ring(100, VID_PIXELS_X/2, VID_PIXELS_Y/2, 2, 2*3.1415/12); // siInitialScreen(); //CRT_Draw_Ring(100, VID_PIXELS_X/2, VID_PIXELS_Y/2, 1); //vidClearScreen(); //fx=1; fy = 1; //rx=10;ry=10; //ff = rand()%100; //while(ff--){ //rx = rand()%(400); //ry = rand()%(200); //} // gdiDrawTextEx(30, 170, "KVAOAR",1); gdiDrawTextEx(340, 170, "CASA",1); gdiDrawTextEx(340, 30, "STM32F103",1); gdiDrawTextEx(340, 50, "VGA OUT",1); gdiDrawTextEx(340, 100, "PYTHAGORAS",1); gdiDrawTextEx(340, 120, "TREE",1); gdiDrawTextEx(30, 30, "22.05.16",1); Draw( VID_PIXELS_X/2,VID_PIXELS_Y/2+50,18,7,1.57); while(1) { // if((ff++%(rand()%200) )==0){ // // // fx = rand()%2 ? 0:(rand()%2 ? -1:1); // fy = rand()%2 ? 0:(rand()%2 ? -1:1); // } // //} // ry++; // rx++; // fx=ran(1)%(400/10); // fy=ran(1)%(200/10); // // ff=rand(3)%2; // CRT_Draw_Ring(100, VID_PIXELS_X/2, VID_PIXELS_Y/2, 2, 2*3.1415/12); //drawCircle(VID_PIXELS_X/2, VID_PIXELS_Y/2, 70); // CRT_Draw_Ring(100, VID_PIXELS_X/2, VID_PIXELS_Y/2,0, 1); //400*200 //#define GDI_ROP_COPY 0 //#define GDI_ROP_XOR 1 //#define GDI_ROP_AND 2 // gdiDrawTextEx(VID_PIXELS_X/2, VID_PIXELS_Y/2, "STM32", 0); // gdiCircle(VID_PIXELS_X/2, VID_PIXELS_Y/2, 50, 0); // gdiLine(0, (VID_PIXELS_X/2), (VID_PIXELS_Y/2)-50, VID_PIXELS_X/2, VID_PIXELS_Y/2, 0); // gdiPoint(0, rx, ry, 0); // // rx += fx; // ry += fy; // // // if ((rx >= 400 )||(gdiTestPoint( rx, ry)==1 )) { // //vidClearScreen(); // //rx = rand()%(400); // //ry = rand()%(200); // fx = -fx; // fx += rand()%2 ? 0:(rand()%2 ? -1:1); // fy += rand()%2 ? 0:(rand()%2 ? -1:1); // } // // // if ((ry >= 200)||(gdiTestPoint( rx, ry)==1 )) { // //vidClearScreen(); // //rx = rand()%(400); // //ry = rand()%(200); // fy = -fy; // fx += rand()%2 ? 0:(rand()%2 ? -1:1); // fy += rand()%2 ? 0:(rand()%2 ? -1:1); // } //sysDelayMs(1); //vidClearScreen(); // vidClearScreen(); // gdiRectangle((VID_PIXELS_X/2)-50, (VID_PIXELS_Y/2)-50, (VID_PIXELS_X/2)+50, (VID_PIXELS_Y/2)+50, 0); //gdiPoint(0, VID_PIXELS_X/2, VID_PIXELS_Y/2, 0); //gdiLine(0, (VID_PIXELS_X/2),0, VID_PIXELS_X/2, (VID_PIXELS_Y), 0); } //demoInit(); //siInit(); return 0; }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* RCC configuration */ RCC_Configuration(); /* TIM4 configuration */ TIM4_Configuration(); /* UART4 configuration */ UART4_Configuration(); /* WIZ820io SPI2 configuration */ WIZ820io_SPI2_Configuration(); // one that is on left one /* WIZ820io SPI3 configuration */ //WIZ820io_SPI3_Configuration(); // one that is on right one /* W5200 Configuration */ Set_network(); /* TLCD configuration */ TLCD_Configuration(); //TLCD_Write(0, 0, str1); //TLCD_Write(0, 1, str2); /* RTC Configuration */ RTC_Configuration(); /* EXIT4(Mode select button) configuration */ EXTILine4_Configuration(); /* EXIT5(F_SYNC : 100Hz) configuration */ EXTILine5_Configuration(); /* EXIT6(F_SCLK : 10KHz) configuration */ EXTILine6_Configuration(); /* myAccel3LV02 Configuration */ Accel3LV02_Configuration(); //myAccel3LV02 setup 1000.0111 Power on, enable all axis, self test off Accel_WriteReg(CTRL_REG1, 0xC7); // following routine setup myAccel3LV02 6g mode //Accel_WriteReg(CTRL_REG2, 0x80); /* GLCD configuration */ GLCD_Configuration(); // For TCP client's connection request delay presentTime = my_time; // When everything is set, print message printf("\r\n - System is ready - "); while(1) { if(TimerCount >= 1000) { // thousand equals one second TimerCount = 0; // for Calculate connection delay my_time++; // retrieve axis data GetAccelValue(AXIS_X, &Xdata); GetAccelValue(AXIS_Y, &Ydata); GetAccelValue(AXIS_Z, &Zdata); char str[30]; sprintf(str, "%d,%d,%d", 0xFFF&Xdata, 0xFFF&Ydata, 0xFFF&Zdata); TLCD_Clear(); TLCD_Write(0, 0, str); } if(ParseUART4) { ParseUART4 = False; // print Wiz810io configuration printSysCfg(); } if(flag_uart == 1) { tmp_start = start; } switch(mode) { case SELECT_AXIS_X : break; case SELECT_AXIS_Y : break; case SELECT_AXIS_Z : break; } /* Ethernet Client Routine -----------------------------------------------*/ /* SendFlag get set from when socket established and received any message */ if(SendFlag) { SendFlag = False; char AxisData[30]; for(order = 0; order < 100 ; order++) { float EW = 0; float NS = 0; float UD = 0; EW = data_x[order] * 1e-7; NS = data_y[order] * 1e-7; UD = data_z[order] * 1e-7; sprintf(AxisData, "%-0.7f,%-0.7f,%-0.7f\n", EW, NS, UD); // Only when socket is established, send data if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) { /* send the received data */ send(SOCK_ZERO, (uint8*)AxisData, strlen(AxisData), (bool)False); } } } /* Process client socket with port 5050 */ //ProcessTcpClient(SOCK_ZERO); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* RCC configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* GPIO configuration */ GPIO_Configuration(); /* Configure the CEC peripheral */ CEC_InitStructure.CEC_BitTimingMode = CEC_BitTimingStdMode; CEC_InitStructure.CEC_BitPeriodMode = CEC_BitPeriodStdMode; CEC_Init(&CEC_InitStructure); /* Set Prescaler value for APB1 clock PCLK1 = 24MHz */ CEC_SetPrescaler(0x4AF); /* Set the CEC initiator address */ CEC_OwnAddressConfig(MY_DEVICE_ADDRESS); /* Activate CEC interrupts associated to the set of RBTF,RERR, TBTF, TERR flags */ CEC_ITConfig(ENABLE); /* Enable CEC */ CEC_Cmd(ENABLE); /* If a frame has been received */ while(ReceivedFrame == 0) { } /* Check the received data with the send ones */ TransferStatus = Buffercmp(TransmitBuffer, ReceiveBuffer, ByteNumber); /* TransferStatus = PASSED, if the data transmitted from CEC Device1 and received by CEC Device2 are the same */ /* TransferStatus = FAILED, if the data transmitted from CEC Device1 and received by CEC Device2 are different */ if (TransferStatus == PASSED) { /* OK */ /* Turn on LED1 */ STM_EVAL_LEDOn(LED1); } else { /* KO */ /* Turn on LED2 */ STM_EVAL_LEDOn(LED2); } while(1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* Enable I2C1 and I2C2 ----------------------------------------------------*/ I2C_Cmd(I2C1, ENABLE); I2C_Cmd(I2C2, ENABLE); /* I2C1 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = ClockSpeed; I2C_Init(I2C1, &I2C_InitStructure); /* I2C2 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit; I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS10; I2C_Init(I2C2, &I2C_InitStructure); /*----- Transmission Phase -----*/ /* Send I2C1 START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* Test on I2C1 EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); /* Send Header to I2C2 for write */ I2C_SendData(I2C1, HeaderAddressWrite); /* Test on I2C1 EV9 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_ADDRESS10)); /* Send I2C2 slave Address for write */ I2C_Send7bitAddress(I2C1, I2C2_SLAVE_ADDRESS7, I2C_Direction_Transmitter); /* Test on I2C2 EV1 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED)); /* Test on I2C1 EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ while (RxIdx < BufferSize) { /* Send I2C1 data */ I2C_SendData(I2C1, I2C1_Buffer_Tx[TxIdx++]); /* Test on I2C2 EV2 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_BYTE_RECEIVED)); /* Store received data on I2C2 */ I2C2_Buffer_Rx[RxIdx++] = I2C_ReceiveData(I2C2); /* Test on I2C1 EV8 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); } /* Send I2C1 STOP Condition */ I2C_GenerateSTOP(I2C1, ENABLE); /* Test on I2C2 EV4 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED)); /* Clear I2C2 STOPF flag: read operation to I2C_SR1 followed by a write operation to I2C_CR1 */ (void)(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF)); I2C_Cmd(I2C2, ENABLE); /* Check the corectness of written data */ TransferStatus = Buffercmp(I2C1_Buffer_Tx, I2C2_Buffer_Rx, BufferSize); /* TransferStatus = PASSED, if the transmitted and received data are equal */ /* TransferStatus = FAILED, if the transmitted and received data are different */ while (1) { } }
/** * @brief Main program. * @param None * @retval : None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* PF.06, PF.07 and PF.08 config to drive LD1, LD2 and LD3 *****************/ /* Enable GPIOF clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE); /* Configure PF.06, PF.07 and PF.08 as Output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOF, &GPIO_InitStructure); /* Enable the FSMC Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE); /* FSMC Initialization */ FSMC_NAND_Init(); /* NAND read ID command */ FSMC_NAND_ReadID(&NAND_ID); /* Verify the NAND ID */ if((NAND_ID.Maker_ID == NAND_ST_MakerID) && (NAND_ID.Device_ID == NAND_ST_DeviceID)) { /* NAND memory address to write to */ WriteReadAddr.Zone = 0x00; WriteReadAddr.Block = 0x00; WriteReadAddr.Page = 0x00; /* Erase the NAND first Block */ status = FSMC_NAND_EraseBlock(WriteReadAddr); /* Write data to FSMC NAND memory */ /* Fill the buffer to send */ Fill_Buffer(TxBuffer, BUFFER_SIZE , 0x66); status = FSMC_NAND_WriteSmallPage(TxBuffer, WriteReadAddr, PageNumber); /* Read back the written data */ status = FSMC_NAND_ReadSmallPage (RxBuffer, WriteReadAddr, PageNumber); /* Verify the written data */ for(j = 0; j < BUFFER_SIZE; j++) { if(TxBuffer[j] != RxBuffer[j]) { WriteReadStatus++; } } if (WriteReadStatus == 0) { /* OK */ /* Turn on LD1 */ GPIO_SetBits(GPIOF, GPIO_Pin_6); } else { /* KO */ /* Turn on LD2 */ GPIO_SetBits(GPIOF, GPIO_Pin_7); } } else { /* Turn on LD3 */ GPIO_SetBits(GPIOF, GPIO_Pin_8); } while(1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* TIM4 configuration: One Pulse mode ------------------------ The external signal is connected to TIM4_CH2 pin (PB.07), The Rising edge is used as active edge, The One Pulse signal is output on TIM4_CH1 pin (PB.06) The TIM_Pulse defines the delay value The (TIM_Period - TIM_Pulse) defines the One Pulse value. TIM2CLK = SystemCoreClock, we want to get TIM2 counter clock at 24 MHz: - Prescaler = (TIM2CLK / TIM2 counter clock) - 1 The Autoreload value is 65535 (TIM4->ARR), so the maximum frequency value to trigger the TIM4 input is 24000000/65535 = 300 Hz. The TIM_Pulse defines the delay value, the delay value is fixed to 682.6 us: delay = CCR1/TIM4 counter clock = 682.6 us. The (TIM_Period - TIM_Pulse) defines the One Pulse value, the pulse value is fixed to 2.048 ms: One Pulse value = (TIM_Period - TIM_Pulse) / TIM4 counter clock = 2.048 ms. * SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density and Connectivity line devices and to 24 MHz for Value line devices ------------------------------------------------------------ */ /* Compute the prescaler value */ PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); /* TIM4 PWM2 Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 16383; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM4, &TIM_OCInitStructure); /* TIM4 configuration in Input Capture Mode */ TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0; TIM_ICInit(TIM4, &TIM_ICInitStructure); /* One Pulse Mode selection */ TIM_SelectOnePulseMode(TIM4, TIM_OPMode_Single); /* Input Trigger selection */ TIM_SelectInputTrigger(TIM4, TIM_TS_TI2FP2); /* Slave Mode selection: Trigger Mode */ TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_Trigger); while (1) {} }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* USARTy and USARTz configuration -------------------------------------------*/ /* USARTy and USARTz configured as follow: - BaudRate = 230400 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 230400; 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; /* Configure USARTy */ USART_Init(USARTy, &USART_InitStructure); /* Configure USARTz */ USART_Init(USARTz, &USART_InitStructure); /* Enable the USARTy */ USART_Cmd(USARTy, ENABLE); /* Enable the USARTz */ USART_Cmd(USARTz, ENABLE); /* Enable USARTy Half Duplex Mode*/ USART_HalfDuplexCmd(USARTy, ENABLE); /* Enable USARTz Half Duplex Mode*/ USART_HalfDuplexCmd(USARTz, ENABLE); while(NbrOfDataToRead2--) { /* Wait until end of transmit */ while(USART_GetFlagStatus(USARTy, USART_FLAG_TXE) == RESET) { } /* Write one byte in the USARTy Transmit Data Register */ USART_SendData(USARTy, TxBuffer1[TxCounter1++]); /* Wait the byte is entirtly received by USARTz */ while(USART_GetFlagStatus(USARTz, USART_FLAG_RXNE) == RESET) { } /* Store the received byte in the RxBuffer2 */ RxBuffer2[RxCounter2++] = USART_ReceiveData(USARTz); } /* Clear the USARTy Data Register */ USART_ReceiveData(USARTy); while(NbrOfDataToRead1--) { /* Wait until end of transmit */ while(USART_GetFlagStatus(USARTz, USART_FLAG_TXE)== RESET) { } /* Write one byte in the USARTz Transmit Data Register */ USART_SendData(USARTz, TxBuffer2[TxCounter2++]); /* 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 USARTz are the same */ /* TransferStatus = FAILED, if the data transmitted from USARTy and received by USARTz are different */ TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2); /* TransferStatus = PASSED, if the data transmitted from USARTz and received by USARTy are the same */ /* TransferStatus = FAILED, if the data transmitted from USARTz and received by USARTy are different */ while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration(); /* Configure the GPIO ports */ GPIO_Configuration(); /* Configure the EXTI Controller */ EXTI_Configuration(); /* SC_USART configuration ----------------------------------------------------*/ /* SC_USART configured as follow: - Word Length = 9 Bits - 0.5 Stop Bit - Even parity - BaudRate = 12096 baud - Hardware flow control disabled (RTS and CTS signals) - Tx and Rx enabled - USART Clock enabled - USART CPOL Low - USART CPHA on first edge - USART Last Bit Clock Enabled */ /* SC_USART Clock set to 4.5MHz (PCLK1 = 36 MHZ / 8) */ USART_SetPrescaler(SC_USART, 0x04); /* SC_USART Guard Time set to 2 Bit */ USART_SetGuardTime(SC_USART, 0x2); USART_ClockInitStructure.USART_Clock = USART_Clock_Enable; USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low; USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge; USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable; USART_ClockInit(SC_USART, &USART_ClockInitStructure); USART_InitStructure.USART_BaudRate = 12096; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1_5; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(SC_USART, &USART_InitStructure); /* Enable the SC_USART Parity Error Interrupt */ USART_ITConfig(SC_USART, USART_IT_PE, ENABLE); /* Enable SC_USART */ USART_Cmd(SC_USART, ENABLE); /* Enable the NACK Transmission */ USART_SmartCardNACKCmd(SC_USART, ENABLE); /* Enable the Smartcard Interface */ USART_SmartCardCmd(SC_USART, ENABLE); /* Loop while no Smartcard is detected */ while(CardInserted == 0) { } /* Read Smartcard ATR response */ for(index = 0; index < 40; index++, Counter = 0) { while((USART_GetFlagStatus(SC_USART, USART_FLAG_RXNE) == RESET) && (Counter != SC_Receive_Timeout)) { Counter++; } if(Counter != SC_Receive_Timeout) { DST_Buffer[index] = USART_ReceiveData(SC_USART); } } /* Decode ATR */ CardProtocol = SC_decode_Answer2reset(DST_Buffer); /* Test if the inserted card is ISO7816-3 T=0 compatible */ if(CardProtocol == 0) { /* Inserted card is ISO7816-3 T=0 compatible */ ATRDecodeStatus = PASSED; } else { /* Inserted Smartcard is not ISO7816-3 T=0 compatible */ ATRDecodeStatus = FAILED; } while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_DualConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 16; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 Channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_239Cycles5); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* ADC2 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 2; ADC_Init(ADC2, &ADC_InitStructure); /* ADC2 regular channels configuration */ ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_239Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 2, ADC_SampleTime_239Cycles5); /* Enable ADC2 external trigger conversion */ ADC_ExternalTrigConvCmd(ADC2, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable Vrefint channel17 */ ADC_TempSensorVrefintCmd(ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Enable ADC2 */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC2 reset calibaration register */ ADC_ResetCalibration(ADC2); /* Check the end of ADC2 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC2)); /* Start ADC2 calibaration */ ADC_StartCalibration(ADC2); /* Check the end of ADC2 calibration */ while(ADC_GetCalibrationStatus(ADC2)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* Test on DMA1 channel1 transfer complete flag */ while(!DMA_GetFlagStatus(DMA1_FLAG_TC1)); /* Clear DMA1 channel1 transfer complete flag */ DMA_ClearFlag(DMA1_FLAG_TC1); while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); SPI_I2S_DeInit(SPI3); SPI_I2S_DeInit(SPI2); /* I2S peripheral configuration */ I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended; I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k; I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; /* I2S3 Master Transmitter to I2S2 Slave Receiver communication -----------*/ /* I2S3 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; I2S_Init(SPI3, &I2S_InitStructure); /* I2S2 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx; I2S_Init(SPI2, &I2S_InitStructure); /* Enable the I2S3 TxE interrupt */ SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE); /* Enable the I2S2 RxNE interrupt */ SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE); /* Enable the I2S2 */ I2S_Cmd(SPI2, ENABLE); /* Enable the I2S3 */ I2S_Cmd(SPI3, ENABLE); /* Wait the end of communication */ while (RxIdx < 32) {} TransferStatus1 = Buffercmp(I2S2_Buffer_Rx, (uint16_t*)I2S3_Buffer_Tx, 32); /* TransferStatus1 = PASSED, if the data transmitted from I2S3 and received by I2S2 are the same TransferStatus1 = FAILED, if the data transmitted from I2S3 and received by I2S2 are different */ /* Reinitialize the buffers */ for (RxIdx = 0; RxIdx < 32; RxIdx++) { I2S2_Buffer_Rx[RxIdx] = 0; } TxIdx = 0; RxIdx = 0; SPI_I2S_DeInit(SPI3); SPI_I2S_DeInit(SPI2); /* I2S peripheral configuration */ I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b; I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_16k; I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; /* I2S3 Master Transmitter to I2S2 Slave Receiver communication -----------*/ /* I2S3 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; I2S_Init(SPI3, &I2S_InitStructure); /* I2S2 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx; I2S_Init(SPI2, &I2S_InitStructure); /* Enable the I2S3 TxE interrupt */ SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE); /* Enable the I2S2 RxNE interrupt */ SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE); /* Enable the I2S2 */ I2S_Cmd(SPI2, ENABLE); /* Enable the I2S3 */ I2S_Cmd(SPI3, ENABLE); /* Wait the end of communication */ while (RxIdx < 32) { } TransferStatus2 = Buffercmp24bits(I2S2_Buffer_Rx, (uint16_t*)I2S3_Buffer_Tx, 32); /* TransferStatus2 = PASSED, if the data transmitted from I2S3 and received by I2S2 are the same TransferStatus2 = FAILED, if the data transmitted from I2S3 and received by I2S2 are different */ while (1) { } }
/** * @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); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* TIM1 configuration ------------------------------------------------------*/ /* Time Base configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 0xFF; TIM_TimeBaseStructure.TIM_Prescaler = 0x4; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* TIM1 channel1 configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0x7F; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC1Init(TIM1, &TIM_OCInitStructure); /* DMA1 Channel1 Configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_RegularConvertedValueTab; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 32; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel14 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5); /* Set injected sequencer length */ ADC_InjectedSequencerLengthConfig(ADC1, 1); /* ADC1 injected channel Configuration */ ADC_InjectedChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_71Cycles5); /* ADC1 injected external trigger configuration */ ADC_ExternalTrigInjectedConvConfig(ADC1, ADC_ExternalTrigInjecConv_None); /* Enable automatic injected conversion start after regular one */ ADC_AutoInjectedConvCmd(ADC1, ENABLE); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 external trigger */ ADC_ExternalTrigConvCmd(ADC1, ENABLE); /* Enable JEOC interrupt */ ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* TIM1 counter enable */ TIM_Cmd(TIM1, ENABLE); /* TIM1 main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); /* Test on channel1 transfer complete flag */ while(!DMA_GetFlagStatus(DMA1_FLAG_TC1)); /* Clear channel1 transfer complete flag */ DMA_ClearFlag(DMA1_FLAG_TC1); /* TIM1 counter disable */ TIM_Cmd(TIM1, DISABLE); while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* System Tick Configuration at 1us */ SysTick_Config(SystemCoreClock / 1000000); #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* TIM2 Configuration */ TIM2_Configuration(); /* TIM3 Configuration (10ms for Network Transmission)*/ TIM3_Configuration(); /* TIM5 Configuration (GLCD Time Share)*/ TIM5_Configuration(); /* TIM6 Configuration (RTC load) */ TIM6_Configuration(); #elif defined USE_EQDAS_SERVER /* TIM4 Configuration */ TIM4_Configuration(); #endif /* CLCD Configuration */ CLCD_Configuration(); /* GLCD Configuration */ GLCD_Configuration(); /* UART1 Configuration */ UART_Configuration(); /* GPS-UART3 Configuration */ //GPS_Configuration(); /* RTC configuration by setting the time by Serial USART1 */ RTC_SetTimeBySerial(); /* Forcefully let user set the IP through terminal */ //ForceIPSetBySerial(); /* WIZ820io SPI1 configuration */ WIZ820io_SPI1_Configuration(); /* W5200 Configuration */ Set_network(); /* Print WIZ820io configuration */ printSysCfg(); /* EXTI Configuration */ EXTI_Configuration(); /* FatFS configuration */ f_mount(0, &fs); // mSD //f_mount(1, &fs); // NAND /* Display Total size of SD card in MB scale */ SD_TotalSize(); /* Scan all files in mSD card */ scan_files(path); /* MAL configuration */ //Set_System(); /* UMS configuration */ //Set_USBClock(); //USB_Interrupts_Config(); //USB_Init(); /* loop upon completion of USB Enumeration */ //while (bDeviceState != CONFIGURED); /* ATFC Algorithm GPIO */ ATFC_GPIO_Configuration(); /* ATFC Parameter Initialization */ ATFCAlgorithmParameterSetup(); // For TCP client's connection request delay presentTime = my_time; /* Clear CLCD before branch into main */ CLCD_Clear(); /* Create directory and sub directory in accordance with current date */ filePath = CreateDirectoryAccordingly(GetYearAndMergeToInt(), GetMonthAndMergeToInt(), GetDayAndMergeToInt(), RTC_GetCounter() / 3600); /* Create file in append mode in accordance with current minute */ CreateFileAppendModeAccordingly(filePath, (RTC_GetCounter() % 3600) / 60); // When everything is set, print message printf("\r\n\n - System is ready - "); while (1) { #if (defined USE_EQDAS01) || (defined USE_EQDAS02) if(TimerCount > 1000) { // 0 ~ 999 (1000) = 1 sec TimerCount = 0; /* int x, y, z; x = mAxisBuf.tmp_data_x_lcd[index]; y = mAxisBuf.tmp_data_y_lcd[index]; z = mAxisBuf.tmp_data_z_lcd[index]; char Serial_Buf[37]; int hour, minute, second, tmsecond; hour = THH; minute = TMM; second = TSS; tmsecond = 0; sprintf(Serial_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", year, month, day, hour, minute, second, tmsecond, x, y, z); printf(Serial_Buf); */ //my_time++; // uncomment when tcp connection is needed /* Process Parameter Text Stream */ /* if(PCFlag) { // EQDAS Client System and ATFC Algorithm Setting PCFlag = false; ProcessParameterStream(); } */ } /* GLCD Time Share */ if(TIM5GLCDCount > 95) { // Allocate proper time to share mcu resource with network TIM5GLCDCount = 0; /* Graphic LCD Copy and Process Routine -------------------------------------- */ if(SyncFlag) { // prevent unpleasant impuse // Index synchronization dedicate to GLCD arrGLCDIdx = index; // Make a copy from raw collected data to temporary array CopyToTmpArray(arrGLCDIdx); // Copy to Temporary GAL array //CopyToTmpGalArray(arrIdx); // Calculate GAL and copy to single temporary GAL value //CalculateGalAndCopyToGal(arrIdx); // Determine KMA scale KMAGrade = DetermineKMA(arrGLCDIdx); // Check sign bit and apply to int container CheckSignAndToInt(arrGLCDIdx); // this function also cuts surplus 1G } int mATFCBit_lcd; mATFCBit_lcd = mAxisBuf.ATFCBit_lcd[arrGLCDIdx]; /* Switch menu & waveform display through graphic lcd */ GLCD_AxisViewWithWaveform(mode, arrGLCDIdx); /* Display KMA Intensity on Graphic LCD */ GLCD_DisplayKMAIntensity(KMAGrade, mATFCBit_lcd); } /* Clock generated by TIM3 */ if(ClientTimerCounter > 10) { // 0 ~ 999 (1000) = 1 sec ClientTimerCounter = 0; year = GetYearAndMergeToInt(); month = GetMonthAndMergeToInt(); day = GetDayAndMergeToInt(); hour = THH; minute = TMM; second = TSS; tmsecond = 0; int mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec; mYear = year; mMonth = month; mDay = day; mHour = hour; mMin = minute; mSec = second; mTMSec = tmsecond; if(SyncFlag) { // Index synchronization arrIdx = index; // Make a copy from raw collected data to temporary net array CopyToNetArray(arrIdx); // Check sign bit and apply to int container CheckSignAndToIntForNet(arrIdx); // this function also cuts surplus 1G } /* Prevent access to volatile variable warning */ /* This have to be here in order to correct data to be used in ATFC */ int mX, mY, mZ, mATFCBit; mX = mAxisNetBuf.axis_x_for_net[arrIdx]; mY = mAxisNetBuf.axis_y_for_net[arrIdx]; mZ = mAxisNetBuf.axis_z_for_net[arrIdx]; mATFCBit = mAxisNetBuf.ATFCBit_net[arrIdx]; /* EQDAQ01, 02 Client Routine ---------------------------------------------*/ /* E1Flag or E2Flag set when client board successfully connect to server --*/ /* Refer to wiz820.c line no. 406 for which flag to be set */ if(E1Flag) { char E1_Buf[45]; sprintf(E1_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%d\r\n", mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec, mX, mY, mZ, mATFCBit); // Only when socket is established, allow send data if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) { /* send selected data */ CountSendByte = send(SOCK_ZERO, (uint8_t*)E1_Buf, strlen(E1_Buf), (bool)false); } } if(E2Flag) { char E2_Buf[45]; sprintf(E2_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%d\r\n", mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec, mX, mY, mZ, mATFCBit); // Only when socket is established, allow send data if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) { /* send selected data */ send(SOCK_ZERO, (uint8_t*)E2_Buf, strlen(E2_Buf), (bool)false); } } } /* do RTC work on every second */ if(RTCTIM6Count > 1000) { RTCTIM6Count = 0; if(InitialThirteenSeconds == 12) { InitialThirteenSeconds = 0; GoATFCFlag = true; } else { if(!GoATFCFlag) { InitialThirteenSeconds++; } } /* RTC 1Hz interrupt */ if(RTCTimeDisplay) { // 1Hz calibrated by RTC RTCTimeDisplay = false; /* Adjust realtime clock deviation */ if(hour > 23) { int i, currentDay, mDay, mHour, mMin, mSec; mDay = hour / 24; for(i=0; i<mDay; i++) { IncreaseSingleDay(); if(i == mDay - 1) { currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt(); BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date } } mHour = THH % 24; mMin = TMM; mSec = TSS; /* Change the current time */ RTC_SetCounter(mHour*3600 + mMin*60 + mSec); } /* Display current time */ Time_Display(RTC_GetCounter()); int OrderCount; for(OrderCount = 0; OrderCount < 100; OrderCount++) { // Copy to data buffer to be written through FATFS CopyToFatFsDataBuffer(OrderCount); } } /* RTC Alarm interrupt */ if(RTCAlarmFlag) { RTCAlarmFlag = false; printf("\r\nRTC Alarm Actviated!"); } } #endif if(ParseGPS) { ParseGPS = false; printf("%s", GPS_Buffer); } if(ParseUSART1) { ParseUSART1 = false; // run some test on SDIO //SDIO_TEST(); #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* Print WIZ820io configuration */ printSysCfg(); printf("\r\n"); printf("\r\nBKP_DR1 = %d", BKP_ReadBackupRegister(BKP_DR1)); printf("\r\nBKP_DR2 = %d", BKP_ReadBackupRegister(BKP_DR2)); printf("\r\nBKP_DR3 = %d", BKP_ReadBackupRegister(BKP_DR3)); printf("\r\nBKP_DR4 = %d", BKP_ReadBackupRegister(BKP_DR4)); printf("\r\nBKP_DR5 = %d", BKP_ReadBackupRegister(BKP_DR5)); printf("\r\nBKP_DR6 = %d", BKP_ReadBackupRegister(BKP_DR6)); printf("\r\nBKP_DR7 = %d", BKP_ReadBackupRegister(BKP_DR7)); printf("\r\nBKP_DR8 = %d", BKP_ReadBackupRegister(BKP_DR8)); printf("\r\nBKP_DR9 = %d", BKP_ReadBackupRegister(BKP_DR9)); printf("\r\nBKP_DR10 = %d", BKP_ReadBackupRegister(BKP_DR10)); printf("\r\nBKP_DR11 = %d", BKP_ReadBackupRegister(BKP_DR11)); printf("\r\nBKP_DR12 = %d", BKP_ReadBackupRegister(BKP_DR12)); printf("\r\nBKP_DR13 = %d", BKP_ReadBackupRegister(BKP_DR13)); printf("\r\nBKP_DR14 = %d", BKP_ReadBackupRegister(BKP_DR14)); printf("\r\nBKP_DR15 = %d", BKP_ReadBackupRegister(BKP_DR15)); printf("\r\nBKP_DR16 = %d", BKP_ReadBackupRegister(BKP_DR16)); /* printf("\r\nstrlen(HEADER) : %d %s", strlen(HEADER), HEADER); printf("\r\nf_mkdir1 : "); char *dirPath = "0:/20130517"; res = f_mkdir(dirPath); FPrintFatResult(res); printf("\r\nf_mkdir2 : "); dirPath = "0:/20130517/22H-23H"; res = f_mkdir(dirPath); FPrintFatResult(res); char *filePath = "0:/20130517/2-23H/test.txt"; // Create log file on the drive 0 res = open_append(&fsrc, filePath); FPrintFatResult(res); if(res == FR_OK) { printf("test.txt successfully created\r\n"); // Write buffer to file int bytesWritten; bytesWritten = f_printf(&fsrc, HEADER); printf("\r\n%d of bytesWritten", bytesWritten); // Close file f_close(&fsrc); } else if ( res == FR_EXIST ) { printf("\r\ntest.txt already exist"); } */ #elif (defined) USE_EQDAS_SERVER char buffer[37]; sprintf(buffer, "%s_%s_%s_%s_%s\r\n", DAQBoardOne[arrIdx].Date, DAQBoardOne[arrIdx].Time, DAQBoardOne[arrIdx].AxisX, DAQBoardOne[arrIdx].AxisY, DAQBoardOne[arrIdx].AxisZ); printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF)); printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer); /* char *original = "-3843,+4095,+2069"; char target[20]; strncpy(target, original, strlen(original)); char *one, *two, *three; char *AfterToken; AfterToken = strtok(target, ","); one = AfterToken; AfterToken = strtok(NULL, ","); two = AfterToken; AfterToken = strtok(NULL, ","); three = AfterToken; AfterToken = strtok(NULL, ","); if(AfterToken != NULL) printf("AfterToken is not empty"); printf("\r\none : %s, two : %s, three : %s", one, two, three);*/ #endif } // following routine is only necessary when the board works as server #if defined USE_EQDAS_SERVER /* Server also needs to have get CLCD going while running */ /* RTC 1Hz interrupt */ if(RTCTimeDisplay) { // 1Hz calibrated by RTC RTCTimeDisplay = false; /* Adjust realtime clock deviation */ if(hour > 23) { int i, currentDay, mDay, mHour, mMin, mSec; mDay = hour / 24; for(i=0; i<mDay; i++) { IncreaseSingleDay(); if(i == mDay - 1) { currentDay = (GetMonthAndMergeToInt() * 100) + GetDayAndMergeToInt(); BKP_WriteBackupRegister(BKP_DR3, currentDay); // Save Month and Date } } mHour = THH % 24; mMin = TMM; mSec = TSS; /* Change the current time */ RTC_SetCounter(mHour*3600 + mMin*60 + mSec); } /* Display current time */ Time_Display(RTC_GetCounter()); } /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */ /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */ if(E1Flag) { E1Flag = false; // clear flag since this routine excutes ceaselessly over time ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order); /* PC Client Parsing routine ------------------------------------------------- */ /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */ if(PCFlag && !E2Flag) { // only when PC is connected and EQ-DAQ-02 is not connected // Send directly to PC //SendToPC(EQ_ONE, E1Order); } if(E1Order < 99) E1Order++; else E1Order = 0; } /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */ /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */ if(E2Flag) { E2Flag = false; ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order); /* PC Client Parsing routine ------------------------------------------------- */ /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */ if(PCFlag && !E1Flag) { // only when PC is connected and EQ-DAQ-01 is not connected // Send directly to PC //SendToPC(EQ_TWO, E2Order); } if(E2Order < 99) E2Order++; else E2Order = 0; /* PC Client Parsing routine ------------------------------------------------- */ /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */ if(PCFlag) { // Send directly to PC MultipleBoardDataToSendToPC(EQ_BOTH, E1Order, E2Order); } } #endif /* Setup TCP Client or Server -----------------------------------------------------*/ /* Please open config.h file to choose a proper board you wish to use -------------*/ #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* Start TCP Client process */ ProcessTcpClient(SOCK_ZERO); // TCP Client /* Parameter setting Server side with port 5050 in default */ ATFCTcpServer(SOCK_TWO, EQDAS_Conf_PORT); // SOCK_TWO because of flag conformity #elif defined USE_EQDAS_SERVER /* Process server socket with each port */ ProcessTcpServer(SOCK_ZERO, 5050); // designated as for EQM-DAQ-01 with port 5050 ProcessTcpServer(SOCK_ONE, 6060); // designated as for EQM-DAQ-02 with port 6060 ProcessTcpServer(SOCK_TWO, 7070); // designated as for PC-CLIENT with port 7070 ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP with port 8080 /* ProcessTcpServer(SOCK_FOUR, 9090); // designated as for TOBEUSED with port 9090 ProcessTcpServer(SOCK_FIVE, 10010); // designated as for TOBEUSED with port 10010 ProcessTcpServer(SOCK_SIX, 10020); // designated as for TOBEUSED with port 10020 ProcessTcpServer(SOCK_SEVEN, 10030); // designated as for TOBEUSED with port 10030 */ #endif } }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* System Clocks Configuration **********************************************/ RCC_Configuration(); /* NVIC Configuration *******************************************************/ NVIC_Configuration(); /* Configure all unused GPIO port pins in Analog Input mode (floating input trigger OFF), this will reduce the power consumption and increase the device immunity against EMI/EMC *************************************************/ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Init(GPIOC, &GPIO_InitStructure); GPIO_Init(GPIOD, &GPIO_InitStructure); GPIO_Init(GPIOE, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE, DISABLE); #ifdef USE_STM3210E_EVAL RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, ENABLE); GPIO_Init(GPIOF, &GPIO_InitStructure); GPIO_Init(GPIOG, &GPIO_InitStructure); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG, DISABLE); #endif /* USE_STM3210E_EVAL */ /* Configure IO connected to LD1, LD2, LD3 and LD4 leds *********************/ /* Enable GPIO_LED clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIO_LED, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIO_LED, &GPIO_InitStructure); while (1) { /* Turn on LD1 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_6); /* Insert delay */ Delay(0xAFFFF); /* Turn on LD2 and LD3 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_7 | GPIO_Pin_8); /* Turn off LD1 */ GPIO_ResetBits(GPIO_LED, GPIO_Pin_6); /* Insert delay */ Delay(0xAFFFF); /* Turn on LD4 */ GPIO_SetBits(GPIO_LED, GPIO_Pin_9); /* Turn off LD2 and LD3 */ GPIO_ResetBits(GPIO_LED, GPIO_Pin_8 | GPIO_Pin_7); /* Insert delay */ Delay(0xAFFFF); /* Turn off LD4 */ GPIO_ResetBits(GPIO_LED, GPIO_Pin_9); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* --------------------------------------------------------------- TIM2 Configuration: TIM2CLK = SystemCoreClock / 2, The objective is to get TIM2 counter clock at 1 KHz: - Prescaler = (TIM2CLK / TIM2 counter clock) - 1 And generate 4 signals with 4 different delays: TIM2_CH1 delay = CCR1_Val/TIM2 counter clock = 1000 ms TIM2_CH2 delay = CCR2_Val/TIM2 counter clock = 500 ms TIM2_CH3 delay = CCR3_Val/TIM2 counter clock = 250 ms TIM2_CH4 delay = CCR4_Val/TIM2 counter clock = 125 ms * SystemCoreClock is set to 72 MHz for Low-density, Medium-density, High-density and Connectivity line devices and to 24 MHz for Low-Density Value line and Medium-Density Value line devices --------------------------------------------------------------- */ /* Compute the prescaler value */ PrescalerValue = (uint16_t) (SystemCoreClock / 2000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* Output Compare Active Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Inactive; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Active Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR2_Val; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Active Mode configuration: Channel3 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Active Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM2, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable); TIM_ARRPreloadConfig(TIM2, ENABLE); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE); /* Set PC.06, PC.07, PC.08 and PC.09 pins */ GPIO_SetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1) {} }
void USART1_Configuration(void) { USART_InitTypeDef USART_InitStructure; /* USARTx configuration ------------------------------------------------------*/ /* USARTx configured as follow: * - BaudRate = 57600 baud * - Word Length = 8 Bits * - One Stop Bit * - No parity * - Hardware flow control disabled (RTS and CTS signals) * - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 57600; 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; //START USART USART_Init(USART1, &USART_InitStructure); USART_Cmd(USART1, ENABLE); //Using Interrupt USART_ClearFlag(USART1, USART_FLAG_TC); //Enable RX interrupt & Disable TX interrupt USART_ITConfig(USART1, USART_IT_TXE, DISABLE); USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); /* NVIC Initialization */ NVIC_InitTypeDef NVIC_InitStruct = { .NVIC_IRQChannel = USART1_IRQn, .NVIC_IRQChannelPreemptionPriority = 0, .NVIC_IRQChannelSubPriority = 0, .NVIC_IRQChannelCmd = ENABLE }; NVIC_Init(&NVIC_InitStruct); } void USART1_puts(char* s) { while(*s) { while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); USART_SendData(USART1, *s); s++; } } /**************************************************************************************/ int main(void) { RCC_Configuration(); GPIO_Configuration(); USART1_Configuration(); LED_Initialization(); USART1_puts("Hello World!\r\n"); USART1_puts("Just for STM32F429I Discovery verify USART1 with USB TTL Cable\r\n"); while(1) { //LED4_Toggle(); //Delay_1us(10000); //USART1_puts(i); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* I2S peripheral configuration */ I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended; I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k; I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low; /* I2S3 Master Transmitter to I2S2 Slave Receiver communication ------------*/ /* I2S3 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx; I2S_Init(SPI3, &I2S_InitStructure); /* I2S2 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx; I2S_Init(SPI2, &I2S_InitStructure); /* Enable the I2S2 */ I2S_Cmd(SPI2, ENABLE); /* Enable the I2S3 */ I2S_Cmd(SPI3, ENABLE); /* Begin the communication in I2S mode */ while (RxIdx < BufferSize) { /* Wait the Tx buffer to be empty */ while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET) {} /* Send a data from I2S3 */ SPI_I2S_SendData(SPI3, I2S3_Buffer_Tx[TxIdx++]); /* Wait the Rx buffer to be full */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) {} /* Store the I2S2 received data in the relative data table */ I2S2_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI2); } TransferStatus1 = Buffercmp(I2S2_Buffer_Rx, I2S3_Buffer_Tx, BufferSize); /* TransferStatus1 = PASSED, if the data transmitted from I2S3 and received by I2S2 are the same TransferStatus1 = FAILED, if the data transmitted from I2S3 and received by I2S2 are different */ /* Reset TxIdx, RxIdx indexes */ TxIdx = 0; RxIdx = 0; /* Switch to SPI mode communication ----------------------------------------*/ /* SPI3 configuration */ SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; SPI_InitStructure.SPI_Mode = SPI_Mode_Master; SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; SPI_InitStructure.SPI_CRCPolynomial = 7; SPI_Init(SPI3, &SPI_InitStructure); /* SPI2 configuration ------------------------------------------------------*/ SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_RxOnly; SPI_InitStructure.SPI_Mode = SPI_Mode_Slave; SPI_Init(SPI2, &SPI_InitStructure); /* Enable SPI2 */ SPI_Cmd(SPI2, ENABLE); /* Enable SPI3 */ SPI_Cmd(SPI3, ENABLE); /* Begin the communication in SPI mode */ while (RxIdx < BufferSize) { /* Wait the Tx buffer to be empty */ while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET) {} /* Send a data from SPI3 */ SPI_I2S_SendData(SPI3, SPI3_Buffer_Tx[TxIdx++]); /* Wait the Rx buffer to be full */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) {} /* Store the SPI2 received data in the relative data table */ SPI2_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI2); } TransferStatus2 = Buffercmp(SPI2_Buffer_Rx, SPI3_Buffer_Tx, BufferSize); /* TransferStatus2 = PASSED, if the data transmitted from SPI3 and received by SPI2 are the same TransferStatus2 = FAILED, if the data transmitted from SPI3 and received by SPI2 are different */ /* Reset TxIdx, RxIdx indexes and receive table values */ for (TxIdx = 0; TxIdx < BufferSize; TxIdx++) { I2S2_Buffer_Rx[TxIdx] = 0; } TxIdx = 0; RxIdx = 0; /* I2S3 Slave Transmitter to I2S2 Master Receiver communication ------------*/ /* I2S3 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveTx; I2S_Init(SPI3, &I2S_InitStructure); /* I2S2 configuration */ I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx; I2S_Init(SPI2, &I2S_InitStructure); /* Wait the Tx buffer to be empty */ while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET) {} /* Prepare the first data to be sent from the slave */ SPI_I2S_SendData(SPI3, I2S3_Buffer_Tx[TxIdx++]); /* Enable the I2S3 */ I2S_Cmd(SPI3, ENABLE); /* Enable the I2S2 */ I2S_Cmd(SPI2, ENABLE); /* Begin the communication in I2S mode */ while (RxIdx < BufferSize) { /* Wait the Rx buffer to be full */ while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET) {} /* Store the I2S2 received data in the relative data table */ I2S2_Buffer_Rx[RxIdx++] = SPI_I2S_ReceiveData(SPI2); /* Wait the Tx buffer to be empty */ while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET) {} /* Send a data from I2S3 */ SPI_I2S_SendData(SPI3, I2S3_Buffer_Tx[TxIdx++]); } TransferStatus3 = Buffercmp(I2S2_Buffer_Rx, I2S3_Buffer_Tx, BufferSize); /* TransferStatus3 = PASSED, if the data transmitted from I2S3 and received by I2S2 are the same TransferStatus3 = FAILED, if the data transmitted from I2S3 and received by I2S2 are different */ while (1) {} }
/** * @brief Main program * @param None * @retval None */ int main(void) { FLASHStatus = FLASH_COMPLETE; MemoryProgramStatus = PASSED; Data = 0x1753; EraseCounter = 0x0; /* RCC Configuration */ RCC_Configuration(); /* Unlock the Flash Program Erase controller */ FLASH_Unlock(); /* Define the number of page to be erased */ NbrOfPage = (EndAddr - StartAddr) / FLASH_PAGE_SIZE; FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP|FLASH_FLAG_PGERR |FLASH_FLAG_WRPRTERR); /* Get pages write protection status */ WRPR_Value = FLASH_GetWriteProtectionOptionByte(); ProtectedPages = WRPR_Value & 0x000000C0; #ifdef WriteProtection_Disable if (ProtectedPages == 0x00) {/* Pages are write protected */ /* Disable the write protection */ FLASHStatus = FLASH_EraseOptionBytes(); /* Generate System Reset to load the new option byte values */ NVIC_SystemReset(); } #elif defined WriteProtection_Enable if (ProtectedPages != 0x00) { /* Pages not write protected */ #if defined (STM32F10X_LD) || defined (STM32F10X_MD) /* Enable the pages write protection */ FLASHStatus = FLASH_EnableWriteProtection(FLASH_WRProt_Pages24to27 |FLASH_WRProt_Pages28to31); #else /* (STM32F10X_HD) || defined (STM32F10X_CL) */ /* Enable the pages write protection */ FLASHStatus = FLASH_EnableWriteProtection(FLASH_WRProt_Pages12to13 |FLASH_WRProt_Pages14to15); #endif /* Generate System Reset to load the new option byte values */ NVIC_SystemReset(); } #endif /* If Pages are not write protected, perform erase and program operations Else nothing */ if (ProtectedPages != 0x00) { /* Clear All pending flags */ FLASH_ClearFlag(FLASH_FLAG_BSY | FLASH_FLAG_EOP|FLASH_FLAG_PGERR |FLASH_FLAG_WRPRTERR); /* erase the FLASH pages */ for(EraseCounter = 0; (EraseCounter < NbrOfPage) && (FLASHStatus == FLASH_COMPLETE); EraseCounter++) { FLASHStatus = FLASH_ErasePage(StartAddr + (FLASH_PAGE_SIZE * EraseCounter)); } /* FLASH Half Word program of data 0x1753 at addresses defined by StartAddr and EndAddr */ Address = StartAddr; while((Address < EndAddr) && (FLASHStatus == FLASH_COMPLETE)) { FLASHStatus = FLASH_ProgramHalfWord(Address, Data); Address = Address + 2; } /* Check the corectness of written data */ Address = StartAddr; while((Address < EndAddr) && (MemoryProgramStatus != FAILED)) { if((*(__IO uint16_t*) Address) != Data) { MemoryProgramStatus = FAILED; } Address += 2; } } while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Timing Mode: TIM2 counter clock at 6 MHz CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48 Hz CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7 Hz CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4 Hz CC4 update rate = TIM2 counter clock / CCR4_Val = 878.9 Hz --------------------------------------------------------------- */ /* Compute the prescaler value */ PrescalerValue = (uint16_t) (SystemCoreClock / 12000000) - 1; /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* Prescaler configuration */ TIM_PrescalerConfig(TIM2, PrescalerValue, TIM_PSCReloadMode_Immediate); /* Output Compare Timing Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR2_Val; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel3 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM2, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1); }
/** * @brief Main program * @param None * @retval : None */ int main(void) { /* System Clocks Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Timing Mode: TIM2CLK = 36 MHz, Prescaler = 4, TIM2 counter clock = 7.2 MHz CC1 update rate = TIM2 counter clock / CCR1_Val = 146.48 Hz CC2 update rate = TIM2 counter clock / CCR2_Val = 219.7 Hz CC3 update rate = TIM2 counter clock / CCR3_Val = 439.4 Hz CC4 update rate = TIM2 counter clock / CCR4_Val = 878.9 Hz --------------------------------------------------------------- */ /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* Prescaler configuration */ TIM_PrescalerConfig(TIM2, 4, TIM_PSCReloadMode_Immediate); /* Output Compare Timing Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR2_Val; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel3 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Timing Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM2, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1); }
void PWM_init(void) { RCC_Configuration(); TIM_Configuration(); GPIO_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); }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is 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 */ /* System Clocks Configuration */ RCC_Configuration(); /* System Tick Configuration at 1us */ SysTick_Config(SystemCoreClock / 1000000); #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* TIM2 Configuration */ TIM2_Configuration(); /* TIM3 Configuration */ TIM3_Configuration(); /* TIM6 Configuration (RTC load) */ TIM6_Configuration(); #elif defined USE_EQDAS_SERVER /* TIM4 Configuration */ TIM4_Configuration(); #endif /* CLCD Configuration */ CLCD_Configuration(); /* GLCD Configuration */ GLCD_Configuration(); /* UART1 Configuration */ UART_Configuration(); /* RTC configuration by setting the time by Serial USART1 */ //RTC_SetTimeBySerial(); /* WIZ820io SPI1 configuration */ WIZ820io_SPI1_Configuration(); /* W5200 Configuration */ Set_network(); /* Print WIZ820io configuration */ printSysCfg(); /* EXTI Configuration */ EXTI_Configuration(); /* FatFS configuration */ f_mount(0, &fs); // mSD //f_mount(1, &fs); // NAND /* Display Total size of SD card in MB scale */ SD_TotalSize(); /* Scan all files in mSD card */ scan_files(path); /* MAL configuration */ //Set_System(); /* UMS configuration */ //Set_USBClock(); //USB_Interrupts_Config(); //USB_Init(); /* loop upon completion of USB Enumeration */ //while (bDeviceState != CONFIGURED); /* ATFC Algorithm GPIO */ ATFC_GPIO_Configuration(); /* ATFC Parameter Initialization */ ATFCAlgorithmParameterSetup(); // For TCP client's connection request delay presentTime = my_time; /* Clear CLCD before branch into main */ CLCD_Clear(); /* Alarm in 3 second */ //RTC_SetAlarm(RTC_GetCounter() + 3); /* Wait until last write operation on RTC registers has finished */ //RTC_WaitForLastTask(); /* Create directory and sub directory in accordance with current date */ //filePath = CreateDirectoryAccordingly(GetYearAndMergeToInt(), GetMonthAndMergeToInt(), //GetDayAndMergeToInt(), RTC_GetCounter() / 3600); /* Create file in append mode in accordance with current minute */ //CreateFileAppendModeAccordingly(filePath, (RTC_GetCounter() % 3600) / 60); // When everything is set, print message printf("\r\n\n - System is ready - "); while (1) { #if (defined USE_EQDAS01) || (defined USE_EQDAS02) if(TimerCount > 1000) { // 0 ~ 999 (1000) = 1 sec TimerCount = 0; /* int x, y, z; x = mAxisBuf.tmp_data_x_lcd[index]; y = mAxisBuf.tmp_data_y_lcd[index]; z = mAxisBuf.tmp_data_z_lcd[index]; char Serial_Buf[37]; int hour, minute, second, tmsecond; hour = THH; minute = TMM; second = TSS; tmsecond = 0; sprintf(Serial_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", year, month, day, hour, minute, second, tmsecond, x, y, z); printf(Serial_Buf); */ //my_time++; // uncomment when tcp connection is needed /* Process Parameter Text Stream */ if(PCFlag) { // EQDAS Client System and ATFC Algorithm Setting PCFlag = false; ProcessParameterStream(); } } /* Clock generated by TIM3 */ if(ClientTimerCounter > 10) { // 0 ~ 999 (1000) = 1 sec ClientTimerCounter = 0; int mAlgorithmContainer; year = GetYearAndMergeToInt(); month = GetMonthAndMergeToInt(); day = GetDayAndMergeToInt(); hour = THH; minute = TMM; second = TSS; tmsecond = 0; int mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec; mYear = year; mMonth = month; mDay = day; mHour = hour; mMin = minute; mSec = second; mTMSec = tmsecond; x = mAxisBuf.tmp_data_x_lcd[arrIdx]; y = mAxisBuf.tmp_data_y_lcd[arrIdx]; z = mAxisBuf.tmp_data_z_lcd[arrIdx]; if(flag_uart) { // prevent unpleasant impuse // Index synchronization arrIdx = index; // Make a copy from raw collected data to temporary array CopyToTmpArray(arrIdx); // Copy to Temporary GAL array CopyToTmpGalArray(arrIdx); // Calculate GAL and copy to single temporary GAL value CalculateGalAndCopyToGal(arrIdx); // Determine KMA scale DetermineKMA(arrIdx); // Check sign bit and apply to int container CheckSignAndToInt(arrIdx); // this function also cuts surplus 1G /* Switch menu & waveform display through graphic lcd */ GLCD_AxisViewWithWaveform(mode, arrIdx, x, y, z); if(GoATFCFlag) { // Apply ATFC Algorithm to Axis x ATFCAlgorithm(mAxisBuf.tmp_data_x_lcd[arrIdx]); } } if(EventDetection) { GPIO_WriteBit(GPIOE, GPIO_Pin_15, Bit_SET); mAlgorithmContainer = x; } else { GPIO_WriteBit(GPIOE, GPIO_Pin_15, Bit_RESET); mAlgorithmContainer = 0; } // Copy to data buffer to be written through FATFS //CopyToFatFsDataBuffer(arrIdx); /* EQDAQ01, 02 Client Routine ---------------------------------------------*/ /* E1Flag or E2Flag set when client board successfully connect to server --*/ /* Refer to wiz820.c line no. 300 for which flag to be set */ if(E1Flag) { char E1_Buf[45]; sprintf(E1_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d_%+05d\r\n", mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec, x, y, z, mAlgorithmContainer); // Only when socket is established, allow send data if(getSn_SR(SOCK_TWO) == SOCK_ESTABLISHED) { /* send selected data */ CountSendByte = send(SOCK_TWO, (uint8_t*)E1_Buf, strlen(E1_Buf), (bool)false); } } if(E2Flag) { char E2_Buf[45]; sprintf(E2_Buf, "%04d%02d%02d_%02d%02d%02d%02d_%+05d_%+05d_%+05d\r\n", mYear, mMonth, mDay, mHour, mMin, mSec, mTMSec, x, y, z); // Only when socket is established, allow send data if(getSn_SR(SOCK_ZERO) == SOCK_ESTABLISHED) { /* send selected data */ send(SOCK_ZERO, (uint8_t*)E2_Buf, strlen(E2_Buf), (bool)false); } } } /* do RTC work on every second */ if(RTCTIM6Count > 1000) { RTCTIM6Count = 0; if(InitialThirteenSeconds == 12) { InitialThirteenSeconds = 0; GoATFCFlag = true; } else { if(!GoATFCFlag) { InitialThirteenSeconds++; } } /* RTC 1Hz interrupt */ if(RTCTimeDisplay) { // 1Hz calibrated by RTC RTCTimeDisplay = false; /* Display current time */ Time_Display(RTC_GetCounter()); } /* RTC Alarm interrupt */ if(RTCAlarmFlag) { RTCAlarmFlag = false; printf("\r\nRTC Alarm Actviated!"); } } /* Save log to file process ------------------------------------------------*/ /* Save process needs to be run every single cycle due to delay might occur */ if(GoAppendDataFlag) { // every 500 sample (equals 5 sec), go save file. GoAppendDataFlag = false; int bytesWritten = 0; if(EachSecFlag) { // it means that DATA1_BUF is full and ready to flush out // be sure to empty out DATA1_BUF or will overflow and cause system to halt. /* Append first data for the duration of 1 second */ bytesWritten = f_printf(&fsrc, DATA1_BUF); printf("\r\n%d of bytesWritten", bytesWritten); if(FileRecordCompleteFlag) { FileRecordCompleteFlag = false; printf("\r\nFile Record Complete!"); /* Close the file */ f_close(&fsrc); } // Reset DATA1_BUF memset(DATA1_BUF, 0, sizeof(DATA1_BUF)); } else { /* Append another second of data */ bytesWritten = f_printf(&fsrc, DATA2_BUF); printf("\r\n%d of bytesWritten", bytesWritten); if(FileRecordCompleteFlag) { FileRecordCompleteFlag = false; printf("\r\nFile Record Complete!"); /* Close the file */ f_close(&fsrc); } // Reset DATA2_BUF memset(DATA2_BUF, 0, sizeof(DATA2_BUF)); } } #endif if(ParseUSART1) { ParseUSART1 = false; // run some test on SDIO //SDIO_TEST(); #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* Print WIZ820io configuration */ printSysCfg(); printf("\r\n"); printf("\r\nBKP_DR1 = %d", BKP_ReadBackupRegister(BKP_DR1)); printf("\r\nBKP_DR2 = %d", BKP_ReadBackupRegister(BKP_DR2)); printf("\r\nBKP_DR3 = %d", BKP_ReadBackupRegister(BKP_DR3)); printf("\r\nBKP_DR4 = %d", BKP_ReadBackupRegister(BKP_DR4)); printf("\r\nBKP_DR5 = %d", BKP_ReadBackupRegister(BKP_DR5)); printf("\r\nBKP_DR6 = %d", BKP_ReadBackupRegister(BKP_DR6)); printf("\r\nBKP_DR7 = %d", BKP_ReadBackupRegister(BKP_DR7)); printf("\r\nBKP_DR8 = %d", BKP_ReadBackupRegister(BKP_DR8)); printf("\r\nBKP_DR9 = %d", BKP_ReadBackupRegister(BKP_DR9)); printf("\r\nBKP_DR10 = %d", BKP_ReadBackupRegister(BKP_DR10)); printf("\r\nBKP_DR11 = %d", BKP_ReadBackupRegister(BKP_DR11)); printf("\r\nBKP_DR12 = %d", BKP_ReadBackupRegister(BKP_DR12)); printf("\r\nBKP_DR13 = %d", BKP_ReadBackupRegister(BKP_DR13)); printf("\r\nBKP_DR14 = %d", BKP_ReadBackupRegister(BKP_DR14)); printf("\r\nBKP_DR15 = %d", BKP_ReadBackupRegister(BKP_DR15)); printf("\r\nBKP_DR16 = %d", BKP_ReadBackupRegister(BKP_DR16)); #elif (defined) USE_EQDAS_SERVER char buffer[37]; sprintf(buffer, "%s_%s_%s_%s_%s\r\n", DAQBoardOne[arrIdx].Date, DAQBoardOne[arrIdx].Time, DAQBoardOne[arrIdx].AxisX, DAQBoardOne[arrIdx].AxisY, DAQBoardOne[arrIdx].AxisZ); printf("\r\nRX_BUF : %s, strlen(RX_BUF) : %d", (char*)RX_BUF, strlen((char*)RX_BUF)); printf("\r\nstrlen(buffer) = %d\n%s", strlen(buffer), buffer); /* char *original = "-3843,+4095,+2069"; char target[20]; strncpy(target, original, strlen(original)); char *one, *two, *three; char *AfterToken; AfterToken = strtok(target, ","); one = AfterToken; AfterToken = strtok(NULL, ","); two = AfterToken; AfterToken = strtok(NULL, ","); three = AfterToken; AfterToken = strtok(NULL, ","); if(AfterToken != NULL) printf("AfterToken is not empty"); printf("\r\none : %s, two : %s, three : %s", one, two, three);*/ #endif } #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* for(i=0; i<100; i++) { if(flag_uart) { // Make a copy from raw collected data to temporary array CopyToTmpArray(i); // Copy to Temporary GAL array CopyToTmpGalArray(i); // Calculate GAL and copy to single temporary GAL value CalculateGalAndCopyToGal(i); // Determine KMA scale DetermineKMA(i); // Check sign bit and apply to int container CheckSignAndToInt(i); // this function also cuts surplus 1G } } */ // following routine is only necessary when the board works as server #elif defined USE_EQDAS_SERVER /* EQ-DAQ-01 Parsing routine ------------------------------------------------- */ /* Set E1Flag indicate that we have valid connection from EQ-DAQ-01(port 5050) */ if(E1Flag) { E1Flag = false; // clear flag since this routine excutes ceaselessly over time ProcessTextStream(EQ_ONE, (char*)RX_BUF, E1Order); /* PC Client Parsing routine ------------------------------------------------- */ /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */ if(PCFlag) { // Send directly to PC SendToPC(E1Order); } if(E1Order < 99) E1Order++; else E1Order = 0; } /* EQ-DAQ-02 Parsing routine ------------------------------------------------- */ /* Set E2Flag indicate that we have valid connection from EQ-DAQ-02(port 6060) */ if(E2Flag) { E2Flag = false; ProcessTextStream(EQ_TWO, (char*)RX_BUF, E2Order); /* PC Client Parsing routine ------------------------------------------------- */ /* Set PCFlag indicate that we have valid connection from PC Client(port 7070) */ if(PCFlag) { // Send directly to PC SendToPC(E2Order); } if(E2Order < 99) E2Order++; else E2Order = 0; } #endif /* Setup TCP Client or Server -----------------------------------------------------*/ /* Please open config.h file to choose a proper board you wish to use */ #if (defined USE_EQDAS01) || (defined USE_EQDAS02) /* Start TCP Client process */ ProcessTcpClient(SOCK_ZERO); // TCP Client /* Parameter setting Server side with port 5050 in default */ ATFCTcpServer(SOCK_TWO, EQDAS_Conf_PORT); // SOCK_TWO because of flag conformity #elif defined USE_EQDAS_SERVER /* Process server socket with each port */ ProcessTcpServer(SOCK_ZERO, 5050); // designated as for EQM-DAQ-01 with port 5050 ProcessTcpServer(SOCK_ONE, 6060); // designated as for EQM-DAQ-02 with port 6060 ProcessTcpServer(SOCK_TWO, 7070); // designated as for PC-CLIENT with port 7070 ProcessTcpServer(SOCK_THREE, 8080); // designated as for PC_DUMP with port 8080 /* ProcessTcpServer(SOCK_FOUR, 9090); // designated as for TOBEUSED with port 9090 ProcessTcpServer(SOCK_FIVE, 10010); // designated as for TOBEUSED with port 10010 ProcessTcpServer(SOCK_SIX, 10020); // designated as for TOBEUSED with port 10020 ProcessTcpServer(SOCK_SEVEN, 10030); // designated as for TOBEUSED with port 10030 */ #endif } }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* System clocks configuration ---------------------------------------------*/ RCC_Configuration(); /* NVIC configuration ------------------------------------------------------*/ NVIC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* Enable I2C1 and I2C2 ----------------------------------------------------*/ I2C_Cmd(I2C1, ENABLE); I2C_Cmd(I2C2, ENABLE); /* I2C1 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = ClockSpeed; I2C_Init(I2C1, &I2C_InitStructure); /* I2C2 configuration ------------------------------------------------------*/ I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit; I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS10; I2C_Init(I2C2, &I2C_InitStructure); /*----- Transmission Phase -----*/ /* Send I2C1 START condition */ I2C_GenerateSTART(I2C1, ENABLE); /* Test on I2C1 EV5 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); /* Send Header to I2C2 for write */ I2C_SendData(I2C1, HeaderAddressWrite); /* Test on I2C1 EV9 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_ADDRESS10)); /* Send I2C2 slave Address for write */ I2C_Send7bitAddress(I2C1, I2C2_SLAVE_ADDRESS7, I2C_Direction_Transmitter); /* Test on I2C2 EV1 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED)); /* Test on I2C1 EV6 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Send data */ while (RxIdx < BufferSize) { /* Send I2C1 data */ I2C_SendData(I2C1, I2C1_Buffer_Tx[TxIdx++]); /* Test on I2C2 EV2 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_BYTE_RECEIVED)); /* Store received data on I2C2 */ I2C2_Buffer_Rx[RxIdx++] = I2C_ReceiveData(I2C2); /* Test on I2C1 EV8 and clear it */ while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)); } /* Send I2C1 STOP Condition */ I2C_GenerateSTOP(I2C1, ENABLE); /* Test on I2C2 EV4 and clear it */ while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED)); /* Clear I2C2 STOPF flag: read operation to I2C_SR1 followed by a write operation to I2C_CR1 */ (void)(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF)); I2C_Cmd(I2C2, ENABLE); /* Check the corectness of written data */ TransferStatus = Buffercmp(I2C1_Buffer_Tx, I2C2_Buffer_Rx, BufferSize); /* TransferStatus = PASSED, if the transmitted and received data are equal */ /* TransferStatus = FAILED, if the transmitted and received data are different */ while (1) { } }
/******************************************************************************* * Function Name : main * Description : Main program * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { #ifdef DEBUG debug(); #endif /* System Clocks Configuration */ RCC_Configuration(); /* NVIC Configuration */ NVIC_Configuration(); /* GPIO Configuration */ GPIO_Configuration(); /* --------------------------------------------------------------- TIM2 Configuration: Output Compare Inactive Mode: TIM2CLK = 36 MHz, Prescaler = 35999, TIM2 counter clock = 1 KHz TIM2_CH1 delay = CCR1_Val/TIM2 counter clock = 1000 ms TIM2_CH2 delay = CCR2_Val/TIM2 counter clock = 500 ms TIM2_CH3 delay = CCR3_Val/TIM2 counter clock = 250 ms TIM2_CH4 delay = CCR4_Val/TIM2 counter clock = 125 ms --------------------------------------------------------------- */ /* Time base configuration */ TIM_TimeBaseStructure.TIM_Period = 65535; TIM_TimeBaseStructure.TIM_Prescaler = 35999; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); /* Output Compare Active Mode configuration: Channel1 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Inactive; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR1_Val; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM2, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Active Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR2_Val; TIM_OC2Init(TIM2, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Active Mode configuration: Channel3 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR3_Val; TIM_OC3Init(TIM2, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Disable); /* Output Compare Active Mode configuration: Channel4 */ TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = CCR4_Val; TIM_OC4Init(TIM2, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Disable); TIM_ARRPreloadConfig(TIM2, ENABLE); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE); /* Set PC.06, PC.07, PC.08 and PC.09 pins */ GPIO_SetBits(GPIOC, GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9); /* TIM2 enable counter */ TIM_Cmd(TIM2, ENABLE); while (1) {} }
int main(void) { PWM_Initialization(); TIM1->CCR2 = 1000; TIM1->CCR3 = 1000; Delay_1us(500000); RCC_Configuration(); PushButton_Initialization(); LED_Initialization(); //LCD_Initialization(); //terminalBufferInitilization(); Delay_1us(100000); SPI_Initialization(); Delay_1us(100000); IMU_Initialization(); Delay_1us(100000); Timer5_Initialization(); //Filter Timer2_Initialization(); //Print Timer4_Initialization(); //Read IMU USART3_Configuration(); USART3_puts("\r\nHello World!\r\n"); while(1) { if(PushButton_Read()){ if(f.arm == 0){ f.arm = 1; Delay_1us(500000); } else if(f.arm == 1){ f.arm = 0; Delay_1us(500000); } } if(f.imu == 1){ //LED3_Toggle(); readIMU(gyroRaw, GYRO_DATA_REGISTER); gyro_remove_offset(gyroRaw); readIMU(accRaw, ACC_DATA_REGISTER); f.imu = 0; // } // if(f.filter == 1){ //LED4_Toggle(); Filter(gyroRaw, gyroAngle, accRaw, accAngle, Angle); if(f.arm == 1){ PID_control(Angle); } else{ TIM1->CCR2 = 1000; TIM1->CCR3 = 1000; errorI = 0; errorD = 0; previous_error = 0; } //f.filter = 0; } strcmd_main(); //if(f.print == 1){ // sprintf(lcd_text_main,"%.4f %.4f %d", Angle[0], Angle[1], f.arm); // //sprintf(lcd_text_main,"G: %.3f %.3f %.3f", EstV.G.X, EstV.G.Y, EstV.G.Z); // LCD_DisplayStringLine(LINE(1), lcd_text_main); // //sprintf(lcd_text_main,"A: %.3f %.3f %.3f", EstV.A.X, EstV.A.Y, EstV.A.Z); // //sprintf(lcd_text_main,"A: %.3f %.3f", sqX_sqZ, EstV.GA.X*EstV.GA.X + EstV.GA.Z*EstV.GA.Z); // // sprintf(lcd_text_main,"%.4f %.4f %.4f \n", gyroAngle[0], gyroAngle[1], gyroAngle[2]); // sprintf(lcd_text_main,"%d ", gyroRaw[2]); // LCD_DisplayStringLine(LINE(2), lcd_text_main); // sprintf(lcd_text_main,"GA: %.3f %.3f %.3f", EstV.GA.X, EstV.GA.Y, EstV.GA.Z); // LCD_DisplayStringLine(LINE(3), lcd_text_main); //sprintf(lcd_text_main,"%.3f %.3f %.3f\n", EstV.G.Z, EstV.A.Z, EstV.GA.Z); //LCD_DisplayStringLine(LINE(2), (uint8_t*)" Ming6842 @ github"); //terminalWrite(lcd_text_main); //PRINT_USART(); //f.print = 0; //} } while(1); // Don't want to exit }