Jump to content
43oh

Recommended Posts

I'm trying to make a Sanguino (Arduino derivative board) talk to a MSP430G2553 Launchpad over SPI. The idea is for the Master to send a constant string "Hello, world!\n" and have the Slave write it to a serial terminal.

 

I'm using this for the master:

#include <SPI.h>


void setup (void)
{
  Serial.begin(9600);
  digitalWrite(SS, HIGH);
  SPI.begin ();
  SPI.setClockDivider(SPI_CLOCK_DIV8);
}


void loop (void)
{
  char c;


  // enable Slave Select
  digitalWrite(SS, LOW);    // SS is pin 10


  // send test string
  for (const char * p = "Hello, world!\n" ; c = *p; p++) {
    SPI.transfer (c);
    Serial.print(c);
  }


  // disable Slave Select
  digitalWrite(SS, HIGH);


  delay (1000);
}

And this for the slave:

#include <SPI.h>


char buf [100];
volatile byte pos;
volatile boolean process_it;


void setup (void)
{
  Serial.begin (9600);


  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);


  // turn on SPI in slave mode
  SPCR |= _BV(SPE);


  // get ready for an interrupt 
  pos = 0;   // buffer empty
  process_it = false;


  // now turn on interrupts
  SPI.attachInterrupt();
}




// SPI interrupt routine
ISR (SPI_STC_vect)
{
  byte c = SPDR;  // grab byte from SPI Data Register
  if (pos < sizeof(buf))
  {
    buf [pos++] = c;
    if (c == '\n')
      process_it = true;
  }
}


void loop (void)
{
  if (process_it)
  {
    buf [pos] = 0;  
    Serial.println (buf);
    pos = 0;
    process_it = false;
  } 
}

I've connected them like this:

Sanguino        Launchpad
      5 <----------> P1.7      (MOSI)
      6 <----------> P1.6      (MISO)
      7 <----------> P1.5      (SCK)
      4 <----------> P2.0      (SS)

Each board is connected to a separate USB port.

 

 

Now, when I use the Launchpad as the Master and the Sanguino as Slave, the two boards seem to be working together but the serial output from the Sanguino is messed up looking something like this:

@1S
Link to post
Share on other sites
  • 1 year later...

@@Anmol,  I just noticed your post and I know that I'm almost two years too late but I think there may be a voltage mismatch between your two boards.

 

I can see that the ATmega644P has an operating voltage of 2.7 V to 5.5 V.  

 

Do you know what voltage the board is operating at?

 

The LaunchPad is a 3.6V product and so you must talk to it with SPI voltages that match.

Link to post
Share on other sites

@@zeke - better late than never, right? :D

If nothing else, it is a reference someone else may come across in the future.

 

 

@@Anmol - Voltage levels would be the first thing I'd address. One might get away with something as simple as 4.7K resistors in series with each signal. It might not work well for high speeds, but at least should get things talking at lower speeds. Beyond that, TI's TXB0xxx and TXS0xxx logic level translators (this is a TI-oriented forum right? ;)), or discrete FET's in the system are other options.

Link to post
Share on other sites

speaking of which, does anyone know if Arduino has a standard API for SPI slave? I do know now that Arduino will soon have transactions for SPI, spearheaded by Paul Stoffregen of Teensy; might be worth targeting that API for DMA SPI work. Someone rewrotr SPI for Tiva to include DMA, possibly @@igor?

 

Sent from my Galaxy Note II with Tapatalk 4

Link to post
Share on other sites

speaking of which, does anyone know if Arduino has a standard API for SPI slave? I do know now that Arduino will soon have transactions for SPI, spearheaded by Paul Stoffregen of Teensy; might be worth targeting that API for DMA SPI work. Someone rewrotr SPI for Tiva to include DMA, possibly @@igor?

 

Sent from my Galaxy Note II with Tapatalk 4

 

No, no SPI slave on Arduino except for the Due

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...