08-20-2012 03:18 AM
In LabVIEWInterface.ino (pde), in function spi_sendReceive():
// Send SPI Byte
Serial.print(SPI.transfer(command[i+6]));
...
Send ASCII symbol to serial
Should be?
Binary data send?
// Send SPI Byte
Serial.write(SPI.transfer(command[i+6]));
...
08-20-2012 06:16 PM
I think that may be correct. Maybe that is why the SPI VIs that I'm trying to make for people don't work . . .
However, Serial.print() is used in 10 places in LIFA v2.1.1.69. Ardiuno documenation says that Serial.print() shouldn't work at all:
http://arduino.cc/en/Serial/Print
Programming Tips
As of version 1.0, serial transmission is asynchronous; Serial.print() will return before any characters are transmitted.
I'd imagine there would be more issues for those who use Arduino 1.0 or greater.
08-21-2012 01:03 AM
Asynchronous doesn't mean it would not work, only that the data is stored in some buffer and then the function returns. A seperate task/thread/interrupt routine or whatever there is on the Arduino firmware will then send out the data in the background while your program can go on.
This could be a problem if your code relies on the data being sent out when print() returns, but should work otherwise.
08-21-2012 05:57 PM
Oh. When it says it returns before it transmits anything that implies that it never sends anything. It doesn't explain it very well if it works lik you explain it.
08-21-2012 07:57 PM
It actually does! The term asynchronous implies more or less exactly what I explained, so the rest of the sentence should be interpreted in that context.
08-21-2012 08:12 PM
Oh . . now that I think of it, that does make sense.
09-27-2012 05:35 PM
Hi there,
does that mean it would be wise to change all apearances of "serial.print" to "serial.write" in order to make the current LIFA Arduino 1.0.1 compatible?
Best regards,
Jan
09-27-2012 06:55 PM
You shouldn't need to do that.
02-26-2013 12:53 PM
I agree that the use of Serial.print() may be causing issues for some, not related to the use of buffering, but for the reason Chupakabra discussed. My LIFA_Base was compiled on Arduino 1.0.3, and the Serial.print() implementation in spi_sendReceive() sends the value of the byte received over SPI as a series of ASCII characters instead of the single byte that LabVIEW is expecting.
For example, if the binary value 255 is received over SPI the Arduino function sends "255" in ASCII, a series of three bytes equal to: 50, 53, 53. LabVIEW is expect a packet from the Arduino with one binary character per byte received over SPI.
Modifying the LabVIEWInterface file as Chupakabra suggested looks to be the correct fix, and is working flawlessly in my implementation. While I haven't tested it, I suspect the analogReadPort() will also have issues, and should be modified to use Serial.write(). The Serial.print("sync") in processCommand() is correct.