Raspberry Pi + MSP430 + SPI

  

This tutorial will explain how to communicate from the Raspberry Pi to an MSP430 Launchpad board (M430G2553 chip) using SPI.

Requirements

  • 1 Raspberry pi (running Raspbian)
  • 1 MSP430 TI Launchpad
  • 3 wires

Your raspberry pi should be running the newest version of Raspbian.  To ensure your system is up-to-date please download and run rpi-update.

Wiring

 

MSP430

Flash the below code to your MSP430 chip. Please see this tutorial for information on compiling and programming your MSP430.

MSP430 Code

Raspberry Pi

With your updated rasbian system you should have the drivers that you need. Now it’s time to load them.

modprobe spi_bcm2708
modprobe spidev

Check to be sure the modules loaded:

lsmod
Module Size Used by
spidev 5944 0
spi_bcm2708 5350 0
snd_bcm2835 21681 0
snd_pcm 81170 1 snd_bcm2835
snd_seq 59528 0
snd_timer 21602 2 snd_seq,snd_pcm
snd_seq_device 6924 1 snd_seq
snd 57427 5 snd_seq_device,snd_timer,snd_seq,snd_pcm,snd_bcm2835
snd_page_alloc 5343 1 snd_pcm
i2c_bcm2708 3822 0

Raspberry Pi Code

Save the below code as spidev_test.c on to your Raspberry Pi and compile it

gcc spidev_test.c -o spidev_test

Running

The MSP430 board LED1 will blink 3 times upon recognition of the SPI clock. After this initial sequence, when you SPI data “HELLO WORLD\n” to the MSP430 it will turn on the LED1 light.
On your Raspberry Pi run the previously compiled program. The -s options sets the frequency of the clock when performing the SPI communication.

sudo ./spidev_test -s 120000

Again, a successful sending of “HELLO WORLD\n” will be denoted by LED1 lighting up on the MSP430 board.

8 Comments

  1. Hi! I found the blog looking for “cron” in the Raspberry. I was thinking about connecting one of my Launchpads to the Rasp and… THE NEXT POST WAS THIS! xD

    Thanks for posting thi. You, Sir, made my morning.

  2. Any way to daisy-chain multiple MSP430 Launchpads ?

  3. What’s the advantage to connecting the RasPi and the Launchpad this way instead of over USB?

  4. When I copy and paste the MSP430 script I get two errors:
    Line 43: nop(); Error: function declared implicitly
    Line 78: __attribute__((interrupt(USCIAB0RX_VECTOR))) void USCI0RX_ISR (void) Errors: expected a “{“, unnamed prototype parameters not allowed when body is present, expected a type specifier

    I’m REALLY new to CCS and the MSP430. Could you clue me in to what I might be doing wrong?

    Thanks.

  5. It looks like the MSP430 code was built with GCC rather than CCS (despite the comment that says “Built with CCS Version 4.2.0″). The syntax used for interrupts and intrinsics varies between compilers.

    This is what got it working for me:

    Try replacing:

    __attribute__((interrupt(USCIAB0RX_VECTOR))) void USCI0RX_ISR(void)
    with:

    #pragma vector = USCIAB0RX_VECTOR
    __interrupt void USCI0RX_ISR(void)
    And also replace nop() with _no_operation()

    • On IAR you need to make the same changes but use __no_operation() instead of _no_operation(), there is a double underscore at the beginning as defined in the intrinsics.h file.

  6. Just a quick note. Don’t go by the comments in the MSP430 code. MOSI is P1.2, and MISO is P1.1. It’s shown reverse of that in the comments. Cost me a couple of hours find out why I was receiving all 0xFF on the SPI slave. Excellent example. Now I can use MSP430 as DAC, and MCP3208 as an ADC for my project. Otherwise, I was thinking of using an Arduino.

  7. Thanks for all the work it took to put this together. Followed all the steps and it ran perfectly the first time. Only thing I had any issue with was loading the api drivers. Never could get spidev to show up with lsmod. But I think the spi drivers are handled through raspi-config now. Anyway, now all I have to do is go back through code and understand exactly what’s going on here. I am long time C programmer but new to the MSP430 and SPI.

Leave a Reply