Simple "hello world" style program for X-NUCLEO-IKS01A1 MEMS Inertial
Dependencies: BLE_API X_NUCLEO_IDB0XA1 X_NUCLEO_IKS01A1 mbed
Fork of HelloWorld_IKS01A1 by
led_RGB.c@8:1c6281289d67, 2015-11-15 (annotated)
- Committer:
- n0tform3
- Date:
- Sun Nov 15 09:00:40 2015 +0000
- Revision:
- 8:1c6281289d67
test with led
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
n0tform3 | 8:1c6281289d67 | 1 | #include "led_RGB.h" |
n0tform3 | 8:1c6281289d67 | 2 | #include "stm32f4xx_conf.h" |
n0tform3 | 8:1c6281289d67 | 3 | #include "stm32f4xx.h" |
n0tform3 | 8:1c6281289d67 | 4 | #include "main.h" |
n0tform3 | 8:1c6281289d67 | 5 | |
n0tform3 | 8:1c6281289d67 | 6 | void Blue_Red_Setup(void) |
n0tform3 | 8:1c6281289d67 | 7 | { |
n0tform3 | 8:1c6281289d67 | 8 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
n0tform3 | 8:1c6281289d67 | 9 | TIM_OCInitTypeDef TIM_OCInitStructure; |
n0tform3 | 8:1c6281289d67 | 10 | GPIO_InitTypeDef GPIO_InitStructure; |
n0tform3 | 8:1c6281289d67 | 11 | |
n0tform3 | 8:1c6281289d67 | 12 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_TIM4); |
n0tform3 | 8:1c6281289d67 | 13 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_TIM3); |
n0tform3 | 8:1c6281289d67 | 14 | GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_TIM3); |
n0tform3 | 8:1c6281289d67 | 15 | |
n0tform3 | 8:1c6281289d67 | 16 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_6; |
n0tform3 | 8:1c6281289d67 | 17 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; |
n0tform3 | 8:1c6281289d67 | 18 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; |
n0tform3 | 8:1c6281289d67 | 19 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; |
n0tform3 | 8:1c6281289d67 | 20 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; |
n0tform3 | 8:1c6281289d67 | 21 | GPIO_Init(GPIOB, &GPIO_InitStructure); |
n0tform3 | 8:1c6281289d67 | 22 | |
n0tform3 | 8:1c6281289d67 | 23 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; |
n0tform3 | 8:1c6281289d67 | 24 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
n0tform3 | 8:1c6281289d67 | 25 | TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (RealSysClock / 50000) - 1; |
n0tform3 | 8:1c6281289d67 | 26 | TIM_TimeBaseStructure.TIM_Period = 255; //f = 0.25KHz |
n0tform3 | 8:1c6281289d67 | 27 | TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; |
n0tform3 | 8:1c6281289d67 | 28 | TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); |
n0tform3 | 8:1c6281289d67 | 29 | |
n0tform3 | 8:1c6281289d67 | 30 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; |
n0tform3 | 8:1c6281289d67 | 31 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; |
n0tform3 | 8:1c6281289d67 | 32 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; |
n0tform3 | 8:1c6281289d67 | 33 | TIM_OCInitStructure.TIM_Pulse = 150; //registro confrontato con oc |
n0tform3 | 8:1c6281289d67 | 34 | TIM_OC3Init(TIM3, &TIM_OCInitStructure); |
n0tform3 | 8:1c6281289d67 | 35 | |
n0tform3 | 8:1c6281289d67 | 36 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; |
n0tform3 | 8:1c6281289d67 | 37 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; |
n0tform3 | 8:1c6281289d67 | 38 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; |
n0tform3 | 8:1c6281289d67 | 39 | TIM_OCInitStructure.TIM_Pulse = 150; //registro confrontato con oc |
n0tform3 | 8:1c6281289d67 | 40 | TIM_OC4Init(TIM3, &TIM_OCInitStructure); |
n0tform3 | 8:1c6281289d67 | 41 | |
n0tform3 | 8:1c6281289d67 | 42 | TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); |
n0tform3 | 8:1c6281289d67 | 43 | TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable); |
n0tform3 | 8:1c6281289d67 | 44 | |
n0tform3 | 8:1c6281289d67 | 45 | } |
n0tform3 | 8:1c6281289d67 | 46 | |
n0tform3 | 8:1c6281289d67 | 47 | void Green_Setup(void) |
n0tform3 | 8:1c6281289d67 | 48 | { |
n0tform3 | 8:1c6281289d67 | 49 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; |
n0tform3 | 8:1c6281289d67 | 50 | TIM_OCInitTypeDef TIM_OCInitStructure; |
n0tform3 | 8:1c6281289d67 | 51 | |
n0tform3 | 8:1c6281289d67 | 52 | TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; |
n0tform3 | 8:1c6281289d67 | 53 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; |
n0tform3 | 8:1c6281289d67 | 54 | TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t) (RealSysClock / 50000) - 1; |
n0tform3 | 8:1c6281289d67 | 55 | TIM_TimeBaseStructure.TIM_Period = 255; //f = 0.25KHz |
n0tform3 | 8:1c6281289d67 | 56 | TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; |
n0tform3 | 8:1c6281289d67 | 57 | TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); |
n0tform3 | 8:1c6281289d67 | 58 | |
n0tform3 | 8:1c6281289d67 | 59 | TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; |
n0tform3 | 8:1c6281289d67 | 60 | TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; |
n0tform3 | 8:1c6281289d67 | 61 | TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; |
n0tform3 | 8:1c6281289d67 | 62 | TIM_OCInitStructure.TIM_Pulse = 150; //registro confrontato con oc |
n0tform3 | 8:1c6281289d67 | 63 | TIM_OC1Init(TIM4, &TIM_OCInitStructure); |
n0tform3 | 8:1c6281289d67 | 64 | |
n0tform3 | 8:1c6281289d67 | 65 | TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable); |
n0tform3 | 8:1c6281289d67 | 66 | |
n0tform3 | 8:1c6281289d67 | 67 | TIM_Cmd (TIM4, ENABLE); |
n0tform3 | 8:1c6281289d67 | 68 | TIM_Cmd (TIM3, ENABLE); |
n0tform3 | 8:1c6281289d67 | 69 | |
n0tform3 | 8:1c6281289d67 | 70 | } |
n0tform3 | 8:1c6281289d67 | 71 |