Thomas Kolb
2f0f6a01f2
This version uses only blocking i2c calls, and long transfers will probably cause frame loss. Also, if no BMP280 is present, the firmware will not start up and hang in an endless loop instead.
36 lines
916 B
C
36 lines
916 B
C
#include <libopencm3/stm32/rcc.h>
|
|
|
|
#include "clock.h"
|
|
#include "libopencm3/stm32/f0/rcc.h"
|
|
|
|
void init_clock(void)
|
|
{
|
|
/* Set STM32 to 48 MHz. */
|
|
rcc_clock_setup_in_hse_8mhz_out_48mhz(); // generate 48 MHz from external 8 MHz crystal
|
|
//rcc_clock_setup_in_hsi_out_48mhz(); // generate ~48 MHz from internal RC oscillator
|
|
|
|
// enable TIM1 for PWM generation
|
|
rcc_periph_clock_enable(RCC_TIM1);
|
|
|
|
// enable GPIO clocks:
|
|
// Port A is needed for the charge pump, extension port and analog input
|
|
rcc_periph_clock_enable(RCC_GPIOA);
|
|
|
|
// Port B is needed for the LEDs
|
|
rcc_periph_clock_enable(RCC_GPIOB);
|
|
|
|
// USART1 is used for RS485
|
|
rcc_periph_clock_enable(RCC_USART1);
|
|
|
|
// ADC1 for analog measuremnts
|
|
rcc_periph_clock_enable(RCC_ADC1);
|
|
|
|
// DMA1 is used for ADC data transfer
|
|
rcc_periph_clock_enable(RCC_DMA1);
|
|
|
|
// I2C1 is used for communication with the BMP280
|
|
rcc_periph_clock_enable(RCC_I2C1);
|
|
}
|
|
|
|
|