how to fix CAN connection errors? - can-bus

i'm newbie to the field of automotive, i'm trying to make a connection with can bus between CAN box and aurix board and monitor this connection using CANoe software.
i'm only trying to send a simple message one time from the kit over the can bus as a start just to test the connection and make sure it works before i proceed with the rest of the application.
but all i receive from the kit on CANoe is errors like Form errors, stuff error, CRC error, CAN overload frame.
i checked the pins of the can on the board multiple times to make sure they are correct, also tried to change the CAN channel used on the CAN box, even checked the wires and every thing seems like connected correctly.
and the software i'm using is only a demo that i found inside TASKING compiler demos in the files related the the kit i'm using so i can assume it's not wrong.
the steps i followed to get it this demo to compile are simple
use the software platform builder inside TASKING IDE to attach the files related to the kit to the project.
include the CAN driver file in it "IfxMultican_Can.h"
then i copied and pasted the code inside the documentation within that header file into my project.
i did every thing i could think of to get this to work but still same errors, so it's either the connections are wrong some how or the driver code provided with TASKING IDE contains errors, there is nothing else in the system.
the code i'm using for the project is
#include <stdio.h>
#include "SoftwarePlatform/illd_tc29xb/src/ifx/TC29xB/Multican/Can/IfxMultican_Can.h"
// CAN handle
IfxMultican_Can can;
// Nodes handles
IfxMultican_Can_Node canSrcNode;
IfxMultican_Can_Node canDstNode;
// Message Object handles
IfxMultican_Can_MsgObj canSrcMsgObj;
IfxMultican_Can_MsgObj canDstMsgObj;
const unsigned id = 0x100;
int main(){
// create configuration
IfxMultican_Can_Config canConfig;
IfxMultican_Can_initModuleConfig(&canConfig, &MODULE_CAN);
//initialize module
//IfxMultican_Can can; // defined globally
IfxMultican_Can_initModule(&can, &canConfig);
// create CAN node config
IfxMultican_Can_NodeConfig canNodeConfig;
IfxMultican_Can_Node_initConfig(&canNodeConfig, &can);
canNodeConfig.baudrate = 1000000; // 1 MBaud
// Source Node
// IfxMultican_Can_Node canSrcNode; // defined globally
{
canNodeConfig.nodeId = IfxMultican_NodeId_0;
canNodeConfig.rxPin = &IfxMultican_RXD0B_P20_7_IN;
canNodeConfig.rxPinMode = IfxPort_InputMode_pullUp;
canNodeConfig.txPin = &IfxMultican_TXD0_P20_8_OUT;
canNodeConfig.txPinMode = IfxPort_OutputMode_pushPull;
// initialize the node
IfxMultican_Can_Node_init(&canSrcNode, &canNodeConfig);
}
// Destination Node
// IfxMultican_Can_Node canDstNode; // defined globally
{
canNodeConfig.nodeId = IfxMultican_NodeId_1;
canNodeConfig.rxPin = &IfxMultican_RXD1B_P14_1_IN;
canNodeConfig.rxPinMode = IfxPort_InputMode_pullUp;
canNodeConfig.txPin = &IfxMultican_TXD1_P14_0_OUT;
canNodeConfig.txPinMode = IfxPort_OutputMode_pushPull;
// initialize the node
IfxMultican_Can_Node_init(&canDstNode, &canNodeConfig);
}
// IfxMultican_Can_MsgObj canSrcMsgObj; // defined globally
{
// create message object config
IfxMultican_Can_MsgObjConfig canMsgObjConfig;
IfxMultican_Can_MsgObj_initConfig(&canMsgObjConfig, &canSrcNode);
// assigned message object:
canMsgObjConfig.msgObjId = 0;
canMsgObjConfig.messageId = id; // 'id' is defined globally
canMsgObjConfig.acceptanceMask = 0x7FFFFFFFUL;
canMsgObjConfig.frame = IfxMultican_Frame_transmit;
canMsgObjConfig.control.messageLen = IfxMultican_DataLengthCode_8;
canMsgObjConfig.control.extendedFrame = FALSE;
canMsgObjConfig.control.matchingId = TRUE;
// initialize message object
IfxMultican_Can_MsgObj_init(&canSrcMsgObj, &canMsgObjConfig);
}
// IfxMultican_Can_MsgObj canDstMsgObj; // defined globally
{
// create message object config
IfxMultican_Can_MsgObjConfig canMsgObjConfig;
IfxMultican_Can_MsgObj_initConfig(&canMsgObjConfig, &canDstNode);
// assigned message object:
canMsgObjConfig.msgObjId = 2;
canMsgObjConfig.messageId = id;
canMsgObjConfig.acceptanceMask = 0x7FFFFFFFUL;
canMsgObjConfig.frame = IfxMultican_Frame_receive;
canMsgObjConfig.control.messageLen = IfxMultican_DataLengthCode_8;
canMsgObjConfig.control.extendedFrame = FALSE;
canMsgObjConfig.control.matchingId = TRUE;
// initialize message object
IfxMultican_Can_MsgObj_init(&canDstMsgObj, &canMsgObjConfig);
}
const unsigned dataLow = 0xC0CAC01A;
const unsigned dataHigh = 0xBA5EBA11;
// Initialize the message structure
IfxMultican_Message txMsg;
IfxMultican_Message_init(&txMsg, id, dataLow, dataHigh, IfxMultican_DataLengthCode_8);
// Transmit Data
while( IfxMultican_Can_MsgObj_sendMessage(&canSrcMsgObj, &txMsg) == IfxMultican_Status_notSentBusy );
return 0;
}
some examples of the errors i get in CANoe
Time Chn ID Name Event Type Dir DLC Data
[-] 18.909137 CAN 1 CAN Error RxErr ECC: 100000011xxxxx, Form Error, Bit Position = 12
| ECC 100000011xxxxx
| Code Form Error
| Position 12
| ID 0010010011001b (499)
| DLC 9
| Data 00-07 00 00 00 00 00 00 00 00
another example
Time Chn ID Name Event Type Dir DLC Data
[-] 18.907080 CAN 1 CAN Error RxErr ECC: 100001001xxxxx, CRC Error, Bit Position = 36
| ECC 100001001xxxxx
| Code CRC Error
| Position 36
| ID 0010010011001b (499)
| DLC 9
| Data 00-07 00 00 00 00 00 00 00 00
i also must point that despite i only send the message once, i keep receiving a non-ending sequence of those errors until i stop the simulation.
is there any way i can use to better understand how to fix those errors?
any information about the kit pins numbering or the correct connection for can would be very helpful.
i also must point that i'm only using the driver for the can abstractly from how it works, i only understand the CAN as bus on which i'll throw a message and receive it from the other end using some functions i don't know how it actually works and the time i have is quite limit and doesn't allow me to learn that much.
board used : KIT_AURIX_TC297_TFT
, CAN box : VN6510A

You need to change your baudrate in CANOe from 500.0 to 1000.0 Kbps (as configured in infineon iLLD canNodeConfig.baudrate = 1000000; // 1 MBaud)
Also, make sure you have 120 Ohm resistor between CANH and CANL.
Try to see your output from microcontroler (CAN TX/CAN RX) in oscilloscope or logic analyser, also the output from your CAN transceiver, since you are using TFT board you already have the transceiver resistor.

Related

How to update another byte of a CAN message while changing a byte in real-time?

I'm new to CANoe and CAPL scripting. I need to update a byte of CAN message based on a change in another byte through a panel. I added a CAPL script for the automatic change/update but when I send/update the byte through the panel it sends the default values for the other bytes. It gets corrected in the next sample.
includes
{
}
variables
{
message M2P_0x101 msg1;
msTimer timer10ms;
byte counter = 1;
}
on message M2P_0x101
{
if(counterAlive == 15)
{
counterAlive = 0;
}
else
{
counter++;
}
msg1.byte(0) = this.byte(0);
msg1.byte(1) = this.byte(1);
msg1.byte(2) = this.byte(2);
msg1.byte(3) = this.byte(3); // Changing through the Panel
msg1.byte(4) = this.byte(3)+1;
msg1.byte(5) = this.byte(5);
msg1.byte(6) = counter;
msg1.byte(7) = this.byte(7);
}
on timer timer10ms
{
output(msg1);
}
on start
{
setTimerCyclic(timer10ms, 10);
}
4th & 6th byte has default value because 3rd byte was changed from the panel.
I expected the 4th byte to be 1(value of 3rd byte + 1) and the 6th byte to be 4(counter value).
How to solve it? As far as I understand, it seems that the panel inputs/changes are sent to the CAN bus first and then CAPL node reads it and makes changes. This could be the reason for overwriting the other bytes of the message with default values.
Is there a way to include the changes made by CAPL before the panel sends the message to the CAN bus? A combination of Panel & CAPL node?

MQL4 multi-timeframe indicator

I would like to write out an indicator that can take in input the int shift of an assigned timeframe, and turns out a value related to another timeframe.
As an example, I would like to write an MACD indicator over a 100 periods of M15, that can return out its value 1,2,3,4,5,6,7... minutes before the current candle.
Since in the current candle this indicator "changes" its value, tick by tick, I think that should be possible to write out such an indicator, but I can not figure out how to do it.
MQL4 language principally has tools for this:
However, as noted above, your experimentation will need thorough quant validations, as the earlier Builds did not support this in [MT4-Strategy Tester] code-execution environment ( and more recent shifts into New-MQL4.56789 have devastated performance constraints for all [CustomIndicators], the all [MT4-graph]-GUI-s together plus the all [Expert Advisor]-s use, since all these suddenly share one ( yes, ONE and THE ONLY ) computing thread.
Ok, you have been warned :o)
So,
if indeed keen to equip your [CustomIndicator] so as to be independent of the GUI-native-TimeFrame, all your calculations inside such [CustomIndicator]-code must use indirect access-tools to source the PriceDOMAIN data - so never use any { Open[] | High[] | Low[] | Close[] }-TimeSeries data directly, but only using { iOpen() | iHigh() | iLow() | iClose() }
All these access tools conceptually have a common signature:
double iLow( string symbol, // symbol
int timeframe, // timeframe
int shift // shift
);
and
if your code
obeys this duty,
your [CustomIndicator]( iff the StrategyTester will not finally spoil the game -- due quant testing will show this )
will be working with data from timeframe & shift of your wish.
Implementation remarks:
Your [CustomIndicator]-code has to implement a "non-GUI-shift" independently from the GUI-native-TimeFrame shift-counting. See an iCustom() signature template for inspiration. The GUI-TimeFrame-shift is like moving the line-graph on GUI-screen, i.e. in GUI-native-TimeFrame steps, not taking into account your [CustomIndicator] "internal"-"non-GUI-shift" values, so your code has to be smarter, so as to process this "internal"-"non-GUI-shift" during a value generation. If in doubts, during prototyping, validate the proper "mechanics" on Time[aShiftINTENDED] vs iTime( _Symbol, PERIOD_INTENDED, aShiftINTENDED )
Due to quite a lot of points, where an iCustom() call-interface may be a bit misleading, or a revision-change-management error-prone, we got used to use a formal template for each [Custom Indicator] code, helping to maintain referential integrity with a iCustom() use in the actual [ExpertAdvisor] code. It might seem a bit dumb, but those, who have spent man*hours in search for a bug in { un- | ill- }-propagated call-interface changes, this may become a life-saver.
We formalise the call-interface in such a way, that this section, maintained in the [CustomIndicator]-code, can always be copied into the [ExpertAdviser] code, so that the iCustom() signature-match can be inspected.
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!
//---- indicator parameters -------------------------------------------------
// POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE
// all iCustom() calls MUST BE REVISED ON REVISION
//!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#define XEMA_CUSTOM_INDICATOR_NAME "EMA_DEMA_TEMA_XEMA_wShift" // this.
//--- input parameters ------------------------------------------------------ iCustom( ) CALL INTERFACE
input int nBARs_period = 8;
extern double MUL_SIGMA = 2.5;
sinput ENUM_APPLIED_PRICE aPriceTYPE = PRICE_CLOSE;
extern int ShiftBARs = 0;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* = iCustom( _Symbol,
PERIOD_CURRENT, XEMA_CUSTOM_INDICATOR_NAME, // |-> iCustom INDICATOR NAME
XEMA_nBARs_period, // |-> input nBARs_period
XEMA_MUL_SIGMA, // |-> input MUL_SIGMA
XEMA_PRICE_TYPE, // |-> input aPriceTYPE from: ENUM_APPLIED_PRICE
XEMA_ShiftBARs, // |-> input ShiftBARs
XEMA_<_VALUE_>_BUFFER_ID, // |-> line# --------------------------------------------from: { #define'd (e)nums ... }
0 // |-> [0]-aTimeDOMAIN-offset
); //
*/
#define XEMA_Main_AXIS_BUFFER_ID 0 // <----xEMA<maxEMAtoCOMPUTE>[]
#define XEMA_UpperBAND_BUFFER_ID 1
#define XEMA_LowerBAND_BUFFER_ID 2
#define XEMA_StdDEV____BUFFER_ID 3
#define XEMA_SimpleEMA_BUFFER_ID 4 // sEMA
#define XEMA_DoubleEMA_BUFFER_ID 10 // dEMA
#define XEMA_TripleEMA_BUFFER_ID 11 // tEMA
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!!
//---- indicator parameters -------------------------------------------------
// POSITIONAL ORDINAL-NUMBERED CALLING INTERFACE
// all iCustom() calls MUST BE REVISED ON REVISION
//!!!!
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Found a way to write it in a very simple way:
double M1 (int shift) {double val = iCustom(NULL,PERIOD_M1, "my_indicator",100,2.0,30.0,0,shift); return(val);}
double M15 (int shift) {double val = iCustom(NULL,PERIOD_M15,"my_indicator",100,2.0,30.0,0,shift); return(val);}
int s1_15;
double B_M1_M15(int i) {
if (i>=0 && i<15 ) s1_15=0;
else if (i>=15 && i<30 ) s1_15=1;
else if (i>=30 && i<45 ) s1_15=2;
else if (i>=45 && i<60 ) s1_15=3;
else if (i>=60 && i<75 ) s1_15=4;
return NormalizeDouble(MathAbs(M1(i) - M15(s1_15)),Digits);
}
and so on for every others couples of timeframe.

CAPL Script for Diagnostic Services

I am writing the CAPL script to Automise the Diagnostic services. I have read some DIDs which are bigger than 8 bytes in size. Till 8 bytes I can capture correctly the data in my CAPL script but when the data size exceeds the 8 bytes, then I get some garbage values 00 for remaining bytes.
The complete read data I can see in CANoe Trace but I am not able to capture it in my CAPL script. If someone has any ideas or solution, please share with me.
In Belo script, the issue is that I can capture value till this.byte(7) correctly. But for this.byte(8) and this.byte(9) I read 00 although the actual value in CANoe Trace is 0x54 and 0x66. So it means I cannot read more than 8 bytes in CAPL from CAN.
My script looks like:
variables
{
//Please insert your code below this comment
byte test_num;
message DTOOL_to_UPA msg_tester;
mstimer readTimerDID_2001;
mstimer defaultSession;
byte readBuf2001[8];
}
// read request
on key 'd'
{
test_num = 0;
msg_tester.dlc = 8;
msg_tester.dir = tx;
msg_tester.can = 1;
settimer(defaultSession, 2000);
}
on timer defaultSession // Request DID: 10 01
{
msg_tester.byte(0) = 0x02;
msg_tester.byte(1) = 0x10;
msg_tester.byte(2) = 0x01;
output(msg_tester);
settimer(readTimerDID_2001, 100);
canceltimer(defaultSession);
}
on timer readTimerDID_2001 // Read Request DID: 22 20 01
{
msg_tester.byte(0) = 0x03;
msg_tester.byte(1) = 0x22;
msg_tester.byte(2) = 0x20;
msg_tester.byte(3) = 0x01;
output(msg_tester);
canceltimer(readTimerDID_2001);
}
on message UPA_to_DTOOL
{
if (this.DIR == RX)
{
// Response Data for DID 2001
if (
(this.byte(0)== 0x04)&&(this.byte(1)== 0x62)&&(this.byte(2)==0x20)&&
(this.byte(3)== 0x01)&&(this.byte(4)== 0x23) &&(this.byte(5)== 0x00)&&
(this.byte(6)== 0x44)&&(this.byte(7)== 0x22) &&(this.byte(8)==0x54)&&
(this.byte(9)== 0x66)
)
{
readDID2001();
}
}
}
on message UPA_to_DTOOL
is reacting on the CAN message UPA_to_DTOOL, and this you can only access the 8 bytes of the CAN message.
If you want to react on diagnostic messages you should use
on diagResponse <serviceName>
inside of this handler you can then access the complete data of the diagnostic message
I had a similar problem accessing j1939 PGN with data length code (DLC) > 8 byte. These messages were transmitted as a j1939 Frame (DLC > 8 byte) instead of a CAN frame (DLC = 8 byte) in the trace window. I had to make use of the getThisMessage(pg pg_variable, int length) function in an on pg event like this.
on pg UPA_to_DTOOL {
pg UPA_to_DTOOL UPA_to_DTOOL_pg;
getThisMessage(UPA_to_DTOOL, UPA_to_DTOOL.dlc);
write("byte 9 = %X", UPA_to_DTOOL.byte(9));
}
Because messages with DLC > 8 are transmitted in a special way, the getThisMessage had to be used in my case, which let me access all the message bytes. I am not sure this solution for j1939 PGNs helps you because I do not know whether you have a license for j1939 in your canoe installation.

Addons Compatibility with Firefox 48

I have an addon correctly working just up to FF 47.I know that with e10s FF 48, it has some compatibility troubles. Here a brief list of the lines of code I think they are affected by the new multiprocess model of the browser:
1.let { Cc, Ci } = require('chrome');
2.const { Cu } = require("chrome");
3.require("sdk/tabs").on("ready",logURL);
4.Cu.import("resource://gre/modules/FileUtils.jsm");
5.const {TextDecoder, TextEncoder, OS} = Cu.import("resource://gre/modules/osfile.jsm", {});
6. file = FileUtils.getFile("Home", [".cp.txt"]); //reopen the file just saved
7. var txt = "";
var fstream = Cc["#mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
var cstream = Cc["#mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
fstream.init(file, -1, 0, 0); cstream.init(fstream, "UTF-8", 0, 0); let str = {};
let read = 0;
do {
read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value
txt += str.value;
} while (read != 0);
cstream.close(); // this closes fstream // use 0x02 | 0x10 to open file for appending. // save the domain option in file
foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
converter.init(foStream, "UTF-8", 0, 0);
var sEP = txt + '\n' + 'h' + '\n'; // encrypt new path converter.writeString(sEP); converter.close(); // this closes foStream
console.log('saved h'); }
I need to know, first of all, if all these elements are effectively problematic with new FF (I am pretty sure 6 and 7 are not compatible — the XUL and XPCOM are obsolete and work on the same thread —, but not so sure for the other lines), and finally if there are surrogate constructs for the 48 version in order to solve the same problems (input/output and so on). In particular, it is essential for the add-on the use of the tabs mechanism (for reading the URL of a tab). Thanks for the help.
None of these issues are e10s related, they are all es6 and xpcom questions.
If you use this in a framescript, then its a e10s question, however I avoid using xpcom in framescripts, try to use messaging from framescript to bootstrap such as this - https://github.com/Noitidart/CommPlayground
Re 1 and 2: if you are not using the Cu Ci in require'ed scripts, let and const is fine.
Re 7: Don't do this way, it will be deprecated soon, and is not main ui friendly. It can lock it up. Use OS.File.
Re 4 and 6: I recommend doing Services.dirsvc.get('Home', Ci.nsIFile).path;. This is XPCOM but it is using the common Services.jsm module, which is less likely to be depercated. Also, Services.dirsvc.get caches the files, so its much faster then FileUtils. However, ideally, you should use OS.Path.join and OS.Constants.Path which comes when you import osfile.jsm. So you would do OS.Path.join(OS.Constants.Path.homeDir, '.cp.txt') - try to avoid as much XPCOM as possible.
Re 3: This is fine.

Can't save to Flash Memory?

I am using the following library <flash.h> to Erase/Write/Read from memory but unfortunately the data I am trying to save doesn't seem to be written to flash memory. I am using PIC18F87j11 with MPLAB XC8 compiler. Also when I read the program memory from PIC after attempting to write to it, there is no data on address 0x1C0CA. What am I doing wrong?
char read[1];
/* set FOSC clock to 8MHZ */
OSCCON = 0b01110000;
/* turn off 4x PLL */
OSCTUNE = 0x00;
TRISDbits.TRISD6 = 0; // set as ouput
TRISDbits.TRISD7 = 0; // set as ouput
LATDbits.LATD6 = 0; // LED 1 OFF
LATDbits.LATD7 = 1; // LED 2 ON
EraseFlash(0x1C0CA, 0x1C0CA);
WriteBytesFlash(0x1C0CA, 1, 0x01);
ReadFlash(0x1C0CA, 1, read[0]);
if (read[0] == 0x01)
LATDbits.LATD6 = 1; // LED 1 ON
while (1) {
}
I don't know what WriteFlashBytes does but the page size for your device is 64 bytes and after writing you need to write an ulock sequence to EECON2 and EECON1 registers to start programming the flash memory

Resources