SPI.transfers input format

Hi all,

I am pretty new around. I am working on controlling a Digital Synthesizer through its serial interface using the Arduino Due SPI option. Everything starts in Matlab GUI where I write a sequence like "07,04,5D" and so on. The Arduino reads the sequence and tries to send through the SPI port the data:

SPI.transfer(0x07)
SPI.transfer(0x04)

However, given the way I get the data and how it should be organized to address different options in the synthesizer, I really get a char variable thischar='0x07' and then try to write the SPI. Something like this:

char bufferchar[SPIstring.length()+1];
SPIstring.toCharArray(bufferchar, SPIstring.length()+1);
SPI.transfer(bufferchar);

Where SPIstring is the string with the command I need to write.

The error given by the compiler is

sketch_mar13a.ino: In function 'void loop()':
sketch_mar13a:93: error: invalid conversion from 'char*' to 'uint8_t'
sketch_mar13a:93: error: initializing argument 1 of 'byte SPIClass::transfer(uint8_t, SPITransferMode)'

I would appreciate suggestions on how to get the char sequence translated into the right format to use the SPI.transfer.

Thanks a lot!

Juan

Your 'bufferchar' is an array.
The SPI.transfer() function accepts a single unsigned 8-bits byte.
That is because the SPI.transfer() transfers only 8-bits, no more.

Thanks for pointing out my errors. Finally I used the strtol function to convert the array to an integer and then some function to convert it to a HEX number.

Actually, the format at the end does not matter for the SPI.transfer. It just needs to be int.