Go Down

Topic: SPI communication between esp nodemcu with arduino uno (Read 89 times) previous topic - next topic

kolhapurkar

 
I am new to arduino serial pheripheral interface ,i want to send  data to  nodemcu from arduino uno ...


i downloded code from internet for testing purpose but it unclear and find some error in declaration  ,as per my view  these is just simple code but dont know why it get error....

so please guide to solve these problem....

arduino uno work as slave device while node mcu master device.code are like that....



[nodemcu master code]


#include<SPI.h>

char buff[]="Hello Slave\n";

void setup() {
 Serial.begin(9600); /* begin serial with 9600 baud */
 SPI.begin();  /* begin SPI */
}

void loop() {
 for(inti=0; i<sizeof buff; i++)  /* transfer buff data per second */
  SPI.transfer(buff);
 delay(1000); 
}


[arduino uno slave code ]


#include <SPI.h>

char buff [100];
volatile byte index;
volatile bool receivedone;  /* use reception complete flag */

void setup (void)
{
  Serial.begin (9600);
  SPCR |= bit(SPE);         /* Enable SPI */
  pinMode(MISO, OUTPUT);    /* Make MISO pin as OUTPUT */
  index = 0;
  receivedone = false;
  SPI.attachInterrupt();    /* Attach SPI interrupt */
}

void loop (void)
{
  if (receivedone)          /* Check and print received buffer if any */
  {
    buff[index] = 0;
    Serial.println(buff);
    index = 0;
    receivedone = false;
  }
}

// SPI interrupt routine
ISR (SPI_STC_vect)
{
  uint8_t oldsrg = SREG;
  cli();
  char c = SPDR;
  if (index <sizeof buff)
  {
    buff [index++] = c;
    if (c == '\n'){     /* Check for newline character as end of msg */
     receivedone = true;
    }
  }
  SREG = oldsrg;
}

/////////////////////////////////////////////////////




Juraj

You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

pylon

The NodeMCU is 3V3 device while the UNO runs at 5V. Did you use a level converter between them? Otherwise you might have already fried the ESP.

Go Up