arduino_spi_slave 从设备通信错误
-
#include <SPI.h>
#define SS_PIN 10
#define BAUD_RATE 19200
#define CHAR_BUF 128
void setup() {
pinMode(SS_PIN, OUTPUT);
Serial.begin(BAUD_RATE);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE0);
delay(1000); // Give the OpenMV Cam time to bootup.
}
void loop() {
int32_t temp = 0;
char buff[CHAR_BUF] = {0};
digitalWrite(SS_PIN, LOW);
delay(1); // Give the OpenMV Cam some time to setup to send data.
if (SPI.transfer(1) == 85) { // saw sync char?
SPI.transfer(&temp, 4); // get length
int zero_legnth = 4 + ((temp + 1) % 4);
if (temp) {
SPI.transfer(&buff, min(temp, CHAR_BUF));
temp -= min(temp, CHAR_BUF);
}
while (temp--) SPI.transfer(0); // eat any remaining bytes
while (zero_legnth--) SPI.transfer(0); // eat zeros.
}
digitalWrite(SS_PIN, HIGH);
Serial.print(buff);
delay(1); // Don't loop to quickly.
}
sketch_jan03a.ino: In function 'void loop()':
sketch_jan03a:23: error: no matching function for call to 'SPIClass::transfer(int32_t*&, int)'
D:\360Downloads\Arduino\libraries\SPI/SPI.h:55: note: candidates are: static byte SPIClass::transfer(byte)
sketch_jan03a:24: error: invalid operands of types 'int32_t*' and 'int' to binary 'operator%'
sketch_jan03a:26: error: ISO C++ forbids comparison between pointer and integer
sketch_jan03a:26: error: operands to ?: have different types 'int32_t*' and 'int'
sketch_jan03a:27: error: ISO C++ forbids comparison between pointer and integer
sketch_jan03a:27: error: operands to ?: have different types 'int32_t*' and 'int'arduino UNO的板子应该没错吧 SPI.transfer(&temp, 4); // get length
transfer第一个参数应该数传输的数组吧 这个程序传输的是数组吗?
-
我编译这个程序没有问题。
-
那是使用arduino软件版本的问题吗?我使用的是arduino1.0.6
-
软件当然要用最新版的。
-
@kidswong999 好的 谢谢