我正在尝试编写一个用于从自动售货机读取数据的小 C 测试程序。我已经连接了电路,现在最难的部分是代码。该机器使用需要 9 个总数据位的 UART。这是我的代码。尝试直接写入完整的 9 位数据类型不起作用,但写入其中的一个元素可以。
struct nineBit { //To make 9 bit character types for an array.
unsigned int data : 8; //8 data bits.
unsigned int mode : 1; //1 'mode' bit.
} data[35]; //Make an array of 9 bit data to store the incoming data block.
void setup() {
Serial1.begin(9600, SERIAL_9N1); //Start the UART.
}
void loop() {
data[0] = Serial1.read(); //Works if 'data[0].data is entered instead.
//How can I transfer this all in one command?
}
错误是 rx.cpp: In function 'void loop()': rx.cpp:11:12: error: no match for 'operator=' (operand types are 'nineBit' and 'int') void setup() { ^
rx.cpp:11:12: note: candidates are:
rx.cpp:1:8: note: nineBit& nineBit::operator=(const nineBit&)
^
rx.cpp:1:8: note: no known conversion for argument 1 from 'int' to 'const nineBit&'
rx.cpp:1:8: note: nineBit& nineBit::operator=(nineBit&&)
rx.cpp:1:8: note: no known conversion for argument 1 from 'int' to 'nineBit&&'
make[1]: *** [../build/target/user/platform-6rx.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.