Go Down

Topic: Can bus help (Read 554 times) previous topic - next topic


Hi Gents
please help to solve
i'm trying to send some frames from sd card. Serial printing of data is correct  before send , but on can bus port readed data field is empty (clear) id and rest is fine
any ideas ??
its some memory collision while reading sd at  --buffer = printFile.readStringUntil('\n');

void setup()
   //***********************  SD  **********************


void sendData()
 if (!sd.begin(chipSelect, SPI_SIXTEENTH_SPEED)) {
 if (! printFile.open("Run.txt", O_READ))
 { sd.errorHalt("opening test.txt for read failed");
 mydisp.println("card failure ");
  while (printFile.available()) {
   buffer = printFile.readStringUntil('\n');
    CAN_FRAME outgoing;
outgoing.id = strtol(buffer.substring(0,8).c_str(), NULL, 16);
 outgoing.extended = true;
 outgoing.priority = 4; //0-15 lower is higher priority
outgoing.data.byte[7] =  strtol(buffer.substring(9,11).c_str(), NULL, 16);
 outgoing.data.byte[6] =  strtol(buffer.substring(12,14).c_str(), NULL, 16);
  outgoing.data.byte[5] =  strtol(buffer.substring(15,17).c_str(), NULL, 16);
   outgoing.data.byte[4] =  strtol(buffer.substring(18,20).c_str(), NULL, 16);
    outgoing.data.byte[3] =  strtol(buffer.substring(21,23).c_str(), NULL, 16);
     outgoing.data.byte[2] =  strtol(buffer.substring(24,26).c_str(), NULL, 16);
      outgoing.data.byte[1] =  strtol(buffer.substring(27,29).c_str(), NULL, 16);
       outgoing.data.byte[0] =  strtol(buffer.substring(30,32).c_str(), NULL, 16);

Serial.print(outgoing.id,HEX);Serial.print(" "); Serial.print(outgoing.data.high,HEX);Serial.println(outgoing.data.low,HEX);
    delay (1000);


//goto openfile;  

void loop()
   delay (1000);


Make sure to set rtr to 0 when you are sending frames. If RTR were to get set you'd be sending a remote data request and wouldn't have data bytes. Perhaps I should have added a constructor that sets the various parameters to sane values. As it sits CAN_FRAME is a struct with no constructor so no attempt is made to set anything to a realistic value. Thus, always set id, length, priority, data bytes, rtr, and extended or they might default to something dumb.

Go Up