Accessing interrupts

Hello,

I’ve been reading the data sheet for the STM32F103C8T6 and see that all pins can be mapped to a hardware interrupt.

This is obviously very different behaviour from that of the ATMEGA328P, which only has 2 external interrupts available.

Will these interrupts and their priority be available to the user, with simple syntax such as attachInterrupt(pin,routine,falling/rising,priority)?

Many thanks!

The Spark library already provides this for most of the pins - is this what you were looking for, or did I misunderstand the question?

1 Like

That’s great, thanks. Any ability to adjust the interrupt priority with the existing library?

Perhaps the docs site could be slightly changed to allow drop-down sub-sections for each of the section headers, rather than having to continuously scroll down a single page.

1 Like

Oh right interrupt priority, missed that bit in the original post.

Doesn’t look like there’s any function to do that in the Spark library, here’s the relevant code from spark_wiring_interrupts.cpp, it looks like the interrupt priority is hardcoded based on the pin number:

	if(GPIO_PinSource < 10)//Should not try changing the priority of EXTI15_10_IRQn
	{
		//configure NVIC
		//select NVIC channel to configure
		NVIC_InitStructure.NVIC_IRQChannel = GPIO_IRQn[GPIO_PinSource];
		if(GPIO_PinSource > 4)
			NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 14;
		else
			NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 13;
		NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
		//enable IRQ channel
		NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
		//update NVIC registers
		NVIC_Init(&NVIC_InitStructure);
	}

The NVIC functions are all part of the chip’s standard peripheral driver library, which I’ve always found somewhat confusing to use, but you may be able to re-initialize the priority levels using the NVIC functionality yourself after calling Spark’s attachInterrupt().

This site has some auto-generated documentation based on the NVIC functions’ source files, hopefully it will at least get you started.

Edit: the site linked above shows the documentation for the STM32 F4 series chips, whereas the SparkCore uses F1 series, so you may want to poke around a bit more to see if you can find documentation for the F1. But I doubt it will be significantly different, if at all.

1 Like

Thanks for that. I’ll have a look through it.

Not sure what you are trying to do, but Interrupt Priorities 0, 1, 2 are used for the dma channels servicing the CC3000, the interrupt from the CC3000, and the UART respectively, and all are very sensitive to interrupt service times. I’d recommend not going anywhere near these with priority changes.

OK, probably won’t do anything with it in that case.