Купил дисплейчик на 4 знакоместа матричный на али за 300 руб Ссылка для дома часики собрать решил.
Начал с драйвера,покопался по просторам интернета. Писал под stm32f030f4c6 ,так как spi ноги были заняты,потому написал софтово с задержками.Будут вопросы помогу.
Нашел исходник товарища Easyrider83,немного переписал его под себя.
Также нужен был знакогенератор,нашел с сайта ардуино Ссылка
Сразу говорю что кушает MAX7219 хорошо даже на средней яркости, 7805 греется хорошо. Потому пришлось выписать стабилизатор отдельный С китая
Исходник
MAX7219.h
#ifndef MAX7219_ #define MAX7219_ #include "stm32f0xx.h" // Output max7219 PA1= CS PA2= CLK PA3= DIN #define CS 1 #define CLK 2 #define DIN 3 #define Load_ON 1 #define Load_OFF 0 #define MAX7219_NoOperation 0xA0 #define MAX7219_DecodeMode 0x09 #define MAX7219_Intensity 0x0A #define MAX7219_ScanLimit 0x0B #define MAX7219_ShutDown 0x0C #define MAX7219_DisplayTest 0x0F extern unsigned char masiv_max7219[4]; void MAX7219_Init(void); void MAX7219_DrawDigit1 (unsigned char Digit); void MAX7219_DrawDigit2 (unsigned char Digit,unsigned char t); void MAX7219_DrawDigit3 (unsigned char Digit); void MAX7219_DrawDigit4 (unsigned char Digit); void MAX7219_Indic (unsigned char *,unsigned char tochka); void MAX7219_DisplayTestVoid (unsigned char Enable); void MAX7219_DisplayClear(void); void MAX7219_SetIntensity (unsigned char Intensity); void MAX7219_Power (unsigned char PowerState); void MAX7219_WriteReg (unsigned char Reg, unsigned char Data,unsigned char Load); #endif
MAX7219.c
#include "MAX7219.h" #include "delays.h" #include "init.h" unsigned char font_max7219[12][8]= { {0x7C,0xC6,0xCE,0xDE,0xF6,0xE6,0x7C,0x0}, // 0 {0x30,0x70,0x30,0x30,0x30,0x30,0x30,0x0}, // 1 {0x78,0xCC,0xC,0x38,0x60,0xC0,0xFC,0x0}, // 2 {0x78,0xCC,0xC,0x38,0xC,0xCC,0x78,0x0}, // 3 {0x1C,0x3C,0x6C,0xCC,0xFE,0xC,0xC,0x0}, // 4 {0xFC,0xC0,0xF8,0xC,0xC,0xCC,0x78,0x0}, // 5 {0x38,0x60,0xC0,0xF8,0xCC,0xCC,0x78,0x0}, // 6 {0xFC,0xC,0xC,0x18,0x30,0x30,0x30,0x0}, // 7 {0x78,0xCC,0xCC,0x78,0xCC,0xCC,0x78,0x0}, // 8 {0x78,0xCC,0xCC,0x7C,0xC,0x18,0x70,0x0}, // 9 {0x66,0x66,0x66,0x3E,0x6,0x6,0x6,0x0}, // ? {0xC6,0xEE,0xFE,0xFE,0xD6,0xD6,0xC6,0x0} }; ///* You can manualy assign the value of chips in serialy connected here*/ //unsigned char ChipsInSerial=0; //otherwise search procedure will be needed and loop must be closed //unsigned char DigitsPerChip=8; unsigned char temp_zero_0=0; // memmory zero indic znakomesta 0 // 100 kHz = 10 mkS period void MAX7219_WriteReg (unsigned char Reg, unsigned char Data,unsigned char Load) { unsigned char cnt=0; unsigned char tmp=0; unsigned char reg_temp=0; GPIO_SET(GPIOA,CS); // CS->1 if(Load) GPIO_RESET(GPIOA,CS); // 4 bit zero GPIO_RESET(GPIOA,DIN); for (tmp=0;tmp<4;tmp++) { GPIO_SET(GPIOA,CLK); delay_us(1); GPIO_RESET(GPIOA,CLK); delay_us(1); } // 4 bit ADRES-Reg for (tmp=0;tmp<4;tmp++) { reg_temp=Reg&0x08; if(reg_temp) GPIO_SET(GPIOA,DIN); else GPIO_RESET(GPIOA,DIN); GPIO_SET(GPIOA,CLK); delay_us(1); GPIO_RESET(GPIOA,CLK); delay_us(1); Reg=Reg<<1; } // 8 bit infa for (tmp=0;tmp<8;tmp++) { reg_temp=Data&0x80; if(reg_temp) GPIO_SET(GPIOA,DIN); else GPIO_RESET(GPIOA,DIN); GPIO_SET(GPIOA,CLK); delay_us(1); GPIO_RESET(GPIOA,CLK); delay_us(1); Data=Data<<1; } GPIO_SET(GPIOA,CS); GPIO_RESET(GPIOA,DIN); } void MAX7219_Init(void) { MAX7219_DisplayTestVoid(0); MAX7219_WriteReg(MAX7219_DecodeMode, 0,Load_ON); MAX7219_WriteReg(MAX7219_Intensity, 0x07,Load_ON); MAX7219_WriteReg(MAX7219_ScanLimit, 0x07,Load_ON); MAX7219_WriteReg(MAX7219_ShutDown, 0x01,Load_ON); MAX7219_DisplayClear(); } void MAX7219_DisplayClear(void) { unsigned char temp=0,temp2=0; // clear command for(temp=0;temp<4;temp++) MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_ON); //MAX7219_DisplayTestVoid(1); for(temp2=1;temp2<9;temp2++) { for(temp=0;temp<4;temp++) { MAX7219_WriteReg(temp2, 0x00,Load_ON); } } // clear command for(temp=0;temp<4;temp++) MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_ON); } // Digit 0=0 1=1 ... 9=9 10=× 11=Ì void MAX7219_DrawDigit4 (unsigned char Digit) { unsigned char temp=0,temp2=0,temp3=0; // for(temp=1;temp<9;temp++) { MAX7219_WriteReg(temp,font_max7219[Digit][temp2],Load_ON); temp2++; // clear command for(temp3=0;temp3<4;temp3++) MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_OFF); } } void MAX7219_DrawDigit3 (unsigned char Digit) { // masiv digit unsigned char temp=0,temp2=0,temp3=0; // for(temp=1;temp<9;temp++) { MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_OFF); MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_OFF); MAX7219_WriteReg(temp,font_max7219[Digit][temp2],Load_OFF); temp2++; MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_ON); } } void MAX7219_DrawDigit2 (unsigned char Digit,unsigned char t) { unsigned char temp=0,temp2=0,temp3=0; // for(temp=1;temp<9;temp++) { MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_OFF); if(temp==7&&t==1) MAX7219_WriteReg(temp,font_max7219[Digit][temp2]|0x01,Load_OFF); else MAX7219_WriteReg(temp,font_max7219[Digit][temp2],Load_OFF); temp2++; MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_OFF); MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_ON); } } void MAX7219_DrawDigit1 (unsigned char Digit) { unsigned char temp=0,temp2=0,temp3=0; // for(temp=1;temp<9;temp++) { MAX7219_WriteReg(temp,font_max7219[Digit][temp2],Load_OFF); temp2++; // clear command for(temp3=0;temp3<2;temp3++) MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_OFF); MAX7219_WriteReg(MAX7219_NoOperation, 0x00,Load_ON); } } void MAX7219_Indic (unsigned char *pMas,unsigned char tochka) { //------------------------------------------------- if(pMas[0]) { MAX7219_DrawDigit1(pMas[0]); temp_zero_0=0;} else if((!pMas[0])&(!temp_zero_0)) { MAX7219_DisplayClear(); temp_zero_0=1; } //------------------------------------------------- if(tochka) MAX7219_DrawDigit2(pMas[1],1); else MAX7219_DrawDigit2(pMas[1],0); //------------------------------------------------- MAX7219_DrawDigit3(pMas[2]); //------------------------------------------------- MAX7219_DrawDigit4(pMas[3]); } void MAX7219_DisplayTestVoid (unsigned char Enable) { MAX7219_WriteReg(MAX7219_DisplayTest, Enable,Load_ON); } void MAX7219_SetIntensity (unsigned char Intensity) { MAX7219_WriteReg(MAX7219_Intensity, Intensity&0x0F,Load_ON); } void MAX7219_Power (unsigned char PowerState) { MAX7219_WriteReg(MAX7219_ShutDown, PowerState,Load_ON); }
Задержки
delay.h
#ifndef DELAY_ #define DELAY_ //#include "stm32f0xx.h" #define CPU_CLOCK 48000000 #define K_Const 4800 void delay_ms(unsigned long nTime); void delay_us(unsigned long nTime); #endif
delay.c
#include "delays.h" void delay_ms(unsigned long nTime) { nTime=(CPU_CLOCK/K_Const)*nTime; while(nTime != 0) {nTime--;} } void delay_us(unsigned long nTime) { nTime=((CPU_CLOCK/1000)/K_Const)*nTime; while(nTime != 0) {nTime--;} }
Забыл про init.h
#ifndef INIT_ #define INIT_ #include "stm32f0xx.h" // Режим работы #define GPIO_MODE_INPUT 0UL #define GPIO_MODE_OUTPUT 1UL #define GPIO_MODE_ALTFUNC 2UL #define GPIO_MODE_ANALOG 3UL // Тип выхода #define GPIO_OUTTYPE_NONE 0UL // заглушка #define GPIO_OUTTYPE_PP 0UL #define GPIO_OUTTYPE_OD 1UL // Подтяжка #define GPIO_PULL_NONE 0UL #define GPIO_PULL_UP 1UL #define GPIO_PULL_DOWN 2UL // Скорость #define GPIO_SPEED_LOW 0UL #define GPIO_SPEED_MED 1UL #define GPIO_SPEED_HI 3UL // Альтернативные функции #define GPIO_ALTFUNC_NONE 0UL // заглушка // Макрос инициализации #define GPIO_INIT(GPIO_PORT,GPIO_PIN,GPIO_MODE,GPIO_OUTTYPE,GPIO_PULL,GPIO_SPEED,GPIO_ALTFUNC)\ {\ GPIO_PORT->MODER = (GPIO_PORT->MODER & ~(3UL << (GPIO_PIN * 2UL)))\ | (GPIO_MODE << (GPIO_PIN * 2UL));\ GPIO_PORT->OTYPER = (GPIO_PORT->OTYPER & ~(1UL << (GPIO_PIN)))\ | (GPIO_OUTTYPE << (GPIO_PIN));\ GPIO_PORT->OSPEEDR = (GPIO_PORT->OSPEEDR & ~(3UL << (GPIO_PIN * 2UL)))\ | (GPIO_SPEED << (GPIO_PIN * 2UL));\ GPIO_PORT->PUPDR = (GPIO_PORT->PUPDR & ~(3UL << (GPIO_PIN * 2UL)))\ | (GPIO_PULL << (GPIO_PIN * 2UL));\ GPIO_PORT->AFR[GPIO_PIN / 8] = (GPIO_PORT->AFR[GPIO_PIN / 8] & ~(15UL << ((GPIO_PIN & 0x7) * 4)))\ | ((GPIO_ALTFUNC) << (GPIO_PIN & 0x7) * 4);\ } // Макросы для работы с ножкой порта #define GPIO_SET(GPIO_PORT,GPIO_PIN) (GPIO_PORT->BSRR = (1 << GPIO_PIN)) #define GPIO_RESET(GPIO_PORT,GPIO_PIN) (GPIO_PORT->BRR = (1 << GPIO_PIN)) #define GPIO_TOGGLE(GPIO_PORT,GPIO_PIN) (GPIO_PORT->BSRR = (1 << (GPIO_PIN+ ((GPIO_PORT->ODR & (1 << GPIO_PIN))?16:0) #define GPIO_ISSET(GPIO_PORT,GPIO_PIN) (GPIO_PORT->IDR & (1 << GPIO_PIN)) #define GPIO_ISRESET(GPIO_PORT,GPIO_PIN) (!(GPIO_PORT->IDR & (1 << GPIO_PIN))) // Макросы для работы с портом #define GPIOS_SET(GPIO_PORT,GPIO_MASK) (GPIO_PORT->BSRR = GPIO_MASK) #define GPIOS_RESET(GPIO_PORT,GPIO_MASK) (GPIO_PORT->BRR = GPIO_MASK) #define GPIOS_TOGGLE(GPIO_PORT,GPIO_MASK) (GPIO_PORT->ODR ^= GPIO_MASK) // Примеры инициализации // GPIO_INIT(GPIOA, 0, GPIO_MODE_OUTPUT, GPIO_OUTTYPE_PP, GPIO_PULL_NONE, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); // GPIO_INIT(GPIOA, 1, GPIO_MODE_INPUT, GPIO_OUTTYPE_NONE, GPIO_PULL_UP, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); extern void init_(void); #endif
Сделал гашение старших разрядов.
Может кому интересно будет повторить часы,выкладываю исходник main.c
/* Standard includes. */ #include "string.h" /* FreeRTOS includes. */ #include "FreeRTOS.h" #include "task.h" #include "semphr.h" #include "timers.h" #include "queue.h" #include "init.h" #include "delays.h" #include "MAX7219.h" // prototip void init(void); void vTaskMain(void *pvParametrs); void vTaskDS3231(void *pvParametrs); void vAutoReloadTimerFunction(TimerHandle_t); /*** descript RTOS ***/ TaskHandle_t xTask_main_Handle,xTask_setup_ds3231; TimerHandle_t xTimer_mig; SemaphoreHandle_t xSemaforSetup; TimerHandle_t xTimer; /*-----------------------------------------------------------*/ unsigned char mas_max7219[4]; // 0 and 1 -> clock 2 and 3-> minut unsigned char tochka=0,temp_tochka=0; // interput exti0 PA0 void EXTI0_1_IRQHandler(void) { static BaseType_t xHigherPriorityTaskWoken = pdTRUE; xHigherPriorityTaskWoken = pdFALSE; if(EXTI->PR & EXTI_PR_PIF0) { EXTI->PR |= EXTI_PR_PIF0; xSemaphoreGiveFromISR(xSemaforSetup, &xHigherPriorityTaskWoken); } portEND_SWITCHING_ISR(xHigherPriorityTaskWoken); } int main( void ) { char error_semafor,error_task1,error_task2,error_timer; BaseType_t xReturned1,xReturned2; init(); // // test i2c // if ((I2C1->ISR & I2C_ISR_TXE) == I2C_ISR_TXE) // { // I2C1->TXDR = 0x01; /* Byte to send */ // I2C1->CR2 |= I2C_CR2_START; /* Go */ // } // while (!(I2C1->ISR & I2C_ISR_TXIS)) {__NOP(); }; // I2C1->TXDR = 0x0F; /* Byte to send */ // Timer Rtos xTimer=xTimerCreate ( /* Just a text name, not used by the RTOS kernel. */ "Timer", /* The timer period in ticks, must be greater than 0. */ 500/portTICK_PERIOD_MS, /* The timers will auto-reload themselves when they expire. */ pdTRUE, /* The ID is used to store a count of the number of times the timer has expired, which is initialised to 0. */ ( void * ) 0, /* Each timer calls the same callback when it expires. */ vAutoReloadTimerFunction ); if( xTimer == NULL ) { /* The timer was not created. */ error_timer=1; } else { /* Start the timer. No block time is specified, and even if one was it would be ignored because the RTOS scheduler has not yet been started. */ if( xTimerStart( xTimer, 0 ) != pdPASS ) { /* The timer could not be set into the Active state. */ error_timer=0; } } // semafor setup ext prerivanie button xSemaforSetup=xSemaphoreCreateBinary(); if(xSemaforSetup==NULL) { while(1) error_semafor=1; } // Task xReturned1=xTaskCreate( vTaskMain, ( const char * ) "TaskMain", configMINIMAL_STACK_SIZE, NULL, 2, &xTask_main_Handle ); if( xReturned1 == pdPASS ) { error_task1=0; } xReturned2=xTaskCreate( vTaskDS3231, ( const char * ) "TaskDS3231", configMINIMAL_STACK_SIZE, NULL, 1, &xTask_setup_ds3231 ); if( xReturned2 == pdPASS ) { error_task2=0; } //xTP1.period=sizeof(tskTCB); vTaskStartScheduler(); for( ;; ); return 0; } /*-----------------------------------------------------------*/ ////////////////////////////////////////////////////////////////////////// // Task Main indic,read ds3231 void vTaskMain(void *pvParametrs) { unsigned char hour=0,minute=0; MAX7219_Init(); //MAX7219_WriteReg(0,0xff); for(;;) { //read ds3231 I2C1->CR2 = /*I2C_CR2_AUTOEND | */(1 << 16) | (0x68 <<1) ; // D0 adress <- 1 if ((I2C1->ISR & I2C_ISR_TXE) == I2C_ISR_TXE) { I2C1->TXDR = 0x01; /* Byte to send */ I2C1->CR2 |= I2C_CR2_START; /* Go */ } while (!(I2C1->ISR & I2C_ISR_TC)) {__NOP(); }; // end transmit // D1 adress <- 1 I2C1->CR2 = /*I2C_CR2_AUTOEND | */ I2C_CR2_RD_WRN| (2 << 16) | (0x68 <<1) ; I2C1->CR2 |= I2C_CR2_START; /* Go */ while (!(I2C1->ISR & I2C_ISR_RXNE)) {__NOP(); }; minute=I2C1->RXDR; while (!(I2C1->ISR & I2C_ISR_RXNE)) {__NOP(); }; hour=I2C1->RXDR; while (!(I2C1->ISR & I2C_ISR_TC)) {__NOP(); }; // end recerve I2C1->CR2 |= I2C_CR2_STOP; // minut and hour mas_max7219[2]=(minute&0xf0)>>4; mas_max7219[3]=minute&0x0f; if(hour&0x20) mas_max7219[0]=2; else if(hour&0x10) mas_max7219[0]=1; else mas_max7219[0]=0; mas_max7219[1]=hour&0x0f; MAX7219_Indic(mas_max7219,tochka); vTaskDelay(200/portTICK_PERIOD_MS); } } ////////////////////////////////////////////////////////////////////////// // Task Setup input clock,write ds3231 void vTaskDS3231(void *pvParametrs) { unsigned char button=0,temp=0; unsigned char clock_setup=0,minut_setup=0; unsigned char flag_mig=0; unsigned char clock=0,minut=0; NVIC_EnableIRQ(EXTI0_1_IRQn); for(;;) { if( xSemaforSetup != NULL ) { xSemaphoreTake( xSemaforSetup, portMAX_DELAY ); NVIC_DisableIRQ(EXTI0_1_IRQn); vTaskSuspend( xTask_main_Handle ); // off task min // first menu clock // delay PA0 if pulldown while(GPIO_ISRESET(GPIOA,0)) __NOP; // delay delay_ms(5); MAX7219_DisplayClear(); // clock mas_max7219[0]=10; MAX7219_DrawDigit1(mas_max7219[0]); TIM3->CNT = 0 ; TIM3->ARR = 48 ; // while(GPIO_ISSET(GPIOA,0)) { clock_setup=TIM3->CNT/2; if(clock_setup>23) clock_setup=0; temp=clock_setup/10; mas_max7219[2]=temp; if(temp) { mas_max7219[3]=clock_setup-(temp*10); flag_mig=1; } else { mas_max7219[3]=clock_setup; if(flag_mig) { MAX7219_DisplayClear(); flag_mig=0; } } MAX7219_DrawDigit1(mas_max7219[0]); if(mas_max7219[2]) MAX7219_DrawDigit3(mas_max7219[2]); MAX7219_DrawDigit4(mas_max7219[3]); delay_ms(20); } clock=(mas_max7219[2]<<4)|mas_max7219[3]; // minut setup while(GPIO_ISRESET(GPIOA,0)) __NOP; // delay delay_ms(5); mas_max7219[0]=11; MAX7219_DrawDigit1(mas_max7219[0]); TIM3->CNT = 0 ; TIM3->ARR = 120 ; // while(GPIO_ISSET(GPIOA,0)) { clock_setup=TIM3->CNT/2; if(clock_setup>59) clock_setup=0; temp=clock_setup/10; mas_max7219[2]=temp; if(temp) { mas_max7219[3]=clock_setup-(temp*10); flag_mig=1; } else { mas_max7219[3]=clock_setup; if(flag_mig) { MAX7219_DisplayClear(); flag_mig=0; } } MAX7219_DrawDigit1(mas_max7219[0]); if(mas_max7219[2]) MAX7219_DrawDigit3(mas_max7219[2]); MAX7219_DrawDigit4(mas_max7219[3]); delay_ms(20); } minut=(mas_max7219[2]<<4)|mas_max7219[3]; while(GPIO_ISRESET(GPIOA,0)) __NOP; // delay delay_ms(20); // write in ds3231 clock and minut I2C1->CR2 = I2C_CR2_AUTOEND | (3 << 16) | (0x68 <<1) ; // D0 adress <- 1 if ((I2C1->ISR & I2C_ISR_TXE) == I2C_ISR_TXE) { I2C1->TXDR = 0x01; /* Byte to send */ I2C1->CR2 |= I2C_CR2_START; /* Go */ } while(!(I2C1->ISR & I2C_ISR_TXIS)) {__NOP(); }; I2C1->TXDR =minut; while(!(I2C1->ISR & I2C_ISR_TXIS)) {__NOP(); }; I2C1->TXDR = clock; //while (!(I2C1->ISR & I2C_ISR_TC)) {__NOP(); }; // end transmit __NOP(); EXTI->PR |= EXTI_PR_PIF0; NVIC_EnableIRQ(EXTI0_1_IRQn); vTaskResume( xTask_main_Handle ); } //vTaskDelay(100/portTICK_PERIOD_MS); } } /////////////////////////////////////////////////////////////////////////// // Timer mig 0.5 sec ////////////////////////////////////////////////////////// // TIMER RTOS void vAutoReloadTimerFunction(TimerHandle_t xTimer) { if(temp_tochka) { tochka=1; temp_tochka=0; } else { tochka=0; temp_tochka=1; } GPIOA->ODR ^= GPIO_ODR_4 ; } //--------------------------------------------------------------- void vApplicationMallocFailedHook( void ) { /* vApplicationMallocFailedHook() will only be called if configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook function that will get called if a call to pvPortMalloc() fails. pvPortMalloc() is called internally by the kernel whenever a task, queue, timer or semaphore is created. It is also called by various parts of the demo application. If heap_1.c or heap_2.c are used, then the size of the heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used to query the size of free heap space that remains (although it does not provide information on how the remaining heap might be fragmented). */ taskDISABLE_INTERRUPTS(); for( ;; ); } /*-----------------------------------------------------------*/ void vApplicationIdleHook( void ) { /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle task. It is essential that code added to this hook function never attempts to block in any way (for example, call xQueueReceive() with a block time specified, or call vTaskDelay()). If the application makes use of the vTaskDelete() API function (as this demo application does) then it is also important that vApplicationIdleHook() is permitted to return to its calling function, because it is the responsibility of the idle task to clean up memory allocated by the kernel to any task that has since been deleted. */ } /*-----------------------------------------------------------*/ void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName ) { ( void ) pcTaskName; ( void ) pxTask; /* Run time stack overflow checking is performed if configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook function is called if a stack overflow is detected. */ taskDISABLE_INTERRUPTS(); for( ;; ); } /*-----------------------------------------------------------*/ void vApplicationTickHook( void ) { /* This function will be called by each tick interrupt if configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be added here, but the tick hook is called from an interrupt context, so code must not attempt to block, and only the interrupt safe FreeRTOS API functions can be used (those that end in FromISR()). */ } /*-----------------------------------------------------------*/ #ifdef JUST_AN_EXAMPLE_ISR void Dummy_IRQHandler(void) { long lHigherPriorityTaskWoken = pdFALSE; /* Clear the interrupt if necessary. */ Dummy_ClearITPendingBit(); /* This interrupt does nothing more than demonstrate how to synchronise a task with an interrupt. A semaphore is used for this purpose. Note lHigherPriorityTaskWoken is initialised to zero. Only FreeRTOS API functions that end in "FromISR" can be called from an ISR. */ xSemaphoreGiveFromISR( xTestSemaphore, &lHigherPriorityTaskWoken ); /* If there was a task that was blocked on the semaphore, and giving the semaphore caused the task to unblock, and the unblocked task has a priority higher than the current Running state task (the task that this interrupt interrupted), then lHigherPriorityTaskWoken will have been set to pdTRUE internally within xSemaphoreGiveFromISR(). Passing pdTRUE into the portEND_SWITCHING_ISR() macro will result in a context switch being pended to ensure this interrupt returns directly to the unblocked, higher priority, task. Passing pdFALSE into portEND_SWITCHING_ISR() has no effect. */ portEND_SWITCHING_ISR( lHigherPriorityTaskWoken ); } #endif /* JUST_AN_EXAMPLE_ISR */
Также init.c
#include "init.h" void init_clock_mcu() { // HSE RCC->CR |= RCC_CR_HSEON; while(!(RCC->CR & RCC_CR_HSERDY)) {}; FLASH->ACR |= FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; // PLL RCC->CR &= ~RCC_CR_PLLON; // off pll while((RCC->CR & RCC_CR_PLLRDY) != 0) {}; RCC->CFGR |= RCC_CFGR_PLLMUL6; RCC->CFGR |= RCC_CFGR_PLLSRC_HSE_PREDIV; RCC->CR |= RCC_CR_PLLON; while((RCC->CR & RCC_CR_PLLRDY) == 0){}; RCC->CFGR |= RCC_CFGR_SW_PLL; while((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL) {}; // MCO test clock // no in 030f4 .... } void init_i2c(void) { RCC->CFGR3 |= RCC_CFGR3_I2C1SW_SYSCLK; // takt 48 Mhz RCC->AHBENR |=RCC_AHBENR_GPIOAEN; RCC->APB1ENR |=RCC_APB1ENR_I2C1EN; // PA9- SCL PA10- SDA AF4 GPIO_INIT(GPIOA, 9, GPIO_MODE_ALTFUNC, GPIO_OUTTYPE_OD, GPIO_PULL_NONE, GPIO_SPEED_HI, 4); GPIO_INIT(GPIOA, 10, GPIO_MODE_ALTFUNC, GPIO_OUTTYPE_OD, GPIO_PULL_NONE, GPIO_SPEED_HI, 4); /* (1) Timing register value is computed with the AN4235 xls file, fast Mode @400kHz with I2CCLK = 48MHz, rise time = 140ns, fall time = 40ns */ /* (2) Periph enable */ /* (3) Slave address = 0x5A, write transfer, 1 byte to transmit, autoend */ I2C1->TIMINGR = (uint32_t)0x10805E89; /* (1) */ I2C1->CR1 = I2C_CR1_PE; /* (2) */ I2C1->CR2 = /*I2C_CR2_AUTOEND | */(2 << 16) | (0x68 <<1) ; /* (3) */ } void init(void) { unsigned int test=0; //init clock HSE-PLL- 48 Mzh + CSS init_clock_mcu(); init_i2c(); RCC->AHBENR |= RCC_AHBENR_GPIOAEN; RCC->APB2ENR |= RCC_APB2ENR_TIM1EN; // taktiro 48 Mzh=1/48= 21 nC RCC->APB1ENR |= RCC_APB1ENR_TIM3EN; GPIO_INIT(GPIOA, 4, GPIO_MODE_OUTPUT, GPIO_OUTTYPE_PP, GPIO_PULL_NONE, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); // tim1 500 mS // 1/48 Mhz= 21 ns arr=63999 pres=374 TIM1->ARR=63999; TIM1->PSC=374; TIM1->DIER |= TIM_DIER_UIE; //NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn); // on in zadache NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn,0); TIM1->CR1 |= TIM_CR1_CEN; // TIM3 Enkoder // PA7,PA6-> AF1 input nopullup(enkoder res 10 kOM) alternativ GPIO_INIT(GPIOA, 6, GPIO_MODE_ALTFUNC , GPIO_OUTTYPE_NONE, GPIO_PULL_NONE, GPIO_SPEED_HI, 1); GPIO_INIT(GPIOA, 7, GPIO_MODE_ALTFUNC, GPIO_OUTTYPE_NONE, GPIO_PULL_NONE, GPIO_SPEED_HI, 1); TIM3->CNT = 0 ; TIM3->ARR = 120 ; // TIM3->CCMR1|= TIM_CCMR1_CC1S_0|TIM_CCMR1_CC2S_0 ; // IC2 is mapped on TI2 // IC1 is mapped on TI1 TIM3->CCMR1 |= TIM_CCMR1_IC1F | TIM_CCMR1_IC2F; // filtr TIM3->SMCR |= TIM_SMCR_SMS_0 | TIM_SMCR_SMS_1 ; // SMS=011 TIM3->CR1 |= TIM_CR1_CEN; // Output max7219 PA1= CS PA2= CLK PA3= DIN GPIO_INIT(GPIOA, 1, GPIO_MODE_OUTPUT, GPIO_OUTTYPE_PP, GPIO_PULL_NONE, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); GPIO_INIT(GPIOA, 2, GPIO_MODE_OUTPUT, GPIO_OUTTYPE_PP, GPIO_PULL_NONE, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); GPIO_INIT(GPIOA, 3, GPIO_MODE_OUTPUT, GPIO_OUTTYPE_PP, GPIO_PULL_NONE, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); // exti0 interput in fail // PA0 input pullup GPIO_INIT(GPIOA, 0, GPIO_MODE_INPUT, GPIO_OUTTYPE_NONE, GPIO_PULL_UP, GPIO_SPEED_HI, GPIO_ALTFUNC_NONE); EXTI->IMR = 0x0001; // EXTI0 EXTI->FTSR = 0x0001; // fail NVIC_SetPriority(EXTI0_1_IRQn,0); }
Также для FreeRtos FreeRTOSConfig.h
/* * FreeRTOS Kernel V10.0.0 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. If you wish to use our Amazon * FreeRTOS name, please do so in a fair use way that does not cause confusion. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * http://www.FreeRTOS.org * http://aws.amazon.com/freertos * * 1 tab == 4 spaces! */ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H /*----------------------------------------------------------- * Application specific definitions. * * These definitions should be adjusted for your particular hardware and * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ /* Ensure stdint is only used by the compiler, and not the assembler. */ #ifdef __ICCARM__ #include <stdint.h> extern uint32_t SystemCoreClock; #endif #define configUSE_PREEMPTION 1 #define configUSE_IDLE_HOOK 0 #define configUSE_TICK_HOOK 1 #define configCPU_CLOCK_HZ ( ( unsigned long ) 48000000 ) #define configTICK_RATE_HZ ( ( TickType_t ) 1000 ) #define configMAX_PRIORITIES ( 3 ) #define configMINIMAL_STACK_SIZE ( ( unsigned short ) 60 ) #define configTOTAL_HEAP_SIZE ( ( size_t ) ( 2000 ) ) #define configMAX_TASK_NAME_LEN ( 5 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 #define configIDLE_SHOULD_YIELD 1 #define configUSE_MUTEXES 1 #define configQUEUE_REGISTRY_SIZE 8 #define configCHECK_FOR_STACK_OVERFLOW 2 #define configUSE_RECURSIVE_MUTEXES 0 #define configUSE_MALLOC_FAILED_HOOK 1 #define configUSE_APPLICATION_TASK_TAG 0 #define configUSE_COUNTING_SEMAPHORES 0 #define configGENERATE_RUN_TIME_STATS 0 //#define configSUPPORT_DYNAMIC_ALLOCATION 1 /* Co-routine definitions. */ #define configUSE_CO_ROUTINES 0 #define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) /* Software timer definitions. */ #define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY ( 2 ) #define configTIMER_QUEUE_LENGTH 5 #define configTIMER_TASK_STACK_DEPTH ( 80 ) /* Set the following definitions to 1 to include the API function, or zero to exclude the API function. */ #define INCLUDE_vTaskPrioritySet 0 #define INCLUDE_uxTaskPriorityGet 0 #define INCLUDE_vTaskDelete 0 #define INCLUDE_vTaskCleanUpResources 1 #define INCLUDE_vTaskSuspend 1 #define INCLUDE_vTaskDelayUntil 1 #define INCLUDE_vTaskDelay 1 /* Normal assert() semantics without relying on the provision of an assert.h header file. */ #define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); } /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names - or at least those used in the unmodified vector table. */ #define vPortSVCHandler SVC_Handler #define xPortPendSVHandler PendSV_Handler #define xPortSysTickHandler SysTick_Handler #endif /* FREERTOS_CONFIG_H */
Также настройка выводов из хала
PA1= CS PA2= CLK PA3= DIN PA4- мигает на плате
Сам модуль покупал с Китай,схема его
Весь проект в архиве и видео Ссылка
Отредактировано CERGEI (2018-05-25 15:18:36)