Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: DUE: Reading Serial data into two dimensional array, it skips every other index. on: December 09, 2013, 12:51:54 am
No offense taken. Reading it now, I will try to make it more understandable before resubmitting.
2  Using Arduino / Programming Questions / Re: DUE: Reading Serial data into two dimensional array, it skips every other index. on: December 09, 2013, 12:19:06 am
Dang, I knew there was a way to get the code to interpret the data for you. I will use the ' ' for sure.

With regard to the looping 42 times, I have a break when it detects my "start" char, basically a way to ensure that I am starting at a known point, I realize now though that since I am reading through the data with different letters to index, I can really start anywhere one of those chars exist. Thanks for the pointer there.
Code:
    if (state == 0){
      for(i=0;i<43;i++)
      {
        serialChar = Serial1.read();
        if (serialChar == 32){
          state = 1;
          serialProcess(state);
          break;


Anyway, I am still having the problem here

Code:
                else if ((serialChar != 32) && (serialChar !=255))
                {
Serial.print("Echoing State before print state: ");
Serial.println(state);
Serial.print("Char: ");
Serial.write(serialChar);
                    Serial.print("");
                    serialData[(state-1)][i2] = serialChar;
                    i2++;
                }

This line
                   
Code:
serialData[(state-1)][i2] = serialChar;
Is supposed to put the currently read char at the [state-1][increment] of the char array, but for some reason [state] is doing weird things and data is only getting stored in the 0,2,4 arrays of the the first dimension.
When I do 
Code:
Serial.print("Echoing State before print state: ");
Serial.println(state);
I get matching states with the data they belong to.
3  Using Arduino / Programming Questions / DUE: Reading Serial data into two dimensional array, it skips every other index. on: December 08, 2013, 11:27:31 pm
As the title says I have a two dimensional array that I am attempting to read data into.
byte serialData[6][6]

If you look at the code below the idea is that I'm trying to take this
Quote
 123456B789012C345678D012345E555555F666666
data and parse it. What I am doing appears to work great,
I use the SPACE char at the beginning to start the parse and then the B-F char to split the 6 bytes of data. Each time I get a new alpha char I am incrementing the first index of the array and then taking the data chars into the 2nd index.

When I print the values of serialData[i] I get the below results


Code:
[0]   = 111111
[0][1][2][3][4][5]
[1] = NULL
[0][1][2][3][4][5]
[2] = 222222
[0][1][2][3][4][5]
[3] = NULL
[0][1][2][3][4][5]
[4] = 333333
[0][1][2][3][4][5]
[5] = NULL
[0][1][2][3][4][5]

If I print even farther than I am even defining in the array...
Code:
serialData[6] = 444444
serialData[7] = NULL
serialData[8] = 555555



What the heck am I doing wrong? Why is it incrementing twice?!?

Thank you!


Code:
// State machine values
int state =0;

byte serialData[6][6] = {0};

//serial data
byte serialChar =0;
boolean newData =0;
byte i2 = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Serial 1 Good Morning");
  Serial1.begin(115200);
  Serial1.println("Serial 2 Good Morning");
}

void loop() {
  
          if (Serial1.available() > 42) {
            newData = true;
            Serial.write("***** BEGIN DATA state = ");
            if (state == 0){
              for(i=0;i<43;i++)
              {
                serialChar = Serial1.read();
                if (serialChar == 32){
                  state = 1;
                  serialProcess(state);
                  break;
                }
              }
                      
            }            
          }


          delay(250);
  
  if (newData){
    Serial.write("{t1:");
    Serial.print(serialData[0]);
    
    Serial.write(",t2:");
    Serial.print(serialData[1]);
    
    Serial.write(",t3:");
    Serial.print(serialData[2]);
    
    Serial.write(",lat:");
    Serial.print(serialData[3]);
    
    Serial.write(",lon:");
    Serial.print(serialData[4]);
  
    Serial.write(",rpm:");
    Serial.print(serialData[5]);
  
    Serial.write("}");
    Serial.println("");
    
    newData =false;
  }

}
          
void serialProcess(int st){
      Serial.println("");
      Serial.print("State of: ");
      Serial.println(state);
      for (byte i=0; i<7; i++) {
                serialChar = Serial1.read();

                
                if ((serialChar > 65) && (serialChar < 71)){
                  if (serialChar == 66){state = 2;}
                  if (serialChar == 67){state = 3;}
                  if (serialChar == 68){state = 4;}
                  if (serialChar == 69){state = 5;}
                  if (serialChar == 70){state = 6;}
                  serialProcess(state);
                  i2=0;
                  break;
                }
                else if ((serialChar != 32) && (serialChar !=255))
                {
Serial.print("Echoing State before print state: ");
Serial.println(state);
Serial.print("Char: ");
Serial.write(serialChar);
                    Serial.print("");
                    serialData[(state-1)][i2] = serialChar;
                    i2++;
                }
                else if (serialChar == 13){
                  i2=0;
                  state=0;
                  Serial.println("");
                  Serial.println("***END OF DATA***");
                  break;
                }
      }
      
}


Moderator edit: [code] ... [/code] tags added to debug output. (Nick Gammon)
4  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: August 03, 2013, 04:51:50 am
Thank you for the great response! Would it be possible for me to roll through different can ids and data locations as I looped? so in other words I could still have 8 mailboxes per loop but have toggle that redirected the mailboxes after each send? I'll try this tomorrow
5  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: August 02, 2013, 05:14:58 pm
Is there any way at all to get more than 8 total mailboxes?

Code:
CAN.global_send_transfer_cmd(CAN_TCR_MB0 | CAN_TCR_MB1 | CAN_TCR_MB2 | CAN_TCR_MB3 | CAN_TCR_MB4 | CAN_TCR_MB5 | CAN_TCR_MB6 | CAN_TCR_MB7 | CAN_TCR_MB8 | CAN_TCR_MB9 | CAN_TCR_MB10 | CAN_TCR_MB11 | CAN_TCR_MB12);

Code:
dueCAN4.ino: In function 'void loop()':
dueCAN4:475: error: 'CAN_TCR_MB8' was not declared in this scope
dueCAN4:475: error: 'CAN_TCR_MB9' was not declared in this scope
dueCAN4:475: error: 'CAN_TCR_MB10' was not declared in this scope
dueCAN4:475: error: 'CAN_TCR_MB11' was not declared in this scope
dueCAN4:475: error: 'CAN_TCR_MB12' was not declared in this scope


I tried this in the library... but not sure what is going on


due_can.cpp
Code:
void CANRaw::interruptHandler() {

uint32_t ul_status = m_pCan->CAN_SR; //get status of interrupts

if (ul_status & CAN_SR_MB0) { //mailbox 0 event
mailbox_int_handler(0, ul_status);
}
if (ul_status & CAN_SR_MB1) { //mailbox 1 event
mailbox_int_handler(1, ul_status);
}
if (ul_status & CAN_SR_MB2) { //mailbox 2 event
mailbox_int_handler(2, ul_status);
}
if (ul_status & CAN_SR_MB3) { //mailbox 3 event
mailbox_int_handler(3, ul_status);
}
if (ul_status & CAN_SR_MB4) { //mailbox 4 event
mailbox_int_handler(4, ul_status);
}
if (ul_status & CAN_SR_MB5) { //mailbox 5 event
mailbox_int_handler(5, ul_status);
}
if (ul_status & CAN_SR_MB6) { //mailbox 6 event
mailbox_int_handler(6, ul_status);
}
if (ul_status & CAN_SR_MB7) { //mailbox 7 event
mailbox_int_handler(7, ul_status);
}
if (ul_status & CAN_SR_MB8) { //mailbox 7 event
mailbox_int_handler(8, ul_status);
}
if (ul_status & CAN_SR_MB9) { //mailbox 7 event
mailbox_int_handler(9, ul_status);
}
if (ul_status & CAN_SR_MB10) { //mailbox 7 event
mailbox_int_handler(10, ul_status);
}
if (ul_status & CAN_SR_MB11) { //mailbox 7 event
mailbox_int_handler(11, ul_status);
}
if (ul_status & CAN_SR_MB12) { //mailbox 7 event
mailbox_int_handler(12, ul_status);
}

keywords.txt
Code:
CAN_TCR_MB0 LITERAL1
CAN_TCR_MB1 LITERAL1
CAN_TCR_MB2 LITERAL1
CAN_TCR_MB3 LITERAL1
CAN_TCR_MB4 LITERAL1
CAN_TCR_MB5 LITERAL1
CAN_TCR_MB6 LITERAL1
CAN_TCR_MB7 LITERAL1
CAN_TCR_MB8 LITERAL1
CAN_TCR_MB9 LITERAL1
CAN_TCR_MB10 LITERAL1
CAN_TCR_MB11 LITERAL1
CAN_TCR_MB12 LITERAL1

I didn't know I was so limited in this respect and am almost ready for this project and just hit an enormous wall!
6  Using Arduino / Project Guidance / Re: Power Due completely from 3.3v pin on: July 16, 2013, 08:38:41 pm
I have a lot of other 3.3v components and wanted really really clean power. For this version It sounds like I should just run 12v to VIN and then disconnect the other power lines. I have to run out real quick but wanted to thank you so much for your fast response!!
7  Using Arduino / Project Guidance / Power Due completely from 3.3v pin on: July 16, 2013, 07:11:57 pm
Can I power the due completely via the 3.3v power pin? I have it sitting on a board where a http://www.adafruit.com/datasheets/tsr1.pdf is providing 3.3v power, but I am unable to get it to output it's CAN and I'm not sure it's doing it's i2c duties either.

Thanks!


If the answer is no, I have a 12v incoming supply to the TSR-1 buck converter, could I just run a wire from it to the due's VIN pin? Is there consequences to running a Due 24/7/365 in this fashion?

(I noticed from this http://forum.arduino.cc/index.php?topic=132130.0) that it "depends on current drawn" My bench power shows I'm drawing 0.07amps right now running almost everything.

Would the Due conflict with the regulated supply if I did this? seems I should disconnect the 3.3v pin if I were to power the Due this way.


Thank you!!
8  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: May 11, 2013, 04:22:43 am


So far so good smiley

Thanks for the tip about being able to do this Adder
CAN.global_send_transfer_cmd(CAN_TCR_MB0 | CAN_TCR_MB1 | CAN_TCR_MB2 | CAN_TCR_MB3 | CAN_TCR_MB4);

Worked perfectly!
9  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: April 25, 2013, 12:02:59 pm
It seems to me that the only thing you're really lacking is that you forgot to pull the trigger at the end. You have to tell it to send those mailboxes once you load them. You can do this one at a time, stagger them, or however you wish. If you want to try to tell it to send all of the mailboxes as fast as it can then do this:

Code:
 CAN.global_send_transfer_cmd(CAN_TCR_MB0 | CAN_TCR_MB1 | CAN_TCR_MB2 | CAN_TCR_MB3 | CAN_TCR_MB4);  //send frame in mailbox 0-4

I should probably abstract that a bit. It looks kind of ugly as-is.


I made the change - here is my code again. I still am only getting out on the first TEST1_CAN_TRANSFER_ID smiley-sad

Thank you!

Quote
#include <Wire.h>
#include "variant.h"
#include <due_can.h>

#define TEST1_CAN_COMM_MB_IDX    0
#define TEST1_CAN_TRANSFER_ID    0x07
#define TEST2_CAN_TRANSFER_ID    0x08
#define TEST3_CAN_TRANSFER_ID    0x08
#define TEST4_CAN_TRANSFER_ID    0x09
#define TEST5_CAN_TRANSFER_ID    0x0A
#define TEST1_CAN0_TX_PRIO       15
#define CAN_MSG_DUMMY_DATA       0x55AAAA55

// CAN frame max data length
#define MAX_CAN_FRAME_DATA_LEN   8

// Message variable to be send
uint32_t CAN_MSG_1 = 0;
uint32_t CAN_MSG_2 = 0;
uint32_t CAN_MSG_3 = 0;
uint32_t CAN_MSG_4 = 0;
uint32_t CAN_MSG_5 = 0;
uint32_t CAN_MSG_6 = 0;
uint32_t CAN_MSG_7 = 0;
uint32_t CAN_MSG_8 = 0;
uint32_t CAN_MSG_9 = 0;
uint32_t CAN_MSG_10 = 0;
uint32_t CAN_MSG_11 = 0;
uint32_t CAN_MSG_12 = 0;

  // Initialize CAN1 mailbox 0 as receiver, frame ID is 0x07
  CAN.init(SystemCoreClock, CAN_BPS_250K);
  CAN.reset_all_mailbox();
  // Initialize CAN0 mailbox 0 as transmitter, transmit priority is 15
  CAN.mailbox_init(0);
  CAN.mailbox_init(1);
  CAN.mailbox_init(2); 
  CAN.mailbox_init(3);
  CAN.mailbox_init(4); 
  CAN.mailbox_set_mode(0, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(1, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(2, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(3, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(4, CAN_MB_TX_MODE); 
  CAN.mailbox_set_priority(0, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(1, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(2, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(3, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(4, TEST1_CAN0_TX_PRIO);
  
  CAN.mailbox_set_accept_mask(0, 0, false);
  // Prepare transmit ID, data and data length in CAN0 mailbox 0
  CAN.mailbox_set_id(0, TEST1_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(0, CAN_MSG_1);
  CAN.mailbox_set_datah(0, CAN_MSG_2);
  CAN.mailbox_set_datalen(0, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(1, TEST2_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(1, CAN_MSG_3);
  CAN.mailbox_set_datah(1, CAN_MSG_DUMMY_DATA);
  CAN.mailbox_set_datalen(1, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(2, TEST3_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(2, CAN_MSG_5);
  CAN.mailbox_set_datah(2, CAN_MSG_6);
  CAN.mailbox_set_datalen(2, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(3, TEST4_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(3, CAN_MSG_7);
  CAN.mailbox_set_datah(3, CAN_MSG_8);
  CAN.mailbox_set_datalen(3, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(4, TEST5_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(4, CAN_MSG_9);
  CAN.mailbox_set_datah(4, CAN_MSG_DUMMY_DATA);
  CAN.mailbox_set_datalen(4, MAX_CAN_FRAME_DATA_LEN);



  // Send out the information in the mailbox
  CAN.global_send_transfer_cmd(CAN_TCR_MB0);
  CAN.global_send_transfer_cmd(CAN_TCR_MB1);
  CAN.global_send_transfer_cmd(CAN_TCR_MB2);
  CAN.global_send_transfer_cmd(CAN_TCR_MB3);
  CAN.global_send_transfer_cmd(CAN_TCR_MB4); 

  CAN.disable();

10  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: April 24, 2013, 03:57:26 am
Maybe a little help here though. I would like to send more than 8 bytes, the following excerpt of code was my best guess but it sits there with a blank stare.

What do I need to change if I want to send this other data?

Thanks!


Code:
#define TEST1_CAN_COMM_MB_IDX    0
#define TEST0_CAN_TRANSFER_ID    0x07
#define TEST1_CAN_TRANSFER_ID    0x08
#define TEST2_CAN_TRANSFER_ID    0x08
#define TEST3_CAN_TRANSFER_ID    0x09
#define TEST4_CAN_TRANSFER_ID    0x0A
#define TEST1_CAN0_TX_PRIO       15
#define CAN_MSG_DUMMY_DATA       0x55AAAA55


      CAN.init(SystemCoreClock, CAN_BPS_250K);
  CAN.reset_all_mailbox();
  // Initialize CAN0 mailbox 0 as transmitter, transmit priority is 15
  CAN.mailbox_init(0);
  CAN.mailbox_init(1);
  CAN.mailbox_init(2); 
  CAN.mailbox_init(3);
  CAN.mailbox_init(4); 
  CAN.mailbox_set_mode(0, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(1, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(2, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(3, CAN_MB_TX_MODE);
  CAN.mailbox_set_mode(4, CAN_MB_TX_MODE); 
  CAN.mailbox_set_priority(0, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(1, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(2, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(3, TEST1_CAN0_TX_PRIO);
  CAN.mailbox_set_priority(4, TEST1_CAN0_TX_PRIO);
 
  CAN.mailbox_set_accept_mask(0, 0, false);
  // Prepare transmit ID, data and data length in CAN0 mailbox 0
  CAN.mailbox_set_id(0, TEST0_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(0, CAN_MSG_1);
  CAN.mailbox_set_datah(0, CAN_MSG_2);
  CAN.mailbox_set_datalen(0, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(1, TEST1_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(1, CAN_MSG_3);
  CAN.mailbox_set_datah(1, CAN_MSG_4);
  CAN.mailbox_set_datalen(1, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(2, TEST2_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(2, CAN_MSG_5);
  CAN.mailbox_set_datah(2, CAN_MSG_6);
  CAN.mailbox_set_datalen(2, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(3, TEST3_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(3, CAN_MSG_7);
  CAN.mailbox_set_datah(3, CAN_MSG_8);
  CAN.mailbox_set_datalen(3, MAX_CAN_FRAME_DATA_LEN);

  CAN.mailbox_set_id(4, TEST4_CAN_TRANSFER_ID, false);
  CAN.mailbox_set_datal(4, CAN_MSG_9);
  CAN.mailbox_set_datah(4, CAN_MSG_DUMMY_DATA);
  CAN.mailbox_set_datalen(4, MAX_CAN_FRAME_DATA_LEN);
11  Products / Arduino Due / Re: [ now published on github ] Building a CAN API for Arduino DUE on: April 23, 2013, 01:10:41 pm
Thank you all again for your wonderful work - just vouching for the awesomeness of Adder's work

I really liked this sparkfun shield

12  Products / Arduino Due / Re: Building a CAN communication protocol interface for Arduino DUE on: January 31, 2013, 04:11:02 pm
I'm in the same position as Zabaat.

I'll build the Pseude shield ASAP and post pics. Maybe I try out another HW solution from the IC I have right here. I would also like to be collaborating with a beta release and feedback you directly.

Cheers

Lufe

Lufe - I'm working to build a better "industrial protocol" arduino board, integrating modbus / rs232 (12v) and CAN and 2x Due chips. I just saw Palliser's ethernet addin and am debating adding that in by exposing those pins off of the dues for future expansion for profinet if possible. Is this something you would be interest in collaborating in?
13  Products / Arduino Due / Re: Building a CAN communication protocol interface for Arduino DUE on: January 30, 2013, 02:39:48 pm
zabaat,
What you're saying is partly true, until the new CAN library is published. The Atmel engineer that developed a prior CAN API for the SAM3X8H, is supporting Arduino with this CAN interface for Due. Once the library is on github, everyone should start to test/discuss/contribute. And I say partly because at this very moment people in this forum could be contributing, let's say, with the design of the shield. Electric schematics have been published here. I have also shown a couple of my shield approaches. What I would like to hear in this post is: My pseudo CAN shield is ready. Here a picture of it, but I have yet to see any of them here. Does that really matter? Yes, because otherwise, you can't do any test or discuss or contribute just with the sketch or the classes. Am I right?


Oh, I guess I was waiting the same way, thinking what use is a can shield in my efforts to contribute to the testing when I have  no sketch or classes. Since it's now clear that is what I need to do to get access. I will build the shield as you have listed and post it's picture. I have had 20 of the chips and 4 Dues for a couple weeks now, definitely would have built this had I known.

I already posses a good understanding of the protocol, USB-CAN adapters and debugging software tools to tackle this. I even have a project that needs it.

I would suggest making a closed project at least for people that understand it is in beta stage so you can control the feedback you get.

14  Products / Arduino Due / Re: Building a CAN communication protocol interface for Arduino DUE on: January 30, 2013, 12:05:42 pm
Hi everybody!

I`m quite new to the Arduino world, but not to the uC world. I'd like to collaborate as much as possible with the development of the CAN API for the Arduino DUE. I actually have several DUE and other Arduino boards (with the necessary shields) and USB CAN interfaces, as well as other applications that are extensively using CAN BUS.

I'm very sorry of not having been able to start collaborating with you earlier, but I really would like to help as much as possible in any task you give me.

Cheers!

Lufe



Except we can't contribute or do anything, it's really fun this way...
15  Products / Arduino Due / Re: Building a CAN communication protocol interface for Arduino DUE on: January 07, 2013, 05:22:01 am
Hi that_kid. I am sorry to know about your broken foot. Just take it easy. Even thou I have my shield working OK, I still looking for a better out-of-the-shelf board that fits better the design. I am also working on some eagle files to build, at some time, my own design. Remember that for the two transceiver we are going to need 8 pins of the Arduino DUE (CANRX0, CANTX0, CANEN0, CANRS0, CANRX1, CANTX1, CANEN1, CANRS1). For my tests, I didn't use the EN and RS pins. I just connected them to +3.3 and ground respectively.

I've been lurking on this thread since you started it. I would be happy to collaborate on the Eagle files and even fab a board as this fits with my plans. I would be happy to produce a run and share the rate with the good people here. My board would integrate modbus via MAX485 as well with very little extra cost. I also would love even a very beta copy of your sketch if possible.
Pages: [1] 2