# HG changeset patch # User Daniel O'Connor # Date 1328534676 -37800 # Node ID 0b75cff7c570052d3d6d7dee84fab17d65a04819 # Parent be0a1ac64d9757c08f82214a4c2df241c3561992 Add _usleep16 - sleeps for cnt microseconds. diff -r be0a1ac64d97 -r 0b75cff7c570 hw.c --- a/hw.c Sun Feb 05 16:41:42 2012 +1030 +++ b/hw.c Mon Feb 06 23:54:36 2012 +1030 @@ -1,9 +1,19 @@ #include +#include #include "stm32f10x.h" #include "lcd.h" static void hw_port_cfg(void); +/* Wait for cnt microseconds */ +void _usleep16(uint16_t cnt) { + TIM6->ARR = cnt; + TIM_SetCounter(TIM6, 0); + TIM_Cmd(TIM6, ENABLE); + while ((TIM6->CR1 & TIM_CR1_CEN) != 0) + ; + +} void hw_init(void) { hw_port_cfg(); @@ -259,5 +269,27 @@ SPI_Init(SPI1, &SPI_InitStructure); /* SPI1 enable */ - SPI_Cmd(SPI1, ENABLE); + SPI_Cmd(SPI1, ENABLE); + + /* Configure TIM6 for interval timing */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); + + /* Reset TIM6 */ + TIM_DeInit(TIM6); + + /* Time Base configuration */ + TIM_TimeBaseStructure.TIM_Period = 0; + TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 1000000) - 1; /* 1 MHz clock */ + TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); + + TIM_Cmd(TIM6, DISABLE); + + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; + GPIO_Init(GPIOE, &GPIO_InitStructure); + + TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single); + TIM_UpdateDisableConfig(TIM6, DISABLE); + }