Using AVR Microprocessors Under planetCCRMA

  • Add the following to your .cshrc file: Use a text editor to open your .cshrc file which resides in your home directory. Add the following lines to the bottom of the file (don't edit other sections, but feel free the look at the script. this script runs each time you start up a new terminal shell)
    setenv AVRLIB ~/avrlib
    set PATH=$(PATH) /usr/avr/bin

    USB-to-Serial Converters

    Modern Apple Macintosh computers do not come with serial ports, so you will have to use a USB-to-Serial adapter. I've personally had success with the Keyspan UPR-112 and the Keyspan USA-19 devices, and a lack of success with an unlabeled generic device known as "Prolific" or "BF". I've heard that in general these tools work only with Keyspan hardware; please let me know [matt at CCRMA] of your experiences with other hardware. If you're physically at CCRMA in spring of 2005, you're welcome to borrow one or both of my serial to USB devices.

    All of these USB devices require drivers, which generally come on a CD when you buy the device, but are also available for download from the manufacturer's website (for example, http://www.keyspan.com/downloads/macosx).

    Once you install the driver and plug in the USB device, it will appear as a Unix tty device. For example, my Keyspan US-19 appears as /dev/tty.USA19W1b1P1.1 and my Keyspan UPR-112 appears as /dev/tty.UPSH112I3b13P1.1

    It's easy to look for these files with ls from a Terminal window:

    ls /dev/tty.*

    You'll need to add the name of this ersatz serial port to a makefile, for example, like this:

    UISP_PORT=/dev/tty.UPSH112I3b13P1.1

    or, add this line to your .cshrc file along with the other setenv lines above.

    -->

    Building CCRMA's Example Programs

    CCRMA's example AVR programs rely on the following to compile and load:

    CBI and SBI Macros

    Many of CCRMA's example programs use macros including CBI and SBI to clear and set individual bits of I/O ports. These old macros are now no longer supported by avr-libc, so if you've got a recent enough version of avr-libc to not include those macros, make sure you have a recent enough version of Pascal Stang's avrlib (March 2005 or later) that does include them.

    The silver lining is that the AVR toolchain now supports this programming style for reading and writing individual bits from I/O ports, which I personally prefer:

    PORTA = 0x01;
    PORTB |= 0x02;
    PORTC &= ~0x04;
    var = PIND;

    Other Issues

    LCD

    The LCD implementation has changed, so CCRMA's old lcdconf.h files (which are in each project directory) need to be replaced with the one in avrlib/conf:

    mv lcdconf.h lcdconf.h.old
    cp ~/avrlib/conf/lcdconf.h .

    Even so, the writing on the LCD will be garbled unless you set LCD_LINES and LCD_LINE_LENGTH to the actual number and length of the lines (in characters) on your LCD. For CCRMA's development boards, we use a 2x40 LCD, so your lcdconf.h should include these two lines:

    #define LCD_LINES 2 // visible lines
    #define LCD_LINE_LENGTH 40 // line length (in characters)

    The new avrlib also includes a macro LCD_DELAY that represents enough NOP ("No Operation") instructions to cause the AVR processor to do nothing for long enough for a character to be written safely to the LCD. It's worked for me consistently with 12 nop instructions, like this:

    #define LCD_DELAY asm volatile ("nop\n nop\n nop\n nop\n " \
                                    "nop\n nop\n nop\n nop\n " \
                                    "nop\n nop\n nop\n nop\n"); 

    Encoder

    My version of avrlib/encoder.h includes an extra definition, of GIMSK, which is necessary to make CCRMA's encoder demos work:

    #define GIMSK GICR // Kludge until Pascal fixes this in avrlib (MW 050524)

    OpenSoundControl

    For projects that use OpenSoundControl (to get data from the AVR over a serial port to Pd), the makefile has to include $(AVRLIB)/ccrma/OSC-client.c in the list of files in the SRC variable. Basically, anywhere you see

    $(AVRLIB)/ccrma/osc.c

    in a makefile, make it say

    $(AVRLIB)/ccrma/osc.c $(AVRLIB)/ccrma/OSC-client.c

    Where to go from here

    To get the AVRmini to talk to Pd on your OSX machine via OSC over Serial over USB (!), see Jesse Fox's excellent instructions:

    http://ccrma.stanford.edu/~jrobfox/OSC_PD_OSX.html

    Somebody should replicate the functionality of the dumpOSCSerial object for Max/MSP.