Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test sketch block after 17 send messages #20

Closed
Mplex72 opened this issue Oct 2, 2020 · 14 comments
Closed

Test sketch block after 17 send messages #20

Mplex72 opened this issue Oct 2, 2020 · 14 comments

Comments

@Mplex72
Copy link

Mplex72 commented Oct 2, 2020

What did I do wrong within this sketch on arduino UNO?
it will send only 17 meassages , then I have "failure" in the serial interface .

<
/*
*
*/
#include <ACAN2515.h>

static const byte MCP2515_CS = 10 ; // CS input of MCP2515 (adapt to your design)
static const byte MCP2515_INT = 3 ; // INT output of MCP2515 (adapt to your design)

ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ;

static const uint32_t QUARTZ_FREQUENCY = 8UL * 1000UL * 1000UL ; // 8 MHz

void setup() {

Serial.begin (38400) ;

while (!Serial) {
delay (50) ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
}
SPI.begin () ;

ACAN2515Settings settings (QUARTZ_FREQUENCY, 500UL * 1000UL) ; // CAN bit rate 500 kb/s
const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ;
if (errorCode == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Propagation Segment: ") ;
Serial.println (settings.mPropagationSegment) ;
Serial.print ("Phase segment 1: ") ;
Serial.println (settings.mPhaseSegment1) ;
Serial.print ("Phase segment 2: ") ;
Serial.println (settings.mPhaseSegment2) ;
Serial.print ("SJW: ") ;
Serial.println (settings.mSJW) ;
Serial.print ("Triple Sampling: ") ;
Serial.println (settings.mTripleSampling ? "yes" : "no") ;
Serial.print ("Actual bit rate: ") ;
Serial.print (settings.actualBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact bit rate ? ") ;
Serial.println (settings.exactBitRate () ? "yes" : "no") ;
Serial.print ("Sample point: ") ;
Serial.print (settings.samplePointFromBitStart ()) ;
Serial.println ("%") ;
}else{
Serial.print ("Configuration error 0x") ;
Serial.println (errorCode, HEX) ;
}
}
static uint32_t gBlinkLedDate = 0 ;
static uint32_t gReceivedFrameCount = 0 ;
static uint32_t gSentFrameCount = 0 ;
byte msg[8] = {0, 0, 0, 0, 0, 0, 0, 0};

void loop() {

byte msg[8] = { 12, 23, 33, 44, 55, 66, 77, 28};

CANMessage frame ;
frame.id = 31 ;
frame.ext = true ;
frame.rtr = false ;
frame.idx = 0 ;
frame.len = 8 ;
for (int i=0 ; i<8 ; i++) {
frame.data [i] = {msg[i]} ;
}
/* frame.data [0] = {egt[1]} ;
frame.data [1] = {egt[2]} ;
frame.data [2] = 33 ;
frame.data [3] = 44 ;
frame.data [4] = 55 ;
frame.data [5] = 66 ;
frame.data [6] = 77 ;
frame.data [7] = 88 ;
*/
if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 50 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
const bool ok = can.tryToSend (frame) ;
if (ok) {
gSentFrameCount += 1 ;
Serial.print ("Sent: ") ;
Serial.println (gSentFrameCount) ;
}else{
Serial.println ("Send failure") ;
}
}
}

@pierremolinaro
Copy link
Owner

pierremolinaro commented Oct 3, 2020 via email

@Mplex72
Copy link
Author

Mplex72 commented Oct 3, 2020

Hi , thanks for the fast reply,

Hi , the message sending stops after 17 times.
I receive the data on the other CANlogger
so it sends the message 17 times , then it stops sending the messages.

How can I get "gSentFrameCount" in my message , for example in the first byte form my previous sketch ?

`
void loop() {

byte msg[8] = { gSentFrameCount, 22, 33, 44, 55, 66, 77, 28};

CANMessage frame ;
frame.id = 31 ;
frame.ext = true ;
frame.rtr = false ;
frame.idx = 0 ;
frame.len = 8 ;
for (int i=0 ; i<8 ; i++) {
frame.data [i] = msg[i] ;
}
`
Thanks , Klass

@Mplex72
Copy link
Author

Mplex72 commented Oct 3, 2020

Hi,
in fact , after better testingit it sending the message only once !
So probably it does not see an ACK ( the data logger is listen only? )
I see the first message on the logger ! , then it stops sending

<
/*
*
*/
#include <ACAN2515.h>

static const byte MCP2515_CS = 10 ; // CS input of MCP2515 (adapt to your design)
static const byte MCP2515_INT = 3 ; // INT output of MCP2515 (adapt to your design)

ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ;

static const uint32_t QUARTZ_FREQUENCY = 8UL * 1000UL * 1000UL ; // 8 MHz

void setup() {

Serial.begin (38400) ;

while (!Serial) {
delay (50) ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
}
SPI.begin () ;

ACAN2515Settings settings (QUARTZ_FREQUENCY, 500UL * 1000UL) ; // CAN bit rate 500 kb/s
const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ;
if (errorCode == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
Serial.print ("Propagation Segment: ") ;
Serial.println (settings.mPropagationSegment) ;
Serial.print ("Phase segment 1: ") ;
Serial.println (settings.mPhaseSegment1) ;
Serial.print ("Phase segment 2: ") ;
Serial.println (settings.mPhaseSegment2) ;
Serial.print ("SJW: ") ;
Serial.println (settings.mSJW) ;
Serial.print ("Triple Sampling: ") ;
Serial.println (settings.mTripleSampling ? "yes" : "no") ;
Serial.print ("Actual bit rate: ") ;
Serial.print (settings.actualBitRate ()) ;
Serial.println (" bit/s") ;
Serial.print ("Exact bit rate ? ") ;
Serial.println (settings.exactBitRate () ? "yes" : "no") ;
Serial.print ("Sample point: ") ;
Serial.print (settings.samplePointFromBitStart ()) ;
Serial.println ("%") ;
}else{
Serial.print ("Configuration error 0x") ;
Serial.println (errorCode, HEX) ;
}
}
static uint32_t gBlinkLedDate = 0 ;
static uint32_t gReceivedFrameCount = 0 ;
static uint32_t gSentFrameCount = 0 ;
byte msg[8] = {0, 0, 0, 0, 0, 0, 0, 0};

void loop() {
uint32_t timehack = millis();
byte msg[8] = { timehack >> 24, timehack >> 16, timehack >> 8, timehack & 0xF, 55, 66, 77, 28};

CANMessage frame ;
frame.id = 31 ;
frame.ext = true ;
frame.rtr = false ;
frame.idx = 0 ;
frame.len = 8 ;
for (int i=0 ; i<8 ; i++) {
frame.data [i] = msg[i] ;
}

if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 50 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
const bool ok = can.tryToSend (frame) ;
if (ok) {
gSentFrameCount += 1 ;
Serial.print ("Sent: ") ;
Serial.println (gSentFrameCount) ;
}else{
Serial.println ("Send failure") ;
}
}
}

@pierremolinaro
Copy link
Owner

pierremolinaro commented Oct 7, 2020 via email

@pierremolinaro
Copy link
Owner

pierremolinaro commented Oct 7, 2020 via email

@Mplex72
Copy link
Author

Mplex72 commented Oct 8, 2020

Hi ,
Indeed it also stops blinking ,
No further idea as I have already tried another arduino and CANboard.
The code can not broadcast Can messages without ACK ?
Klass

@pierremolinaro
Copy link
Owner

pierremolinaro commented Oct 8, 2020 via email

@Mplex72
Copy link
Author

Mplex72 commented Oct 8, 2020

ok , will try that first ,
I even think I have a Mega somewhere .

@pierremolinaro
Copy link
Owner

pierremolinaro commented Oct 10, 2020 via email

@Mplex72
Copy link
Author

Mplex72 commented Oct 10, 2020

Hi ,
tested with the new release > still not working
Then de mailboxes set to 1 ,> now it sends out 2 messages before going fault.
very strange behavior.
now I have to try a Mega or a TeensyLC.

@Mplex72
Copy link
Author

Mplex72 commented Oct 10, 2020

`/*
*
*/
#include <ACAN2515.h>

static const byte MCP2515_CS = 10 ; // CS input of MCP2515 (adapt to your design)
static const byte MCP2515_INT = 3 ; // INT output of MCP2515 (adapt to your design)

ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ;

static const uint32_t QUARTZ_FREQUENCY = 16UL * 1000UL * 1000UL ; // 8 MHz

void setup() {

Serial.begin (38400) ;

while (!Serial) {
delay (50) ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
}
SPI.begin () ;

ACAN2515Settings settings (QUARTZ_FREQUENCY, 500UL * 1000UL) ;
settings.mTransmitBuffer0Size = 1 ; // >= 0
settings.mReceiveBufferSize = 1 ; // >= 0
const uint16_t errorCode = can.begin (settings, [] { can.isr () ; }) ;
if (errorCode == 0) {
Serial.print ("Bit Rate prescaler: ") ;
Serial.println (settings.mBitRatePrescaler) ;
}else{
Serial.print ("Configuration error 0x") ;
Serial.println (errorCode, HEX) ;
}
}
static uint32_t gBlinkLedDate = 0 ;
static uint32_t gReceivedFrameCount = 0 ;
static uint32_t gSentFrameCount = 0 ;
byte msg[8] = {0, 0, 0, 0, 0, 0, 0, 0};

void loop() {
uint32_t timehack = millis();
byte msg[8] = { timehack >> 24, timehack >> 16, timehack >> 8, timehack & 0xF, 55, 66, 77, 88};

CANMessage frame ;
frame.id = 31 ;
frame.ext = true ;
frame.rtr = false ;
frame.idx = 0 ;
frame.len = 8 ;
for (int i=0 ; i<8 ; i++) {
frame.data [i] = msg[i] ;
}

if (gBlinkLedDate < millis ()) {
gBlinkLedDate += 50 ;
digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ;
const bool ok = can.tryToSend (frame) ;
if (ok) {
gSentFrameCount += 1 ;
Serial.print ("Sent: ") ;
Serial.println (gSentFrameCount) ;
}else{
Serial.println ("Send failure") ;
}
}
}`

@Mplex72
Copy link
Author

Mplex72 commented Oct 10, 2020

Hi , problem found ,
defect Uno pin 3 not working , other arduinoUno immediately works.
with that in mind I tried to run without interupt pin as in "Teensy without interupt" example.
That is not working , is this code without Int pin only possible in loopback mode ?

ACAN2515 can (MCP2515_CS, SPI, 255) ; // Last argument is 255 -> no interrupt pin
and
const uint32_t errorCode = can.begin (settings, NULL) ; // Second argument is NULL -> no interrupt service routine

@obdevel
Copy link

obdevel commented Oct 10, 2020

is this code without Int pin only possible in loopback mode ?

See the pdf doc section 6.4. Without interrupt you must receive using the poll() method.

@Mplex72
Copy link
Author

Mplex72 commented Oct 10, 2020

Ah , should have seen that,
Everything is working fine now , nice and stable.
Thanks , Klaas

@Mplex72 Mplex72 closed this as completed Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants