soundstream32
Member
hi i'm having some problems using interruptions on gpio pins, i want to control the level of a digital potentiometer, for now i just want that when i press a button the interrupt occurs, but my code is just not working. can some one please help me with this, here is my code
#include <SPI.h>
#include <stdio.h>
char str[100];
// set pin 10 as the slave select for the digital pot:
const int slave_Select_Pin = 31;
volatile int level1 = 255;
volatile int level2 = 255;
const int BUTTON1 = 2;
volatile boolean flagB1;
void setup() {
// put your setup code here, to run once:
pinMode (slave_Select_Pin, OUTPUT);
Serial.begin(9600);
SPI1.setMOSI(21);
// initialize SPI:
SPI1.begin();
MSP42010PotWrite(slave_Select_Pin, B00010001, level1);
MSP42010PotWrite(slave_Select_Pin, B00010010, level2);
pinMode(BUTTON1, INPUT);
attachInterrupt (BUTTON1, isrButton1, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
if (flagB1 == true)
{
Serial.println("BUTTON 1 interrupt has occurred");
flagB1=false;
}
}
void MSP42010PotWrite(int slaveSelectPin, byte address, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI:
SPI1.transfer(address);
SPI1.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}
void isrButton1 ()
{
flagB1 = true;
}
#include <SPI.h>
#include <stdio.h>
char str[100];
// set pin 10 as the slave select for the digital pot:
const int slave_Select_Pin = 31;
volatile int level1 = 255;
volatile int level2 = 255;
const int BUTTON1 = 2;
volatile boolean flagB1;
void setup() {
// put your setup code here, to run once:
pinMode (slave_Select_Pin, OUTPUT);
Serial.begin(9600);
SPI1.setMOSI(21);
// initialize SPI:
SPI1.begin();
MSP42010PotWrite(slave_Select_Pin, B00010001, level1);
MSP42010PotWrite(slave_Select_Pin, B00010010, level2);
pinMode(BUTTON1, INPUT);
attachInterrupt (BUTTON1, isrButton1, RISING);
}
void loop() {
// put your main code here, to run repeatedly:
if (flagB1 == true)
{
Serial.println("BUTTON 1 interrupt has occurred");
flagB1=false;
}
}
void MSP42010PotWrite(int slaveSelectPin, byte address, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI:
SPI1.transfer(address);
SPI1.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}
void isrButton1 ()
{
flagB1 = true;
}