Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison hw.c @ 10:0b75cff7c570
Add _usleep16 - sleeps for cnt microseconds.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 06 Feb 2012 23:54:36 +1030 |
parents | 58d76cf522ff |
children | 96c345d304af |
comparison
equal
deleted
inserted
replaced
9:be0a1ac64d97 | 10:0b75cff7c570 |
---|---|
1 #include <stdint.h> | 1 #include <stdint.h> |
2 #include <stdio.h> | |
2 #include "stm32f10x.h" | 3 #include "stm32f10x.h" |
3 #include "lcd.h" | 4 #include "lcd.h" |
4 | 5 |
5 static void hw_port_cfg(void); | 6 static void hw_port_cfg(void); |
6 | 7 |
8 /* Wait for cnt microseconds */ | |
9 void _usleep16(uint16_t cnt) { | |
10 TIM6->ARR = cnt; | |
11 TIM_SetCounter(TIM6, 0); | |
12 TIM_Cmd(TIM6, ENABLE); | |
13 while ((TIM6->CR1 & TIM_CR1_CEN) != 0) | |
14 ; | |
15 | |
16 } | |
7 | 17 |
8 void hw_init(void) { | 18 void hw_init(void) { |
9 hw_port_cfg(); | 19 hw_port_cfg(); |
10 lcd_init(); | 20 lcd_init(); |
11 lcd_setpwm(1000); | 21 lcd_setpwm(1000); |
257 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; | 267 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; |
258 SPI_InitStructure.SPI_CRCPolynomial = 7; | 268 SPI_InitStructure.SPI_CRCPolynomial = 7; |
259 SPI_Init(SPI1, &SPI_InitStructure); | 269 SPI_Init(SPI1, &SPI_InitStructure); |
260 | 270 |
261 /* SPI1 enable */ | 271 /* SPI1 enable */ |
262 SPI_Cmd(SPI1, ENABLE); | 272 SPI_Cmd(SPI1, ENABLE); |
273 | |
274 /* Configure TIM6 for interval timing */ | |
275 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); | |
276 | |
277 /* Reset TIM6 */ | |
278 TIM_DeInit(TIM6); | |
279 | |
280 /* Time Base configuration */ | |
281 TIM_TimeBaseStructure.TIM_Period = 0; | |
282 TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 1000000) - 1; /* 1 MHz clock */ | |
283 TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); | |
284 | |
285 TIM_Cmd(TIM6, DISABLE); | |
286 | |
287 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; | |
288 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
289 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
290 GPIO_Init(GPIOE, &GPIO_InitStructure); | |
291 | |
292 TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single); | |
293 TIM_UpdateDisableConfig(TIM6, DISABLE); | |
294 | |
263 } | 295 } |