AnsweredAssumed Answered

SPI transfer between LPC54608 and Raspberry Pi

Question asked by nathan sowie on Jul 17, 2018
Latest reply on Jul 30, 2018 by soledad

Hi everyone,


I have a LPC54608 (on a OM13092 demo board) and Raspberry Pi 3 Model B+.

I am trying to transfer data via SPI using the R. Pi as the SPI master and the LPC54608 as the SPI slave, but I don't manage to make it work.

I am using the example code "lpcxpresso54608_driver_example_spi_interrupt_b2b_slave" from the MUCXpresso SDK on the LPC54608, and the SPI example from the "bcm2835.h" library on the R. Pi that I modified a bit to match the code uploaded on the LPC54608.

Here is the code I am using the R Pi:

// spi.c
// Example program for bcm2835 library
// Shows how to interface with SPI to transfer a byte to and from an SPI device
// After installing bcm2835, you can build this
// with something like:
// gcc -o spi spi.c -l bcm2835
// sudo ./spi
// Or you can test it before installing with:
// gcc -o spi -I ../../src ../../src/bcm2835.c spi.c
// sudo ./spi
// Author: Mike McCauley
// Copyright (C) 2012 Mike McCauley
// $Id: RF22.h,v 1.21 2012/05/30 01:51:25 mikem Exp $
#include <bcm2835.h>
#include <stdio.h>
int main(int argc, char **argv)
   // If you call this, it will not actually access the GPIO
   // Use for testing
   // bcm2835_set_debug(1);
   if (!bcm2835_init())
      printf("bcm2835_init failed. Are you running as root??\n");
      return 1;
   if (!bcm2835_spi_begin())
      printf("bcm2835_spi_begin failed. Are you running as root??\n");
      return 1;
   bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
   bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
   bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_128); // The default
   bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
   bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default


   int BUFFER_SIZE = 64;
   char buffer[BUFFER_SIZE];

   for (int i = 0; i < BUFFER_SIZE ; i++) {
      buffer[i] = bcm2835_spi_transfer(i);

   for (int j = 0; j < BUFFER_SIZE; j++) {
      printf("%d i = %d\n", buffer[j], j);

On the LPC54608 part I tried to let the code untouched (I attached this source code), then I replaced the line 138: 

SPI_EnableInterrupts(EXAMPLE_SPI_SLAVE, kSPI_RxLvlIrq | kSPI_TxLvlIrq);

by : 

SPI_EnableInterrupts(EXAMPLE_SPI_SLAVE, kSPI_RxLvlIrq);

to only get interrupt only when the SPI receive buffer is filled.

I also tried to replace this line by: 


to get an interrupt each time the Slave Select line is asserted.

Using the original code, or a modified one  (with the modifications mentioned above), the data transferred between the 2 uP are not the one expected: I got random data on both side.


When I look with an oscilloscope to the 4 lines, everything seems to be normal on CS, SCLK AND MOSI lines: the slave select is asserted, then a clock is generated an on the SCLK line and there is a data transfer on MOSI line (which correspond to what it the actual data should be). But the data send to R.Pi by the LPC54608 on the MISO lines do not correspond to the one the Tx Buffer is supposed to be filled with.


Has anyone an idea from where I am doing wrong, or has done something similar, and could provide an example code ?


Thanks in advance,

Nathan Sowie