Page 1 of 1

SPI2 + digitalWrite issues with Maple

PostPosted: Sun Sep 30, 2012 7:49 pm
by scott2
Heyo, I'm having two issues with the Maple that I didn't have with my Arduino. The first is, once AudioCodec_init() is called, I can't seem to use digitalWrite. If digitalWrite(somePin,HIGH) is called before the init, it works fine. Otherwise it doesn't work. I've tried this with multiple non SPI1 pins. This may also be why SPI2 doesn't work either for me...

Any ideas why?

Example witha slightly modified version of fixed_delay:

Code: Select all
/*
fixed_delay.pde (MAPLE)
guest openmusiclabs 7.13.11
this function delays both the left and right channels by a
fixed amount.  the limit to the length of the delay is set
by the internal SRAM of the chip you are using.  for the
Maple r5 (STM32F103RBT6), this is 20kbytes.  each audio data
sample is 16bits, or 2bytes, so at most you can get a 10k
sample delay buffer.  but, since this is in stereo, that is
limited to 5k for each, left and right.  this is further
limited by the fact that the program itself needs to use
some of that space, so feel free to play around with the SIZE
constant.  the compiler will complain if its too big.  "SIZE
7000" gives a delay of 3500 samples per channel, which is a
3500/44.1kHz = 79ms delay time.
*/


// setup codec parameters
// must be done before #includes
// see readme file in libraries folder for explanations
#define SAMPLE_RATE 8 // 44.1Khz
#define ADCS 0 // no ADCs are being used
#define MUTEMIC 0 // turn off the mute on the microphone
#define INSEL 1 // select the microphone input
#define MICBOOST 1 // enables the microphone +10dB amp
                   // set this to 0 if its too loud

// include necessary libraries
#include <AudioCodec_Maple.h>

int somepin = 8;
int timer = 0;

// create data variables for audio transfer
// note the use of "int16" rather than int -> on the maple,
// an int is 32bits
int16 left_in = 0x0000;
int16 left_out = 0x0000;
int16 right_in = 0x0000;
int16 right_out = 0x0000;
                   
                     
void setup() {
  pinMode(somepin,OUTPUT);
  SerialUSB.end(); // usb conflicts with the codec in this mode
                   // a different operating mode which allows both
                   // is in the works
  AudioCodec_init(); // setup codec registers
  // call this last if setting up other parts
}

void loop() {
  while (1); // reduces clock jitter
}

// timer4->ch1 interrupt routine - all data processed here
// you must call this function "AudioCodec_interrupt"
void AudioCodec_interrupt() {
  digitalWrite(somepin,HIGH); //I've tried this here, right after AudioCodec_Init() in setup(), and before the init
  // &'s are necessary on data_in variables
  AudioCodec_data(&left_in, &right_in, left_out, right_out);
  left_out = left_in;
  right_out = right_in;
 
  // dont use reti() with on maple
}


Re: SPI2 + digitalWrite issues with Maple

PostPosted: Sun Sep 30, 2012 10:02 pm
by guest
does it work if you put the digitalWrite() in Loop()?
how about right after the init() in the setup()?