Go Down

Topic: Interfacing Arduino with mBed LPC1768 via SPI- seems to be unreliable? (Read 1 time) previous topic - next topic


I am trying to send some data between an Arduino UNO (master) and an mBed LPC1768 microcontroller board (slave). To test that this will work I have written a simple Arduino sketch that sends 255 bytes (just ints, 1-255), waits for one second, repeats forever. The program on my mBed simply prints the recieved values to the serial port which I'm viewing with putty, and also increments a counter every time a byte is recieved. This way the mBed slave knows if it's recieved the correct byte. But my problem is that it doesn't seem to work- at least not very well. usually 3 or 4 bytes are recieved before it reports a mismatch, and I have tried at every possible clock speed, even tried with a 1ms delay between each byte.
I tried this same test program with 2 mBed boards and it worked just fine- for some reason with an Arduino as the master it is unreliable. Can anybody shed any light on this?

Code: [Select]

#include <SPI.h>

void setup (void)

  digitalWrite(SS, HIGH);  // ensure SS stays high for now
  SPI.begin ();


void loop (void)
  for (int i = 1; i < 256; i++){  //send 255 bytes
    digitalWrite(SS, LOW);
    SPI.transfer (i);
  digitalWrite(SS, HIGH);

  delay (1000);  // 1 second delay between the next 255 bytes

}  // end of loop

Code: [Select]

#include "mbed.h"

Serial pc(USBTX, USBRX);
SPISlave spi(p5, p6, p7, p8); //mosi, miso, sclk

int main() {
int counter = 0;
int x;
    while(1) {
        x = spi.read();
        pc.printf("%d", x);
        pc.printf("  ");
    if(counter != x){
        pc.printf("mismatch at byte no. ");
        pc.printf("%d", counter);
        pc.printf(", counter is at ");
        pc.printf("%d", counter);
        pc.printf(" and the value received is ");
        pc.printf("%d\n\r", x);
    if(counter == 255){
    x = 0;
            counter = 0;

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131