Page 1 of 2

Serial comm with Maple

PostPosted: Mon May 07, 2012 11:51 am
by chipaudette
I've been using the Audio Codec Shield with an Arduino as a ADC and DAC for my PC for some lab work. I was streaming the data back to the PC over the Arduino's regular USB serial link. This worked fine but I decided that I wanted to do some real-time calculations on the Arduino and it didn't have enough I bought a Maple.

When I open up the Audio Codec Shield example program (sine_generator) from LeafLabs, the first thing that I see is that they disable the USBSerial saying that "conflicts with the codec".

Um, no serial? Really? That's a pretty big loss of functionality! It also makes debugging pretty hard. This also prevents me from using it as an ADC for my PC.

Are there any workarounds for this? The LeafLabs comment in the code also says that "a different operating mode which allows both is in the works". Has there been any progress?


Re: Serial comm with Maple

PostPosted: Mon May 07, 2012 12:19 pm
by chipaudette
Oh, and because the USBSerial is disabled in order to use the Codec Shield, you can't upload new code to the Maple from its IDE without putting the Maple into bootloader mode...which requires you to pull off the shield and press the magic combination of buttons.

This is quite a pain, it really slows me down, and it increases the likelihood bending pins on the shield.

Any knowledge or workarounds would be *greatly* appreciated!


Re: Serial comm with Maple

PostPosted: Tue May 08, 2012 1:15 pm
by guest
hello chip
sorry that i did not catch your first post

we havent recieved any updates from leaflabs
in regards to the USB problems
and youre right
it is quite a pain to have to reset on every upload

i will ask leaflabs to see if they can look at it
but if you want to post over at the leaflabs forums
there might be other users who have looked at this issue

Re: Serial comm with Maple

PostPosted: Tue May 08, 2012 1:25 pm
by guest
another thing to try
is to just comment out the usb code
and see what happens
if i recall correctly
the reason why it is there is because the usb makes audio glitches
but maybe it will be ok

Re: Serial comm with Maple

PostPosted: Wed May 16, 2012 10:51 pm
by guest
i was giving this some more thought today
and i think the problem with usb
is that it could only be blocked for so long
before it crashed the whole micro
and the interrupt routine for the codecshield
takes up all the processing time

one way around this
is to change what happens where
if only the first data transfer happened in the interrupt
and the rest happened in the main loop
it would block the usb
and usb would function fine
although this would cause the audio data
to not be transferred at exactly the right time
but im not sure how big of a problem that would be

Re: Serial comm with Maple

PostPosted: Tue Jun 12, 2012 5:43 pm
by vaxon
I'm not getting any real serial data back from the Arduinio. I tried stripping it down to :

AudioCodec_data(&left_in, &right_in, left_out, right_out);

With " Serial.println(out1);" in the loop and It just glitches out.

What was your test setup, chip?

Re: Serial comm with Maple

PostPosted: Tue Jun 12, 2012 8:02 pm
by guest
the maple has different issues than the arduino

try changing the interrupt routine to:


this will have it push all the data onto the stack

the other thing to try
is to re-enable timer0
as the last line in your setup() put
TIMSK0 = 0x01;

Re: Serial comm with Maple

PostPosted: Wed Jun 13, 2012 11:12 pm
by guest
i just tried a number of variants
and i couldnt get the serial to talk
i will have to dig deeper to find out why
but i think the codec interrupt might be blocking for too long
or vice versa

i got it to transfer a few bytes
and it caused clicks when doing so

im working on a rewrite of the header file
that will allow for a different programming setup
and it might alleviate this problem

a rewrite of the serial code would probably make it work
it depends upon what you want to do
streaming data out of the arduino would be pretty easy
just write UDR0 = byte;

ive got that working without any glitches

heres what you have to do:
1. change the interrupt routine to:

2. get rid of the reti; at the end of the interrupt routine
3. reinstate TIMER0 by writing TIMSK0 = 0x01 at the end of the setup routine
4. call Serial.begin() in the setup routine
5. call UDR0 = (byte of your data) when you want to send something

there isnt any flow control in this scheme
but delay() is now re-enabled
so you can just space it so it wont collide

Re: Serial comm with Maple

PostPosted: Fri Jul 06, 2012 4:43 am
by clee
It's my understanding that USB needs to be stopped when using the maple because the maple stm32 microcontroller is actually servicing the USB communication. libmaple does this using interrupts which glitch the audio processing. The arduino actually has a second microcontroller from FTDI just for USB input so that the main MCU doesn't have to worry about USB protocol servicing.

One option for you to get rapid serial communication is to use a FTDI breakout board or USB to serial cable and connect to one of the several serial interfaces on the maple. Lot's of manufacturers make these available (eg I need to look again at the maple to see if it needs 5V or 3.3V serial input.

I think it is even possible to make it so the cable triggers a hardware reset of the maple---though I haven't done it myself.

I just got my audio codec shield so I might try this approach myself. I already have a few of these FTDI USB-to-serial gadgets.

Re: Serial comm with Maple

PostPosted: Fri Jul 06, 2012 5:05 pm
by guest
that sounds like a good idea
let us know how it goes

i think there will still be trouble with bootloading
as the bootload code wants to read from the onboard usb