9 years, 11 months ago.

Solved: Programs with SPI connection to RPi won't start

Hi, relative MCU-newbie here ...

I have a Raspberry Pi connected to a NXP LPC812-max via SPI. I got it working ... with some slight of hand.

Set-up: the 4 SPI + GND connections between the RPi and the LPC812 are in place (directly connected). The RPi runs the following SPI-master code:

Code for RPi SPI master

import spidev
import time

spi = spidev.SpiDev()
spi.open(0,0)

try:
    while True:
        for i in range(256):
            send = [i]
            print "RPi SPI sending:", send
            resp = spi.xfer2(send)
            print "RPi received:", resp[0]
            time.sleep(1)
except KeyboardInterrupt:
    spi.close()

The LPC812 runs the following SPI-slave code:

Code for LPC812-max SPI slave

#include "mbed.h"

int main()
{  Serial serial(USBTX, USBRX);    // open serial communication
    serial.printf("Mbed getting ready");

    SPISlave device(P0_14, P0_15, P0_12, P0_13); // mosi, miso, sclk, css
    device.format(8,0);             // bits=8, mode=0
    device.reply(0x21);             // Prime SPI with first reply
    while(1) {
        if(device.receive()) {
            int v = device.read();  // Read byte from master
            v = v & 0xFF;           // Only take the lower 8 bits
            serial.printf("Mbed has received: %d\r\n",v);
            v = (v + 1) % 0x100;    // Add one to it, modulo 256
            serial.printf("Mbed is going to send: %d\r\n",v);
            device.reply(v);        // Make this the next reply
        }
    }
}

If I start the RPi code and do a reset on the LPC812 nothing happens. I have to disconnect the SCK, do a reset and re-insert the SCK before everything runs as it should. Also if I load another program such as a blinking led, it won't start until I disconnect, reset and re-connect the SCK.

What am I doing wrong?

Wim Huiskamp provided the answer: the LPC812 version C4 (which is indeed on the LPC812-max board I use) has the ISP entry pin on PI00_12 (P0_12), which is also used for the SPI SCK. The SPI SCK in mode 0 will (almost always) cause the board to expect a program to be flashed after a reset. So, I changed the SPI mode to 2 (inverted SCK) and now my program starts (almost always).

posted by Jeroen Voogd 09 Dec 2014

Note that this problem will bite you whenever you use P0_12 as DigitalIn (or even DigitalOut) pin that could be at a Low level during a hard reset or power-on reset! The LPC812 will then enter the ISP bootmode and expects to be flashed using the serial port rather than start normally.

posted by Wim Huiskamp 14 Dec 2014
Be the first to answer this question.