SPI1.transfer - multiple bytes does not work

I was reading here:
https://docs.particle.io/reference/firmware/photon/#transfer-

That you can send multiple bytes at a time. I am using particle build and yet when I implement this I get “Build didn’t produce binary error: Command Failed…”

I have:

unsigned char RXBuffer[10], TXBuffer[10];
SPI1.transfer(TXBuffer, RXBuffer, 1, NULL);

I also tried removing the NULL but get same results.

the function prototype:

SPI.transfer(tx_buffer, rx_buffer, length, myFunction)

implies that length is the same size of your tx_buffer and rx_buffer which it seems three need to be the same, I would conclude.

did you try:

unsigned char RXBuffer[10], TXBuffer[10];
SPI1.transfer(TXBuffer, RXBuffer, 10, NULL);

?

Parameters:
tx_buffer: array of Tx bytes that is filled by the user before starting the SPI transfer
rx_buffer: array of Rx bytes that will be filled by the slave during the SPI transfer
length: number of data bytes that are to be transferred
myFunction: user specified function callback to be called after completion of the SPI DMA transfer

Just tried it. Same results.

is it a data type issue? You may want to try byte arrays instead of unsigned char, I’m certain that Arduino-like programming prefers byte

you could also try posting a test version of what you are trying to do so everyone can see what’s what…

I thought it might be worth asking if this happens if you comment out the SPI1.transfer too? This is also the classic symptom a file in the dev directory that is not a source file and you need to add to the ignore file. It’s a long-shot but worth mentioning.

Here is the code:

indent #include "application.h"


uint8_t sFLASH_SendByte(uint8_t tValue)
{
    uint8_t RXBuffer[10], TXBuffer[10];

    TXBuffer[0] = tValue;

    SPI1.transfer(TXBuffer, RXBuffer, 1, NULL);

    //return RXBuffer[0];
}

//*********************************************************************
//******************  INITALIZE THE CHIP SELECT PIN  ******************
//*********************************************************************
void setup()
{

    SPI1.begin(D5);
    SPI1.setBitOrder(MSBFIRST);
    SPI1.setClockDivider(SPI_CLOCK_DIV2);
    SPI1.setDataMode(SPI_MODE0);
  
  
    sFLASH_SendByte(0x04);
    
    }


void loop()
{

  delay(50);
}

When I comment out “SPI1.transfer(TXBuffer, RXBuffer, 1, NULL);” it does compile.

Changing uint8_t RXBuffer[10], TXBuffer[10];
to
byte RXBuffer[10], TXBuffer[10];
or
char RXBuffer[10], TXBuffer[10];

resulted in same problem.

1 Like

Hi @mikemoy

You are running into a missing HAL layer problem that has been fixed in the develop branch. The real error reported by the web IDE (build button) is:

^
../../../build/target/wiring/platform-6-m//libwiring.a(spark_wiring_spi.o): In function `SPIClass::transfer(void*, void*, unsigned int, void (*)())':
/spark/compile_service/shared/workspace/6_photon_18_1/firmware/wiring/src/spark_wiring_spi.cpp:164: undefined reference to `HAL_SPI_DMA_Transfer'

I recognized this immediately from this thread:

So you can compile locally or wait for 0.4.6 for the fix.

1 Like

@bko, thank you, I did run into that post before posting mine actually. I guess I read it to quickly, because I missed the part where it was said it was in the developer branch.

Guess, I’ll have to wait. As for local compiling I wish Particle would make one set of instructions from scratch step by step and not assuming anything the user knows or does not on what to get and install, and lastly then create, compile and download.