9 years, 2 months ago.

sending lots of data via spi from slave to master

Hi,

I need help to send lots of data from lpc1768 as spi-slave to master.

Before programming I need help to structure my programm and I´d like to know if my solution is a good way.

The lpc1768 should do different functions:

1. reading adc-values - sampling rate 2 kHz

2. saving data on sd-card

3. sending data to rasperry pi via spi (sampling rate 500 Hz)

Reading from adc is implemented as ticker-function. The ticker reads adc-values and puts data to fifo_1 for sd-card. fifo_2 is used for data-sending to rasperry pi. the ticker-function puts only every 4th values to fifo_2 (500Hz).

When fifo_1 has more than 200 values the data will be send to sd-card.

These two functions are implementad on my programm without errors.

My problem is step 3 - sending data from fifo_2 to raspberry pi. The values on fifo_2 has 16bit-range. With rasperry pi I can only receive 8bit-word via spi.

My first step is to reduce 16bit-word into two 8bit words. This is no problem.

I can send 8bit-commands via spi from raspberry to lpc1768 - commands like start and stop recording to start/stop the ticker. I´ve also commands telling lpc1768 sending data from fifo_2.

My idea is making a command to find out number of values in fifo_2. lpc1768 sends 16bit-value as answer. Next step is to make loop on raspberry pi like this:

number_of_elements -> number of elements in fifo_2

buffer=[]
for k in range (number_of_elemts):
  value_1 = spi.read(1)
  value_2 = spi.read(2)
  
  buffer.append( (value_1[0]<<8) + value_2[0] )

code on mbed:

int i;
for (i=0; i<number_of_elements; i++)
{
   data = fifo_2.get()
   device.reply (data>>8);            // sending first 8bit from 16bit value
   device.reply (data & 0xFF);     // sending second 8bit from 16bit value
}

Is this good construction to implement send-function for fifo_2?

Be the first to answer this question.