4 years, 5 months ago.

How to send Data array by SPI at once?(WB-55)

to Dear.

I have to send a file which I recieve by bluetooth to spi .

bluetooth MTU size is 130.

but I can not find how to send data array by SPI.

so SPI speed is lower than Bluetooth speed.

plz let me know how to use SPI's api.

1 Answer

4 years, 5 months ago.

The basic structure you need to do is something like this:

char databuffer[130];
int bytesReceived;
while (true) {
  bytesReceived = readBTRata(databuffer);
  startSPICycle(); // activate chip select, send address etc... if needed,
  for (int i=0;i<bytesReceived;i++)
    writeSPIByte(databuffer[i]);
  endSPICycle(); // clear chip select if needed
}

Obviously that's not working code but it should give you an idea of the structure to use.

If you need to be able to cope with new bluetooth data arriving while the SPI is still sending or you need to start the SPI transmit before the bluetooth receive has finished then it gets a bit trickier.

Dear Andy.

Thanks for your quick reply.

unfortunately, I already do like you.

but slave read the data in buffers user already set.

so I should send fixed length data to slave.

posted by SHIN ETHAN 22 Nov 2019

I'm not sure where your problem is.

For an SPI master you write one byte per byte to send.

For an SPI slave you can't set the transaction size, the master controls when and how much data to read, the slave has no control over this. So you set the data for the next read to be the first byte, wait for the master to read a byte and then set the data to be the second byte and so on.

If you need to be able to vary the size of the transfer then you need to use some method to tell the master how many bytes to read. If you need the slave to tell the master when there is data available you need to use some other method to do this, normally an interrupt to the master device.

posted by Andy A 22 Nov 2019