From 1702ce6ce430a66bb7af51644b91b7c196e719d9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 29 Jun 2022 11:03:02 +0300 Subject: =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D1=8E=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B9.=20=D0=9F=D1=80=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BC=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D0=B8=20NixieClock=5Fv2.=20=D0=A0=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=8B=20=D1=82=D0=B8=D0=BA=D0=B0=D1=8E=D1=82.=20=D0=95=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0?= =?UTF-8?q?,=20=D1=87=D1=82=D0=BE=20=D1=81=D0=BA=D0=B0=D1=87=D0=B5=D1=82?= =?UTF-8?q?=20=D0=B2=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=81=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=80=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=D0=B0=20(=D0=BE=D0=BD=D0=B0=20=D0=B2=20=D0=B4=D1=80?= =?UTF-8?q?=D1=83=D0=B3=D0=BE=D0=BC=20=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?).=20=D0=9F=D0=BE=D1=8D=D1=82=D0=BE=D0=BC=D1=83=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=B5=20=D1=81=D0=BE=D0=B1=D0=B8=D1=80=D0=B0?= =?UTF-8?q?=D1=8E=D1=81=D1=8C=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B0=D0=BD=D1=82=D0=B8=D0=B4=D1=80=D0=B5=D0=B1=D0=B5=D0=B7?= =?UTF-8?q?=D0=B3.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Libraries/LED_Driver/led_driver_config.c | 184 +++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 Libraries/LED_Driver/led_driver_config.c (limited to 'Libraries/LED_Driver/led_driver_config.c') diff --git a/Libraries/LED_Driver/led_driver_config.c b/Libraries/LED_Driver/led_driver_config.c new file mode 100644 index 0000000..d2df9d4 --- /dev/null +++ b/Libraries/LED_Driver/led_driver_config.c @@ -0,0 +1,184 @@ +#include "led_driver_config.h" + +static void LED_TIMConfig ( void ); +static void LED_SPIConfig ( void ); + +// ---------------------------------------------------------------------------- +// Подготовка железа, прерываний и тд для работы с RGB светодиодиками +// ---------------------------------------------------------------------------- +void LED_Driver_Config ( void ) +{ + LED_TIMConfig (); + LED_SPIConfig (); +} + + +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +static void LED_TIMConfig ( void ) +{ + NVIC_InitTypeDef NVIC_InitStructure; + TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; + + /* LED_TIMx clock enable */ + LED_RCC_APBxPeriphClockCmd ( LED_TIM_RCC, ENABLE ); + + /* Enable the LED_TIMx gloabal Interrupt */ + NVIC_InitStructure.NVIC_IRQChannel = LED_TIM_IRQx; + NVIC_InitStructure.NVIC_IRQChannelPriority = 2; // Установим приоритет ниже, чем у модуля NixieDriver + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init ( &NVIC_InitStructure ); + + /* ----------------------------------------------------------------------- + In this example TIM7 counter clock (TIM7CLK) is set to APB1 clock (PCLK1), since + APB1 prescaler is set to 1 and TIM7 prescaler is set to 0. + + In this example TIM7 input clock (TIM7CLK) is set to APB1 clock (PCLK1), + since APB1 prescaler is set to 1. + TIM7CLK = PCLK1 = HCLK = SystemCoreClock + + With Prescaler set to 479 and Period to 24999, the TIM7 counter is updated each 250 ms + (i.e. and interrupt is generated each 250 ms) + TIM7 counter clock = TIM7CLK /((Prescaler + 1)*(Period + 1)) + = 48 MHz / ((25000)*(480)) + = 4 Hz + ==> TIM7 counter period = 250 ms + + Note: + SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f0xx.c file. + Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate() + function to update SystemCoreClock variable value. Otherwise, any configuration + based on this variable will be incorrect. + ----------------------------------------------------------------------- */ + + /* Time base configuration */ + TIM_TimeBaseStructure.TIM_Period = 1000; // Это миксросекунды //24999 + TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock/1000000)-1; //479; + TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; + TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; + //TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; + TIM_TimeBaseInit ( LED_TIMx, &TIM_TimeBaseStructure ); + + /* LED_TIMx Interrupts enable */ + TIM_ITConfig ( LED_TIMx, TIM_IT_Update, ENABLE ); + + /* LED_TIMx enable counter */ + TIM_Cmd ( LED_TIMx, ENABLE ); +} + + +// ---------------------------------------------------------------------------- +// +// ---------------------------------------------------------------------------- +static void LED_SPIConfig ( void ) +{ + GPIO_InitTypeDef GPIO_InitStructure; + SPI_InitTypeDef SPI_InitStructure; + NVIC_InitTypeDef NVIC_InitStructure; + + /* Enable the SPI periph */ + LED_SPIx_RCC_APBxPeriphClockCmd ( LED_SPIx_CLK, ENABLE ); + + /* Enable SCK, MOSI, MISO and NSS GPIO clocks */ + RCC_AHBPeriphClockCmd ( LED_SPIx_SCK_GPIO_CLK | + LED_SPIx_MOSI_GPIO_CLK | + LED_SPIx_ST_GPIO_CLK, + ENABLE ); + + GPIO_PinAFConfig ( LED_SPIx_SCK_GPIO_PORT, LED_SPIx_SCK_SOURCE, LED_SPIx_SCK_AF ); + GPIO_PinAFConfig ( LED_SPIx_MOSI_GPIO_PORT, LED_SPIx_MOSI_SOURCE, LED_SPIx_MOSI_AF ); + //GPIO_PinAFConfig ( LED_SPIx_ST_GPIO_PORT, LED_SPIx_ST_SOURCE, LED_SPIx_ST_AF ); + + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + + /* SPI SCK pin configuration */ + GPIO_InitStructure.GPIO_Pin = LED_SPIx_SCK_PIN; + GPIO_Init ( LED_SPIx_SCK_GPIO_PORT, &GPIO_InitStructure ); + + /* SPI MOSI pin configuration */ + GPIO_InitStructure.GPIO_Pin = LED_SPIx_MOSI_PIN; + GPIO_Init ( LED_SPIx_MOSI_GPIO_PORT, &GPIO_InitStructure ); + + /* GPIO ST pin configuration */ + GPIO_InitStructure.GPIO_Pin = LED_SPIx_ST_PIN; + //GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + GPIO_Init ( LED_SPIx_ST_GPIO_PORT, &GPIO_InitStructure ); + + /* SPI configuration -------------------------------------------------------*/ + SPI_I2S_DeInit ( LED_SPIx ); + //SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx; //SPI_Direction_2Lines_FullDuplex + SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; + SPI_InitStructure.SPI_DataSize = SPI_DataSize_16b; + SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; + SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; + SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; + SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64; + SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; + SPI_InitStructure.SPI_CRCPolynomial = 7; + SPI_InitStructure.SPI_Mode = SPI_Mode_Master; + SPI_Init ( LED_SPIx, &SPI_InitStructure ); + + /* Enable the SPI peripheral */ + SPI_Cmd ( LED_SPIx, ENABLE ); + + /* Configure the SPI interrupt priority */ + NVIC_InitStructure.NVIC_IRQChannel = LED_SPIx_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPriority = 0; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init ( &NVIC_InitStructure ); + + /* Enable the Rx buffer not empty interrupt */ + SPI_I2S_ITConfig ( LED_SPIx, SPI_I2S_IT_RXNE, ENABLE ); + + LED_ST_PIN_RESET; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3