I'm trying to integrate an SPI connection to my flutter project, so I use a Raspberry Pi as master and an arduino as slave.
The arduino gets each byte of the request and returns a byte not related to the request (tested and working with another arduino as master).
When I try to communicate with my program, the arduino does retrieve the command sent, but in the result logged in the flutter project, it shows me the command sent and not the one the arduino is supposed to return.
My Flutter code:
var spi = SPI(0, 0, SPImode.MODE0, 500000);
try {
print('SPI info:' + spi.getSPIinfo());
var data = utf8.encode("Some data\r");
var result = spi.transfer(data, false);
var index = 0;
for (var v in data) {
print('Send $v->Answer ${result[index++]}');
}
print(utf8.decode(result));
} catch (e) {
print(e);
} finally {
spi.dispose();
}
My Arduino code:
#include <SPI.h>
char buff [50];
char resp [50] = "Helo diti\r";
volatile byte indx;
void setup (void) {
Serial.begin (9600);
pinMode(MISO, OUTPUT); // have to send on master in so it set as output
SPCR |= _BV(SPE); // turn on SPI in slave mode
indx = 0; // buffer empty
SPI.attachInterrupt(); // turn on interrupt
}
ISR (SPI_STC_vect)
{
byte c = SPDR; // read byte from SPI Data Register
if (indx < sizeof buff) {
buff [indx] = c; // save data in the next index in the array buff
SPDR = byte(resp[indx]);
indx++;
if (c == '\r') {
Serial.println(buff);
indx = 0; //reset button to zero
}
}
}
void loop (void) {
}
Hi,
I'm trying to integrate an SPI connection to my flutter project, so I use a Raspberry Pi as master and an arduino as slave.
The arduino gets each byte of the request and returns a byte not related to the request (tested and working with another arduino as master).
When I try to communicate with my program, the arduino does retrieve the command sent, but in the result logged in the flutter project, it shows me the command sent and not the one the arduino is supposed to return.
My Flutter code:
My Arduino code:
What is logged:
Expected:
Returned with master Arduino:
Thank you for your help