Thanks for the infos.
Actually I have problems with interrupt and the standard functions.
For example: This code runs and I have an interrupt driven shimmer function
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_tim.h>
#include <stm32f4xx_rcc.h>
#include <misc.h>
#include <LedStrip.h>
LedStrip myLedStrip;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
uint8_t ind = 0;
bool flagINT = false;
void setup()
{
Serial.begin(115200);
// A WS2812B strip with 30LEDs
myLedStrip.begin(30);
swOn();
initIrqTimer();
}
void loop() {
if (flagINT == true){
myLedStrip.set(0,random(35)+220,random (5),0);
myLedStrip.update();
flagINT = false;
TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
}
}
void swOn ()
{
for(int ciclo = 1; ciclo < 31; ciclo ++){
myLedStrip.set(ciclo, 255,0,0);
myLedStrip.update();
delay(30);
}
}
void swOff ()
{
for(int ciclo = 30; ciclo > 0; ciclo --){
myLedStrip.set(ciclo, 0,0,0);
myLedStrip.update();
delay(30);
}
}
void initIrqTimer()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 11;
nvicStructure.NVIC_IRQChannelSubPriority = 11;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
TIM_TimeBaseInitTypeDef timerInitStructure;
timerInitStructure.TIM_Prescaler = 4200 -1; // CLK 84MHz diviso 4200 -> 20KHz (50 usec)
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 200 -1; // Durata 200 ticks -> 10 msec interrupt
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM9, &timerInitStructure);
TIM_Cmd(TIM9, ENABLE);
TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
}
extern "C" void TIM1_BRK_TIM9_IRQHandler()
{
if (TIM_GetITStatus(TIM9, TIM_IT_Update) != RESET)
{
TIM_ITConfig(TIM9, TIM_IT_Update, DISABLE);
TIM_ClearITPendingBit(TIM9, TIM_IT_Update);
flagINT = true;
}
}
But if I add a hum effect in the background, I got the audio scrambled.
Here is the code:
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_tim.h>
#include <stm32f4xx_rcc.h>
#include <misc.h>
#include <LedStrip.h>
LedStrip myLedStrip;
WavPlayer hum;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
uint8_t ind = 0;
bool flagINT = false;
void setup()
{
Serial.begin(115200);
// A WS2812B strip with 30LEDs
myLedStrip.begin(30);
Audio.begin();
Audio.setVolume(-10); // No noise for testing..
swOn();
initIrqTimer();
hum.play("hum.wav", PlayModeLoop);
}
void loop() {
if (flagINT == true){
myLedStrip.set(0,random(35)+220,random (5),0);
myLedStrip.update();
flagINT = false;
TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
}
}
void swOn ()
{
for(int ciclo = 1; ciclo < 31; ciclo ++){
myLedStrip.set(ciclo, 255,0,0);
myLedStrip.update();
delay(30);
}
}
void swOff ()
{
for(int ciclo = 30; ciclo > 0; ciclo --){
myLedStrip.set(ciclo, 0,0,0);
myLedStrip.update();
delay(30);
}
}
void initIrqTimer()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 11;
nvicStructure.NVIC_IRQChannelSubPriority = 11;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
NVIC_EnableIRQ(TIM1_BRK_TIM9_IRQn);
TIM_TimeBaseInitTypeDef timerInitStructure;
timerInitStructure.TIM_Prescaler = 4200 -1; // CLK 84MHz diviso 4200 -> 20KHz (50 usec)
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 200 -1; // Durata 200 ticks -> 10 msec interrupt
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM9, &timerInitStructure);
TIM_Cmd(TIM9, ENABLE);
TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
}
extern "C" void TIM1_BRK_TIM9_IRQHandler()
{
if (TIM_GetITStatus(TIM9, TIM_IT_Update) != RESET)
{
TIM_ITConfig(TIM9, TIM_IT_Update, DISABLE);
TIM_ClearITPendingBit(TIM9, TIM_IT_Update);
flagINT = true;
}
}
I do not understand if I did something wrong or there is a interrupt management problem