Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison hw.c @ 13:96c345d304af
Add 1wire code.
1wire.c, 1wire.h and 1wire-config.h are copied avr-lib.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 08 Feb 2012 10:37:22 +1030 |
parents | 0b75cff7c570 |
children | afdd22502c2a |
comparison
equal
deleted
inserted
replaced
12:093bc0c3b1cc | 13:96c345d304af |
---|---|
1 #include <stdint.h> | 1 #include <stdint.h> |
2 #include <stdio.h> | 2 #include <stdio.h> |
3 #include "stm32f10x.h" | 3 #include "stm32f10x.h" |
4 | |
5 #include "1wire.h" | |
4 #include "lcd.h" | 6 #include "lcd.h" |
5 | 7 |
6 static void hw_port_cfg(void); | 8 static void hw_port_cfg(void); |
7 | 9 |
8 /* Wait for cnt microseconds */ | 10 /* Wait for cnt microseconds */ |
9 void _usleep16(uint16_t cnt) { | 11 void |
10 TIM6->ARR = cnt; | 12 _usleep16(uint16_t cnt) { |
13 TIM6->ARR = cnt > 3 ? cnt - 3 : cnt; | |
11 TIM_SetCounter(TIM6, 0); | 14 TIM_SetCounter(TIM6, 0); |
12 TIM_Cmd(TIM6, ENABLE); | 15 TIM_Cmd(TIM6, ENABLE); |
13 while ((TIM6->CR1 & TIM_CR1_CEN) != 0) | 16 while ((TIM6->CR1 & TIM_CR1_CEN) != 0) |
14 ; | 17 ; |
15 | |
16 } | 18 } |
17 | 19 |
18 void hw_init(void) { | 20 void |
21 hw_init(void) { | |
19 hw_port_cfg(); | 22 hw_port_cfg(); |
20 lcd_init(); | 23 lcd_init(); |
21 lcd_setpwm(1000); | 24 lcd_setpwm(1000); |
22 } | 25 } |
23 | 26 |
277 /* Reset TIM6 */ | 280 /* Reset TIM6 */ |
278 TIM_DeInit(TIM6); | 281 TIM_DeInit(TIM6); |
279 | 282 |
280 /* Time Base configuration */ | 283 /* Time Base configuration */ |
281 TIM_TimeBaseStructure.TIM_Period = 0; | 284 TIM_TimeBaseStructure.TIM_Period = 0; |
282 TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 1000000) - 1; /* 1 MHz clock */ | 285 TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 2 / 1000000) - 1; /* 1 MHz clock */ |
283 TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); | 286 TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); |
284 | 287 |
285 TIM_Cmd(TIM6, DISABLE); | 288 TIM_Cmd(TIM6, DISABLE); |
286 | 289 |
287 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; | 290 /* Setup for single pulse mode clear UDIS */ |
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); | 291 TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single); |
293 TIM_UpdateDisableConfig(TIM6, DISABLE); | 292 TIM_UpdateDisableConfig(TIM6, DISABLE); |
294 | 293 |
294 /* Setup GPIO for 1-wire */ | |
295 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; | |
296 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; | |
297 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; | |
298 GPIO_Init(GPIOE, &GPIO_InitStructure); | |
299 | |
300 OWInit(); | |
301 | |
302 #if 0 | |
303 while (1) { | |
304 GPIO_SetBits(GPIOE, GPIO_Pin_2); | |
305 _usleep16(10); | |
306 GPIO_ResetBits(GPIOE, GPIO_Pin_2); | |
307 _usleep16(20); | |
308 GPIO_SetBits(GPIOE, GPIO_Pin_2); | |
309 _usleep16(30); | |
310 GPIO_ResetBits(GPIOE, GPIO_Pin_2); | |
311 _usleep16(100); | |
312 } | |
313 #endif | |
295 } | 314 } |