Mundarija:
- 1 -qadam: Uskuna
- 2 -qadam: qurish
- 3 -qadam: Dasturlar
- 4 -qadam: Kod haqida
- 5 -qadam: Asosiy.h
- 6 -qadam: Main.c
Video: To'rt bitli osiloskop: 6 qadam
2024 Muallif: John Day | [email protected]. Oxirgi o'zgartirilgan: 2024-01-30 13:26
MAX7219 nuqtali matritsali displeyni qanchalik tez surishim mumkinligini ko'rish uchun bu shunchaki qiziqarli loyihadir. Va men uni "hayot o'yini" bilan shug'ullanishning o'rniga, men u bilan "ko'lam" tuzishga qaror qildim. Sarlavhadan tushunganingizdek, bu haqiqiy osiloskopning o'rnini bosmaydi:-).
Men bundan jiddiy foydalanishni rejalashtirmaganim uchun, men unga bosma elektron karta yasamayman. Balki, ehtimol men uni taxtaga qo'yaman, lekin hozircha u non taxtasida qoladi va qoladi. Bundan tashqari, kirish kuchaytirgichi/susaytirgichi yo'q, siz 0 dan 3,3 V gacha signal berishingiz kerak, salbiy yoki 3,3 V dan oshmang, chunki siz mikrokontrollerga zarar etkazishingiz mumkin.
1 -qadam: Uskuna
Ebay yoki shunga o'xshash saytlar orqali Xitoyda ehtiyot qismlarni sotib olsangiz, bu juda arzon. U STM32F103C8 ishlab chiqish kartasini ishlatadi, uni ba'zida "ko'k tabletka" deb atashadi, men uni taxminan 2 evroga sotib oldim (yoki AQSh dollari, ular deyarli bir xil, 2018 yil oxiri), ikkita 8x8x4 o'lchamli MAX7219 chipli displeyli displey. Bir parcha 5 evro va taxminan 1 evrolik aylanadigan kodlovchi.
Albatta, bir necha yuz milliamperda 3,3V kuchlanishli quvvat manbai kerak. STM32F103C8 ishlab chiqish platasidagi voltaj regulyatori ishlatilmayapti, u displeylar uchun etarli oqim bera olmaydi. MAX7219 ma'lumot varag'i ish kuchlanishining 4,0 dan 5,5 V gacha bo'lishi kerakligini bildiradi, lekin u 3,3 V da yaxshi ishlaydi, ehtimol siz uni juda issiq yoki sovuq muhitda ishlatmagansiz, lekin 20 Tselsiy bo'yicha yaxshi. Va endi men mikrokontroller va displeylar orasidagi darajali konvertorlardan foydalanishim shart emas.
2 -qadam: qurish
Rasmga qaraganingizda, men non panelidagi elektr uzatish liniyalaridan noan'anaviy tarzda foydalanayotganimni ko'rishingiz mumkin, yuqoridagi ikkala chiziq ham musbat, pastki qismi ham er osti temiridir. Bu men uchun odatiy usuldir va u yaxshi ishlaydi, bu sozlamalarni men chizgan sxemalarga o'xshatadi. Bundan tashqari, men juda ko'p kichik taxtalarni yasadim, ular ustida ishlarni tezlashtirish uchun non paneliga ulashim mumkin va ularning hammasi ikkita yuqori chiziqni musbat, pastki chizig'ini esa er sifatida ishlatish uchun tuzilgan. Aytganimdek, piksellar sonini 4 bit (16 darajali) va yonida 4x8 diodli lampalar bo'lgani uchun 32 ta namuna punkti bor. Buni Rigol Rigol DS1054Z (8 bit va 12Mpts) bilan solishtiring, shunda siz o'yinchoq emasligini ko'rasiz. Haqiqiy tarmoqli kengligi nima, bilmayman, men uni 10 kHz gacha sinab ko'rdim va bu yaxshi ishlaydi.
3 -qadam: Dasturlar
Men foydalanadigan IDE-bu Atollic TrueStudio, bu yil boshida (2018) ST Micro Electronics tomonidan qabul qilingan va bepul, vaqt chegarasi, kod o'lchami chegarasi, nag-ekranlar mavjud. U bilan birga men STM32CubeMX dasturidan foydalanaman, u menga boshlang'ich kodni etkazib beradi va barcha tashqi qurilmalarni ishga tushiradi. Va u mikrokontrollerning barcha pimlari va ulardan foydalanish displeyiga ega. Agar siz kod ishlab chiqarish uchun STM32CubeMX -dan foydalanmasangiz ham, bu juda qulay, menga yoqmagan narsa - bu HAL deb nomlangan STM32CubeMX standarti. Men LowLayer ishlash usulini afzal ko'raman.
Mikrokontrollerni dasturlash uchun men ST Micro Electronics-dan ST-Link dasturchisi/tuzatuvchisidan yoki Segger tomonidan ishlab chiqarilgan J-Linkdan foydalanaman. Bu ikkala qurilma ham bepul emas, lekin siz ularning xitoycha nusxalarini bir necha evroga sotib olishingiz mumkin.
4 -qadam: Kod haqida
MAX7219 -ning LEDlari gorizontal deb nomlangan, bir -birining yonida 8 ta LED. Osiloskop uchun 8 ta LEDni bir-birining ustiga qo'yish osonroq bo'lardi, shuning uchun men ma'lumotlar bilan vertikal tarzda yozilgan va kerakli gorizontal tarzda o'qiladigan oddiy ramka-bufer yasadim. MAX7219 8 LED uchun 16 bitli koddan foydalanadi, bu erda birinchi bayt tanlangan qatorga murojaat qilish uchun ishlatiladi. Va bu modullarning to'rttasi yonma -yon joylashtirilganligi sababli, ularning kirishlari modulning chiqishlariga ulangan bo'lsa, oxirgi modulga o'tish uchun siz 16 bitni to'rt marta yuborishingiz kerak. (Umid qilamanki, men hamma narsani tushuntirib beraman …) Ma'lumotlar MAX7219 ga SPI, oddiy, lekin juda tez protokoli yordamida yuboriladi. Bu men tajriba o'tkazgan narsadir, ma'lumotlarni MAX7219 -ga qanchalik tez yuborish mumkin. Oxir -oqibat, men ma'lumotlar jadvalida ko'rsatilgan maksimal tezlikdan past bo'lgan 9 MGts ga qaytdim.
Men STM32F103C8 mavjud to'rtta taymerdan ikkitasini ishlataman, biri vaqt bazasini yaratish uchun, ikkinchisi vaqt bazasini o'rnatadigan aylanadigan kodlovchi o'qish uchun. TIMER3 vaqt bazasini yaratadi, u soatni 230 ga bo'lish orqali, hisoblagichni har 3,2 ussda yangilab turadi. Hisoblagichni 2 soatlik impulsdan 2000 soatgacha pulsatsiyaga qadar tanlashingiz mumkin aylanadigan kodlovchi. Aytaylik, siz 100 ni tanladingiz. TIMER3 har 320 uS da VOQEA yaratadi. Bu EVENT kirish signalining namunasini yozib olish uchun ADCni ishga tushiradi va 32 ta namunani bitta skrining uchun olish kerak, bu taxminan keyin tugaydi. 10 mS. 10mSda siz bitta to'lqin uzunligini 100 Gts yoki 200 Gtsning ikkitasini va boshqalarni sig'dira olasiz. Har bir ekran uchun 3 ta to'lqinni bosib o'tish to'lqin shaklini tanib olishni qiyinlashtiradi.
Qolganlari uchun men sizni faqat kodga havola qila olaman, agar siz Arduino bilan tajribaga ega bo'lsangiz ham, amal qilish qiyin emas. Aslida, siz xuddi shunday narsani Arduino bilan qilishingiz mumkin edi, lekin men uning "ko'k tabletka" kabi tez ishlashiga shubha qilaman. STM32F103C8 - bu 72 MGts chastotada ishlaydigan 32 bitli mikrokontrolder, u ikkita SPI periferiya va juda tez ADCga ega.
5 -qadam: Asosiy.h
#ifndef _ MAIN_H _#_MAIN_H_ ni belgilang
#"stm32f1xx_ll_adc.h" ni qo'shing
#include "stm32f1xx_ll_rcc.h" #include "stm32f1xx_ll_bus.h" #include "stm32f1xx_ll_system.h" #include "stm32f1xx_ll_exti.h" #include "stm32f1xxlxxl_cort_fortx" o'z ichiga "stm32f1xx_ll_dma.h" #include "stm32f1xx_ll_spi.h" #include "stm32f1xx_ll_tim.h" #include "stm32f1xx.h" #include "stm32f1xx_ll_gpio.h"
#ifndef NVIC_PRIORITYGROUP_0
#define NVIC_PRIORITYGROUP_0 ((uint32_t) 0x00000007) #define NVIC_PRIORITYGROUP_1 ((uint32_t) 0x00000006) #define NVIC_PRIORITYGROUP_2 ((uint32_t) 0x00000005) #define NVIC_PRIORITYGROUP_3 ((uint32_t) 0x00000004) #define NVIC_PRIORITYGROUP_4 ((uint32_t) 0x00000003) #endif
#ifdef _cplusplus
extern "C" {#endif void _Error_Handler (char *, int);
#define Error_Handler () _Error_Handler (_ FILE_, _LINE_)
#ifdef _cplusplus} #endif
#endif
6 -qadam: Main.c
#inclite "main.h" statik bo'shligi LL_Init (void); bo'sh SystemClock_Config (bo'sh); statik bo'shliq MX_GPIO_Init (bo'sh); statik bo'shliq MX_ADC1_Init (bo'sh); statik bo'shliq MX_SPI1_Init (bo'sh); statik bo'shliq MX_SPI2_Init (bo'sh); statik bo'shliq MX_TIM3_Init (bo'sh); statik bo'shliq MX_TIM4_Init (bo'sh);
uint16_t SPI1_send64 (uint16_t ma'lumotlar3, uint16_t ma'lumotlar2, uint16_t ma'lumotlar1, uint16_t ma'lumotlar0);
uint16_t SPI2_send64 (uint16_t ma'lumotlar3, uint16_t ma'lumotlar2, uint16_t ma'lumotlar1, uint16_t ma'lumotlar0); bekor MAX7219_1_init (); bekor MAX7219_2_init (); bo'sh erase_frame_buffer (bekor); to'ldirish_frame_buferi bo'sh (bo'sh); bo'sh ekran_frame_buffer (bo'sh); void set_timebase (bekor);
uint8_t yuqori_tasvir [4] [8]; // vier bayt naast elkaar, acht onder elkaar
uint8_t pastki_tasvir [4] [8]; // ramka-tampon
uint8_t sample_buffer [32]; // ADC natijalari bo'yicha bufer
int main (bekor)
{LL_Init (); SystemClock_Config (); MX_GPIO_Init (); MX_ADC1_Init (); MX_SPI1_Init (); MX_SPI2_Init (); MX_TIM3_Init (); MX_TIM4_Init ();
LL_SPI_Enable (SPI1);
LL_SPI_Enable (SPI2);
LL_TIM_EnableCounter (TIM3);
LL_TIM_EnableCounter (TIM4);
LL_ADC_Enable (ADC1);
LL_ADC_REG_StartConversionSWStart (ADC1); LL_ADC_EnableIT_EOS (ADC1);
LL_mDelay (500); // MAX7219 ga quvvat yoqilgandan keyin biroz vaqt kerak
MAX7219_1_init (); MAX7219_2_init ();
// LL_TIM_SetAutoReload (TIM3, 9);
vaqt (1)
{set_timebase (); erase_frame_buffer (); to'ldirish_frame_buffer (); displey_frame_buffer (); }}
bo'sh erase_frame_buffer (bekor)
{int8_t x; int8_t y;
uchun (x = 0; x <4; x ++) // kolom_bytes {
uchun (y = 0; y <8; y ++) // lijnen {top_display [x] [y] = 0; // hamma narsa pastki_displayda mavjud emas [x] [y] = 0; }}}
bo'sh_fare_buffer (bekor)
{uint8_t y = 0; // kuchlanish uint8_t tijd = 0; // tijd uint8_t display_byte; // otlar 8 bitga teng emas, balki 4 ta ma'lumotga ko'ra, u_88_t display_bit;
uchun (tijd = 0; tijd <32; tijd ++) {display_byte = tijd / 8; display_bit = 7 - (% 8);
y = namuna_bufer [tijd];
if (y> 7) // yuqori displeyda schrijven
{yuqori_display [display_byte] [15-y] | = (1 << display_bit); } else // pastki displeyda schrijven {pastki_display [display_byte] [7-y] | = (1 << display_bit); }}}
void display_frame_buffer (bekor)
{
uint8_t y; // acht lijnen boven elkaar (displey uchun) uint16_t yl; // MAX7219 haqida ma'lumot
uchun (y = 0; y <8; y ++) {yl = (y+1) << 8; // MAX7219 yuqori 8 -bitli 16 -bitli woord -da
SPI2_send64 ((yl | yuqori_tasvir [0] [y]), (yl | yuqori_shakl [1] [y]), (yl | yuqori_shakl [2] [y]), (yl | yuqori_shakl [3] [y]));
SPI1_send64 ((yl | pastki_shakl [0] [y]), (yl | pastki_shakl [1] [y]), (yl | pastki_shakl [2] [y]), (yl | pastki_shakl [3] [y])); }
}
void set_timebase (bekor)
{uint8_t timebase_knop;
timebase_knop = LL_TIM_GetCounter (TIM4) / 2;
tugma (vaqt bazasi tugmasi)
{0 holat: LL_TIM_SetAutoReload (TIM3, 1999); tanaffus; 1 -holat: LL_TIM_SetAutoReload (TIM3, 999); tanaffus; 2 -holat: LL_TIM_SetAutoReload (TIM3, 499); tanaffus; 3 -holat: LL_TIM_SetAutoReload (TIM3, 199); tanaffus; 4 -holat: LL_TIM_SetAutoReload (TIM3, 99); tanaffus; 5 -holat: LL_TIM_SetAutoReload (TIM3, 49); tanaffus; 6 -holat: LL_TIM_SetAutoReload (TIM3, 19); tanaffus; 7 -holat: LL_TIM_SetAutoReload (TIM3, 9); tanaffus; 8 -holat: LL_TIM_SetAutoReload (TIM3, 4); tanaffus; 9 -holat: LL_TIM_SetAutoReload (TIM3, 1); tanaffus;
standart:
LL_TIM_SetAutoReload (TIM3, 99); tanaffus; }}
bekor MAX7219_1_init ()
{SPI1_send64 (0x0000, 0x0000, 0x0000, 0x0000); // yo'q SPI1_send64 (0x0C00, 0x0C00, 0x0C00, 0x0C00); // SPI1_send64 -ni o'chirish (0x0000, 0x0000, 0x0000, 0x0000); // yo'q SPI1_send64 (0x0F00, 0x0F00, 0x0F00, 0x0F00); // test rejimi o'chirilgan SPI1_send64 (0x0C01, 0x0C01, 0x0C01, 0x0C01); // o'chirish, normal ishlash SPI1_send64 (0x0900, 0x0900, 0x0900, 0x0900); // 7seg dekodlash yo'q, 64 piksel SPI1_send64 (0x0A07, 0x0A07, 0x0A07, 0x0A07); // intensivlik 50% SPI1_send64 (0x0B07, 0x0B07, 0x0B07, 0x0B07); // barcha qatorlar}
bekor MAX7219_2_init ()
{SPI2_send64 (0x0000, 0x0000, 0x0000, 0x0000); // yo'q SPI2_send64 (0x0C00, 0x0C00, 0x0C00, 0x0C00); // SPI2_send64 -ni o'chirish (0x0000, 0x0000, 0x0000, 0x0000); // yo'q SPI2_send64 (0x0F00, 0x0F00, 0x0F00, 0x0F00); // test rejimi o'chirilgan SPI2_send64 (0x0C01, 0x0C01, 0x0C01, 0x0C01); // o'chirish, normal ishlash SPI2_send64 (0x0900, 0x0900, 0x0900, 0x0900); // 7seg dekodlash yo'q, 64 piksel SPI2_send64 (0x0A07, 0x0A07, 0x0A07, 0x0A07); // intensivlik 50% SPI2_send64 (0x0B07, 0x0B07, 0x0B07, 0x0B07); // barcha qatorlar}
uint16_t SPI1_send64 (uint16_t ma'lumotlar3, uint16_t ma'lumotlar2, uint16_t ma'lumotlar1, uint16_t ma'lumotlar0)
{LL_GPIO_ResetOutputPin (GPIOA, LL_GPIO_PIN_4);
LL_SPI_TransmitData16 (SPI1, ma'lumotlar3);
while (LL_SPI_IsActiveFlag_TXE (SPI1) == 0) {}
LL_SPI_TransmitData16 (SPI1, ma'lumotlar2);
while (LL_SPI_IsActiveFlag_TXE (SPI1) == 0) {}
LL_SPI_TransmitData16 (SPI1, ma'lumotlar1);
while (LL_SPI_IsActiveFlag_TXE (SPI1) == 0) {}
LL_SPI_TransmitData16 (SPI1, ma'lumotlar0);
while (LL_SPI_IsActiveFlag_BSY (SPI1) == 1) {}
LL_GPIO_SetOutputPin (GPIOA, LL_GPIO_PIN_4);
qaytarish LL_SPI_ReceiveData16 (SPI1); }
uint16_t SPI2_send64 (uint16_t ma'lumotlar3, uint16_t ma'lumotlar2, uint16_t ma'lumotlar1, uint16_t ma'lumotlar0)
{LL_GPIO_ResetOutputPin (GPIOB, LL_GPIO_PIN_12);
LL_SPI_TransmitData16 (SPI2, ma'lumotlar3);
while (LL_SPI_IsActiveFlag_TXE (SPI2) == 0) {}
LL_SPI_TransmitData16 (SPI2, ma'lumotlar2);
while (LL_SPI_IsActiveFlag_TXE (SPI2) == 0) {}
LL_SPI_TransmitData16 (SPI2, ma'lumotlar1);
while (LL_SPI_IsActiveFlag_TXE (SPI2) == 0) {}
LL_SPI_TransmitData16 (SPI2, ma'lumotlar0);
while (LL_SPI_IsActiveFlag_BSY (SPI2) == 1) {}
LL_GPIO_SetOutputPin (GPIOB, LL_GPIO_PIN_12);
qaytarish LL_SPI_ReceiveData16 (SPI2); }
bekor ADC1_2_IRQHandler (bekor)
{statik uint8_t sample_counter; uint8_t tetik; statik uint8_t previous_trigger;
agar (LL_ADC_IsActiveFlag_EOS (ADC1)! = RESET)
{if (sample_counter <32) {sample_buffer [sample_counter] = LL_ADC_REG_ReadConversionData32 (ADC1) / 256; if (sample_counter <32) sample_counter ++; boshqa sample_counter = 0; } boshqa {trigger = LL_ADC_REG_ReadConversionData32 (ADC1) / 256;
if ((trigger == 7) && (previous_trigger <trigger)) // hamma narsa blokirovka qilingan … {sample_counter = 0; } previous_trigger = tetik; }
LL_GPIO_TogglePin (GPIOC, LL_GPIO_PIN_13);
LL_ADC_ClearFlag_EOS (ADC1);
} }
statik bo'shliq LL_Init (bo'sh)
{LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_AFIO); LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_PWR);
NVIC_SetPriorityGrouping (NVIC_PRIORITYGROUP_4);
NVIC_SetPriority (MemoryManagement_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (BusFault_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)); NVIC_SetPriority (UsageFault_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)); NVIC_SetPriority (SVCall_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)); NVIC_SetPriority (DebugMonitor_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0))); NVIC_SetPriority (PendSV_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)); NVIC_SetPriority (SysTick_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0));
LL_GPIO_AF_Remap_SWJ_NOJTAG ();
}
void SystemClock_Config (bekor)
{LL_FLASH_SetLatency (LL_FLASH_LATENCY_2); agar (LL_FLASH_GetLatency ()! = LL_FLASH_LATENCY_2) Error_Handler (); LL_RCC_HSE_Enable (); while (LL_RCC_HSE_IsReady ()! = 1); LL_RCC_PLL_ConfigDomain_SYS (LL_RCC_PLLSOURCE_HSE_DIV_1, LL_RCC_PLL_MUL_9); LL_RCC_PLL_Enable (); while (LL_RCC_PLL_IsReady ()! = 1); LL_RCC_SetAHBPrescaler (LL_RCC_SYSCLK_DIV_1); LL_RCC_SetAPB1Prescaler (LL_RCC_APB1_DIV_2); LL_RCC_SetAPB2Prescaler (LL_RCC_APB2_DIV_1); LL_RCC_SetSysClkSource (LL_RCC_SYS_CLKSOURCE_PLL); while (LL_RCC_GetSysClkSource ()! = LL_RCC_SYS_CLKSOURCE_STATUS_PLL); LL_Init1msTick (72000000); LL_SYSTICK_SetClkSource (LL_SYSTICK_CLKSOURCE_HCLK); LL_SetSystemCoreClock (72000000); LL_RCC_SetADCClockSource (LL_RCC_ADC_CLKSRC_PCLK2_DIV_6);
NVIC_SetPriority (SysTick_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0));
}
statik bo'shliq MX_ADC1_Init (bekor)
{LL_ADC_InitTypeDef ADC_InitStruct; LL_ADC_CommonInitTypeDef ADC_CommonInitStruct; LL_ADC_REG_InitTypeDef ADC_REG_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;
LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_ADC1);
GPIO_InitStruct. Pin = LL_GPIO_PIN_0;
GPIO_InitStruct. Mode = LL_GPIO_MODE_ANALOG; LL_GPIO_Init (GPIOA, & GPIO_InitStruct);
NVIC_SetPriority (ADC1_2_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0));
NVIC_EnableIRQ (ADC1_2_IRQn);
ADC_InitStruct. DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
ADC_InitStruct. SequencersScanMode = LL_ADC_SEQ_SCAN_DISABLE; LL_ADC_Init (ADC1, & ADC_InitStruct);
ADC_CommonInitStruct. Multimode = LL_ADC_MULTI_INDEPENDENT;
LL_ADC_CommonInit (_ LL_ADC_COMMON_INSTANCE (ADC1), & ADC_CommonInitStruct);
ADC_REG_InitStruct. TriggerSource = LL_ADC_REG_TRIG_EXT_TIM3_TRGO;
ADC_REG_InitStruct. SequencerLength = 1; ADC_REG_InitStruct. SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE; ADC_REG_InitStruct. ContinuousMode = LL_ADC_REG_CONV_SINGLE; ADC_REG_InitStruct. DMATransfer = LL_ADC_REG_DMA_TRANSFER_NONE; LL_ADC_REG_Init (ADC1, & ADC_REG_InitStruct);
LL_ADC_SetChannelSamplingTime (ADC1, LL_ADC_CHANNEL_0, LL_ADC_SAMPLINGTIME_41CYCLES_5);
}
statik bo'shliq MX_SPI1_Init (bekor)
{LL_SPI_InitTypeDef SPI_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;
LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_SPI1);
GPIO_InitStruct. Pin = LL_GPIO_PIN_5 | LL_GPIO_PIN_7;
GPIO_InitStruct. Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOA, & GPIO_InitStruct);
// NVIC_SetPriority (SPI1_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0)));
// NVIC_EnableIRQ (SPI1_IRQn);
SPI_InitStruct. TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct. Mode = LL_SPI_MODE_MASTER; SPI_InitStruct. DataWidth = LL_SPI_DATAWIDTH_16BIT; SPI_InitStruct. ClockPolarity = LL_SPI_POLARITY_LOW; SPI_InitStruct. ClockPhase = LL_SPI_PHASE_1EDGE; SPI_InitStruct. NSS = LL_SPI_NSS_SOFT; SPI_InitStruct. BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8; SPI_InitStruct. BitOrder = LL_SPI_MSB_FIRST; SPI_InitStruct. CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; SPI_InitStruct. CRCPoly = 10; LL_SPI_Init (SPI1, & SPI_InitStruct); }
statik bo'shliq MX_SPI2_Init (bekor)
{LL_SPI_InitTypeDef SPI_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;
LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_SPI2);
GPIO_InitStruct. Pin = LL_GPIO_PIN_13 | LL_GPIO_PIN_15;
GPIO_InitStruct. Mode = LL_GPIO_MODE_ALTERNATE; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOB, & GPIO_InitStruct);
// NVIC_SetPriority (SPI2_IRQn, NVIC_EncodePriority (NVIC_GetPriorityGrouping (), 0, 0));
// NVIC_EnableIRQ (SPI2_IRQn);
SPI_InitStruct. TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct. Mode = LL_SPI_MODE_MASTER; SPI_InitStruct. DataWidth = LL_SPI_DATAWIDTH_16BIT; SPI_InitStruct. ClockPolarity = LL_SPI_POLARITY_LOW; SPI_InitStruct. ClockPhase = LL_SPI_PHASE_1EDGE; SPI_InitStruct. NSS = LL_SPI_NSS_SOFT; SPI_InitStruct. BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV4; SPI_InitStruct. BitOrder = LL_SPI_MSB_FIRST; SPI_InitStruct. CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; SPI_InitStruct. CRCPoly = 10; LL_SPI_Init (SPI2, & SPI_InitStruct); }
statik bo'shliq MX_TIM3_Init (bekor)
{LL_TIM_InitTypeDef TIM_InitStruct;
LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_TIM3);
TIM_InitStruct. Prescaler = 229;
TIM_InitStruct. CounterMode = LL_TIM_COUNTERMODE_UP; TIM_InitStruct. Autoreload = 9; TIM_InitStruct. ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; LL_TIM_Init (TIM3, & TIM_InitStruct);
LL_TIM_DisableARRP qayta yuklash (TIM3);
LL_TIM_SetClockSource (TIM3, LL_TIM_CLOCKSOURCE_INTERNAL); LL_TIM_SetTriggerOutput (TIM3, LL_TIM_TRGO_UPDATE); LL_TIM_EnableMasterSlaveMode (TIM3); }
statik bo'shliq MX_TIM4_Init (bekor)
{LL_TIM_InitTypeDef TIM_InitStruct; LL_GPIO_InitTypeDef GPIO_InitStruct;
LL_APB1_GRP1_EnableClock (LL_APB1_GRP1_PERIPH_TIM4);
GPIO_InitStruct. Pin = LL_GPIO_PIN_6 | LL_GPIO_PIN_7;
GPIO_InitStruct. Mode = LL_GPIO_MODE_FLOATING; LL_GPIO_Init (GPIOB, & GPIO_InitStruct);
LL_TIM_SetEncoderMode (TIM4, LL_TIM_ENCODERMODE_X2_TI1);
LL_TIM_IC_SetActiveInput (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_ACTIVEINPUT_DIRECTTI); LL_TIM_IC_SetPrescaler (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_ICPSC_DIV1); LL_TIM_IC_SetFilter (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_IC_FILTER_FDIV1); LL_TIM_IC_SetPolarity (TIM4, LL_TIM_CHANNEL_CH1, LL_TIM_IC_POLARITY_RISING); LL_TIM_IC_SetActiveInput (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_DIRECTTI); LL_TIM_IC_SetPrescaler (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1); LL_TIM_IC_SetFilter (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1); LL_TIM_IC_SetPolarity (TIM4, LL_TIM_CHANNEL_CH2, LL_TIM_IC_POLARITY_RISING);
TIM_InitStruct. Prescaler = 0;
TIM_InitStruct. CounterMode = LL_TIM_COUNTERMODE_UP; TIM_InitStruct. Autoreload = 19; TIM_InitStruct. ClockDivision = LL_TIM_CLOCKDIVISION_DIV1; LL_TIM_Init (TIM4, & TIM_InitStruct);
LL_TIM_DisableARRP qayta yuklash (TIM4);
LL_TIM_SetTriggerOutput (TIM4, LL_TIM_TRGO_RESET); LL_TIM_DisableMasterSlaveMode (TIM4); }
statik bo'shliq MX_GPIO_Init (bekor)
{LL_GPIO_InitTypeDef GPIO_InitStruct;
LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOC);
LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOD); LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOA); LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_GPIOB);
LL_GPIO_SetOutputPin (GPIOC, LL_GPIO_PIN_13);
LL_GPIO_SetOutputPin (GPIOA, LL_GPIO_PIN_4); LL_GPIO_SetOutputPin (GPIOB, LL_GPIO_PIN_12);
GPIO_InitStruct. Pin = LL_GPIO_PIN_13;
GPIO_InitStruct. Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_LOW; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOC, & GPIO_InitStruct);
GPIO_InitStruct. Pin = LL_GPIO_PIN_4;
GPIO_InitStruct. Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOA, & GPIO_InitStruct);
GPIO_InitStruct. Pin = LL_GPIO_PIN_12;
GPIO_InitStruct. Mode = LL_GPIO_MODE_OUTPUT; GPIO_InitStruct. Speed = LL_GPIO_SPEED_FREQ_HIGH; GPIO_InitStruct. OutputType = LL_GPIO_OUTPUT_PUSHPULL; LL_GPIO_Init (GPIOB, & GPIO_InitStruct); }
void _Error_Handler (char *fayl, int qator)
{vaqt (1) {}}
#ifdef USE_FULL_ASSERT
void assert_failed (uint8_t* fayl, uint32_t qator)
{} #endif
Tavsiya:
"High-Fivey" kartonli mikro: bitli robot: 18 qadam (rasmlar bilan)
"High-Fivey" kartonli mikro: bitli robot: Uyda qolib ketgandirsiz, lekin hali ham beshlikka kimdir kerakmi? Biz bir nechta kartonli va mikroli do'stona kichik robot yaratdik: "Crazy Circuits Bit Board" bilan birga, u sizdan bo'lgan muhabbatini saqlab qolish uchun sizdan yuqori beshlikni xohlaydi. Agar sizga yoqsa
Micro: akselerometr bilan bitli robotni boshqarish: 4 qadam
Micro: bit robotlarini akselerometr yordamida boshqarish: Ushbu maqolada biz TinkerGen kompaniyasining BitCar to'plamidan foydalanib, Micro: bitli robotni quramiz va uni boshqa Micro: bitli platadagi akselerometr yordamida boshqaramiz. STEM ta'limi uchun mo'ljallangan robot. O'rnatish oson, masalan
Arduino Nano-MMA8452Q 3 o'qli 12 bitli/8 bitli raqamli akselerometr bo'yicha qo'llanma: 4 qadam
Arduino Nano-MMA8452Q 3-o'qli 12-bitli/8-bitli raqamli akselerometr bo'yicha qo'llanma: MMA8452Q-bu 12 bitli, aqlli, kam quvvatli, uch o'qli, sig'imli, mikromaxinli akselerometr. Foydalanuvchilar tomonidan dasturlashtiriladigan moslashuvchan variantlar akselerometrga o'rnatilgan ikkita funktsiya yordamida ta'minlanadi, ular ikkita uzilishga o'rnatiladi
Raspberry Pi MMA8452Q 3 o'qli 12-bitli/8-bitli raqamli akselerometr Python qo'llanmasi: 4 qadam
Raspberry Pi MMA8452Q 3-o'qli 12-bitli/8-bitli raqamli akselerometr Python qo'llanmasi: MMA8452Q-bu 12 bitli aniqlikdagi aqlli, kam quvvatli, uch o'qli, sig'imli, mikromashinli akselerometr. Foydalanuvchilar tomonidan dasturlashtiriladigan moslashuvchan variantlar akselerometrga o'rnatilgan ikkita funktsiya yordamida ta'minlanadi, ular ikkita uzilishga o'rnatiladi
Raspberry Pi MMA8452Q 3 o'qli 12-bitli/8-bitli raqamli akselerometrli Java darsligi: 4 qadam
Raspberry Pi MMA8452Q 3-o'qli 12-bitli/8-bitli raqamli akselerometr Java darsligi: MMA8452Q-bu 12 bitli aniqlikdagi aqlli, kam quvvatli, uch o'qli, sig'imli, mikromaxinli akselerometr. Foydalanuvchilar tomonidan dasturlashtiriladigan moslashuvchan variantlar akselerometrga o'rnatilgan ikkita funktsiya yordamida ta'minlanadi, ular ikkita uzilishga o'rnatiladi