Skocz do zawartości

Przerwania zewnętrzne exti


olek623

Pomocna odpowiedź

Witam, mam problem z przerwaniami zewnętrznymi, nie mogę zainicjować EXTI- nie wiem czy mikrokontroler f0 nie jest w to wyposażony? Mam błedy typu : "request for member 'EXTI_Line' in something not a structure or union"

 #include <stm32f0xx_rcc.h>
#include "stm32f0xx.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_misc.h"


void LED()
{

	  GPIO_InitTypeDef GPIO_InitStructure;
	  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
	  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
	  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
	  GPIO_Init(GPIOC, &GPIO_InitStructure);
}


void GPIOInit(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;  ///?????????????
    GPIO_Init(GPIOF, &GPIO_InitStructure);
}

void NVICInit(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;

    NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
/*
    NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    */
}

void EXTIInit(void)
{
      EXTI_InitTypeDef EXTI_InitStructure;

      GPIO_EXTILineConfig(GPIO_PortSourceGPIOF, GPIO_PinSource1);


      EXTI_InitStructure.EXTI_Line = GPIO_Pin_1;
      EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
      EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
      EXTI_InitStructure.EXTI_LineCmd = ENABLE;
      EXTI_Init(&EXTI_InitStructure);
}

void EXTI1_IRQHandler(void)
{
    if (EXTI_GetITStatus(EXTI_Line1)!=RESET)
    {
        GPIO_SetBits(GPIOC,GPIO_Pin_8 | GPIO_Pin_9);
    }
    EXTI_ClearITPendingBit(EXTI_Line1);
}

int main(void)
{
	LED(); 
	GPIOInit();
	NVICInit();
	EXTIInit();
}

[ Dodano: 12-12-2016, 21:40 ]

Udało mnie się znaleźć błąd- oczywiście banał. Niestety z jedną rzeczą nie mogę jeszcze sobie poradzić, otóż działa mi przerwanie dla przycisku GPIOA-0, czyli wbudowanego przycisku. Jak chcę np dla GPIOF-0 niestety nie. Czy to kwestia podłączenia przycisku? Bo tak dokładnie to nie wiem jak to powinno być, wydaje mi się i tak właśnie robię żę do PF0 i do +3v ? Druga sprawa przerwanie występuje od razu przy starcie dlaczego?

 
#include "stm32f0xx.h"
#include "stm32f0xx_exti.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rcc.h"
#include "stm32f0xx_misc.h"
#include "stm32f0xx_syscfg.h"

uint32_t time;
void delayinit(void)
{
SystemInit();
SystemCoreClockUpdate();
SysTick_Config(SystemCoreClock/1000);

}

void SysTick_Handler(void) //nazwa jest w bibliotece
{
if (time>0)
{
	time--;
}
}

void delay(uint32_t czas)
{
time=czas;
while (time>0);
}




void LEDInit(void)
{
 GPIO_InitTypeDef  GPIO_InitStructure;

 /* Enable the GPIO_LED Clock */
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

 /* Configure the GPIO_LED pin */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOC, &GPIO_InitStructure);
}


void EXTI0_Config(void)
{
 EXTI_InitTypeDef   EXTI_InitStructure;
 GPIO_InitTypeDef   GPIO_InitStructure;
 NVIC_InitTypeDef   NVIC_InitStructure;

 /* Enable GPIOA clock */
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);

 /* Configure PA0 pin as input floating */
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 GPIO_Init(GPIOF, &GPIO_InitStructure);

 /* Enable SYSCFG clock */
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

 /* Connect EXTI0 Line to PA0 pin */
 SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOF, EXTI_PinSource0);

 /* Configure EXTI0 line */
 EXTI_InitStructure.EXTI_Line = EXTI_Line0;
 EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
 EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
 EXTI_InitStructure.EXTI_LineCmd = ENABLE;
 EXTI_Init(&EXTI_InitStructure);

 /* Enable and set EXTI0 Interrupt */
 NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
 NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 NVIC_Init(&NVIC_InitStructure);
}

void EXTI0_1_IRQHandler(void)
{
 if(EXTI_GetITStatus(EXTI_Line0) != RESET)
 {
  GPIO_SetBits(GPIOC,GPIO_Pin_9);

   /* Clear the EXTI line 0 pending bit */
   EXTI_ClearITPendingBit(EXTI_Line0);
 }
}

int main(void)
{
delayinit();

 LEDInit();

 /* Configure PA0 in interrupt mode */
 EXTI0_Config();

 /* Generate software interrupt: simulate a falling edge applied on EXTI0 line */
 EXTI_GenerateSWInterrupt(EXTI_Line0);

 /* Infinite loop */
 while (1)
 {
  GPIO_SetBits(GPIOC,GPIO_Pin_8);
  delay(1000);
  GPIO_ResetBits(GPIOC,GPIO_Pin_8);
  delay(1000);
  GPIO_ResetBits(GPIOC,GPIO_Pin_9);
  delay(1000);

 }
}

Link do komentarza
Share on other sites

Z tego co zdążyłem się zorientować to:

- mamy 16 linii przerwań,
- np. PC0 jest połączone do linii 0 tak jak PA0, PB0....

Stąd nie możemy użyć pinów PA0, PB0 jako EXTI jednocześnie.

Możemy natomiast używać jednocześnie 16 EXTI np. PA1, PA2, PB3, PA4 itd.

Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.