You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.8 KiB
101 lines
1.8 KiB
#include "main.h"
|
|
#include "delay.h"
|
|
#include "deviceSetup.h"
|
|
#include "usart.h"
|
|
#include "ascii.h"
|
|
#include "timer.h"
|
|
#include "i2c.h"
|
|
|
|
#include "stm32f042x6.h"
|
|
#include "hardwareDescription.h"
|
|
|
|
volatile uint8_t led_on;
|
|
|
|
void setup();
|
|
|
|
void EXTI0_1_IRQHandler(void)
|
|
{
|
|
if(EXTI->PR & EXTI_PR_PIF1) {
|
|
// clear flag
|
|
EXTI->PR |= EXTI_PR_PIF1;
|
|
led_on = !led_on;
|
|
}
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
setup();
|
|
|
|
// https://controllerstech.com/external-interrupt-using-registers/
|
|
|
|
pinConfig(pinA1, input, def_stage, pullDown, def_speed);
|
|
|
|
// Connect
|
|
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN;
|
|
SYSCFG->EXTICR[1] &= ~SYSCFG_EXTICR1_EXTI1_Msk;
|
|
SYSCFG->EXTICR[1] |= SYSCFG_EXTICR1_EXTI1_PA;
|
|
|
|
// Interrupt mask register
|
|
EXTI->IMR |= EXTI_IMR_IM1;
|
|
|
|
// rising trigger selection
|
|
EXTI->RTSR |= EXTI_RTSR_RT1;
|
|
|
|
NVIC_SetPriority (EXTI0_1_IRQn, 0);
|
|
NVIC_EnableIRQ(EXTI0_1_IRQn);
|
|
|
|
while(1)
|
|
{
|
|
if(led_on){
|
|
pinWrite(pinB3,1);
|
|
} else{
|
|
pinWrite(pinB3,0);
|
|
}
|
|
}
|
|
/*
|
|
while(1)
|
|
{
|
|
delayMs(100);
|
|
pinToggle(pinB3);
|
|
delayMs(100);
|
|
}
|
|
*/
|
|
return 1;
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
uint8_t i = 0;
|
|
|
|
delayInitMs(8000000, 1000); // Clock Freq and Divider for ARM library
|
|
|
|
pinConfig(pinB3, output, pushPull, def_res, def_speed);
|
|
pinConfig(pinA0, input, def_stage, pullDown, def_speed);
|
|
|
|
setupInit(); // This is the sescond call of System init the assebly start code is calling it before the main.
|
|
|
|
usartInit( usart2,
|
|
pinA2,
|
|
pinA15,
|
|
115200,
|
|
eight,
|
|
NO_PARITY_CTRL,
|
|
noFlowControl);
|
|
|
|
//clears screen and send the wellcome messgae
|
|
print_Usart(usart2, ASCII_clear);
|
|
print_Usart(usart2, "Hello to our KED project\n\r");
|
|
|
|
|
|
//blinks 10 times to indicate the sicsessfull init if the device
|
|
for(i = 0 ; i < 10 ; i++) {
|
|
delayMs(100);
|
|
pinToggle(pinB3);
|
|
delayMs(100);
|
|
}
|
|
|
|
pinWrite(pinB3,0);
|
|
}
|
|
|
|
|