Go Down

Topic: I am having trouble repeating a function (Read 459 times) previous topic - next topic

Acrogen

Hi ,

I am having trouble getting my CAN shield to output 2 pieces of data alternatly. all it does is showes the first piec of data once and then repeats the second piece of data repeatedly.

Code: [Select]
#include <CAN.h>
#include <SPI.h>

#define BUS_SPEED 500

//global variable used to determine whether loop should
//be in Tx or Rx mode.
int state;
//global variable used to toggle pin
int pin;

void setup() {               

 
  Serial.begin(9600);
 
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
 
  // initialize CAN bus class
  // this class initializes SPI communications with MCP2515
  CAN.begin();
  CAN.baudConfig(BUS_SPEED);
  CAN.setMode(NORMAL);
  //CAN.setMode(LOOPBACK);  // set to "NORMAL" for standard com
 
  //Wait 10 seconds so that I can still upload even
  //if the previous iteration spams the serial port
  delay(100);
 
  state = 0;

  pin = LOW; 
}
byte val = 0;
void loop() {
 
  byte length,rx_status,i;
  unsigned short frame_id;
  byte frame_data[8];

      frame_data[0] = val;
      frame_data[1] = 0xAA;
      frame_data[2] = 0x0F;
      frame_data[3] = 0xAA;
      frame_data[4] = 0x02;
      frame_data[5] = 0x1F;
      frame_data[6] = 0xDD;
      frame_data[7] = 0x7A;
 
      frame_id = 0x1d4;
      length = 8;

 

     
   
     
      CAN.load_ff_0(length,frame_id,frame_data);
      CAN.load_ff_1(length,0x1d5,frame_data);
      //CAN.load_ff_2(1,0x1d6,frame_data);
      CAN.send_0();   
      CAN.send_1();
      //CAN.send_2();
     

       val++;
  delay(10);

}

Thanks in advanced

PaulS

Code: [Select]
//global variable used to determine whether loop should
//be in Tx or Rx mode.
int state;

Then, why are you not explicitly giving it a value?

Code: [Select]
  //Wait 10 seconds so that I can still upload even
  //if the previous iteration spams the serial port
  delay(100);

Always good when the comments match the code.

Quote
I am having trouble getting my CAN shield to output 2 pieces of data alternatly. all it does is showes the first piec of data once and then repeats the second piece of data repeatedly.

What two pieces of data? All I see you sending it is val.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy