Interrupt communication


hello guys!

i performing communication between 3 nodes, (1) tx continuously transmitting data ack on, (2) rx continuously receiving data 1 ack on , transfering same data 3 when requested through interrupt, (3) master requests transfer of data 2 through interrupt.

every 10 ms master set pin 2 of rx high causing interrupt. node rx send data master.

the problem here system not working. :p

in point of view seems interrupt long, because if reduce loop size, 20, 19 works. in other words, data in master if reduce loop size.

bellow can find code of rx. master requesting transfer , tx transmitting data.

what happening can't make work larger loop size? hope clear enough...

btw, using 4 lsb portc 0-3 , 4msb portd 4-7.

code: [select]
/*
  jul 2016 - communication module

#include <spi.h>
#include <spritzcipher.h>
#include "rf24.h"
#include "nrf24l01.h"
#include "3ccar.h"
#include "digitalio.h"

/*************************** user config ***************************/
bool role = 1;                                        // choosign nodes. can set external pin.

/*************************** instantiations ***************************/
rf24 radio(7,8);                                      // hardware configuration: set nrf24l01 radio on spi bus plus pins 7 & 8

/*************************** global variables ***************************/
const byte addresses[][8] = {"1node","2node","3node","4node",
                             "5node","6node","7node","8node"};
const byte key[10] = { 0x03, 0x01, 0x02, 0x07, 0x01,
                       0x06, 0x01, 0x02, 0x08, 0x01 };
byte data[10] = { 0x95, 0x28, 0x0a, 0x9a, 0xf1,
                  0x31, 0x08, 0x17, 0xf0, 0xb2 };
byte data_tx[20];                                     // transmitted data
byte data_rx[20];                                     // received data
unsigned long packet_received = 0;                             // unsigned long packet_received = 0;
unsigned int clk_pin = 9;
unsigned int ss_pin = 2;

/*************************** setup - state 0 ***************************/
void setup(){

  //serial.begin(115200);
  radio.begin();                                       // setup , configure rf radio
  radio.setchannel(115);                               // set channel
  radio.setpalevel(rf24_pa_low);             // set pa low demonstration.
  radio.setdatarate(rf24_1mbps); //              
  radio.setautoack(1);                                 // ensure autoack enabled
  radio.setcrclength(rf24_crc_16);          // set crc length 16-bit
  if(role){                                           // transmitter address "1node"
    radio.openwritingpipe(addresses[1]);          
    radio.openreadingpipe(1,addresses[0]);            
  }else{                                               // receiver address "2node"
    radio.openwritingpipe(addresses[0]);            
    radio.openreadingpipe(1,addresses[1]);          
  }
  radio.startlistening();                             // start listening should come after pipes.

//setting interrupt
 pinmode(ss_pin, input);
 pinmode(clk_pin, input);
 ddrc |= b00001111;
 ddrd |= b01111000;
 portc &= b11110000;
 portd &= b10000111;

attachinterrupt(digitalpintointerrupt(ss_pin), spi_transfer, falling);

}

/*************************** main loop ***************************/
void loop() {

  if ( radio.available() ){                            
      radio.read( &data_rx, sizeof(data_rx) );        
      packet_received++;                              
  } 
  
}

/*************************** functions ***************************/

void spi_transfer() {   // out_pin can miso or mosi

  (int j = 0; j<20; j++){
    while(!digitalread(clk_pin));
    while(digitalread(clk_pin));
    portc = data_rx[j]; // 4 lsb
    portd = data_rx[j] >> 1; // 4 msb
  }
  
}



Arduino Forum > Using Arduino > Microcontrollers > Interrupt communication


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'