Hello everyone ,
i am doing the SPI communication between arduino ADK and arduino Mega . when i am doing this with normal code or you can with normal loop it's working but when i am connecting XBOX to Arduino ADK and try to get some value in arduino mega it's not working . inshort i want do communication between mega and adk and some button of xbox is pressed i want send some valu to mega . please give me the guidance.
Master code
''' include<SPI.h>
int x;
void setup (void)
{
Serial.begin(115200);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
digitalWrite(SS,HIGH);
}
void loop(void)
{
byte m_send,m_receive;
x = 1;
digitalWrite(SS, LOW);
m_send = x;
m_receive=SPI.transfer(m_send);
Serial.println(m_receive);
delay(1000);
}
'''
Slave code
'''include<SPI.h>
volatile boolean received;
volatile byte Slavereceived,Slavesend;
int x;
void setup()
{
Serial.begin(115200);
pinMode(MISO,OUTPUT);
SPCR |= _BV(SPE);
received = false;
SPI.attachInterrupt();
}
ISR (SPI_STC_vect)
{
Slavereceived = SPDR;
received = true;
}
void loop()
{
if(received)
{
Serial.println(Slavereceived);
x=9;
Slavesend=x;
SPDR = Slavesend;
delay(1000);
}
}
'''
this was my normal code which is working.