|
Post by Admin on Mar 7, 2017 16:26:53 GMT
In that case:
CAN0_RxInit(0x151, 0x7FFFFFFFUL, 8, 29, 1);
If you not transmitting through CAN0 then:
CAN0_RxInit(0x151, 0x7FFFFFFFUL, 8, 29, 0);
|
|
joao
New Member
Posts: 31
|
Post by joao on Mar 8, 2017 7:46:44 GMT
So i keep trying but so far nothing...
i moved to 11bits ID at 250K already tried 100K and 50K
this is the code i am using on the shieldbuddy:
void setup() {
// put your setup code for core 0 here, to run once:
SerialASC.begin(9600);
CAN0_Init(250000);
/* Parameters CAN ID, Acceptance mask, data length, 11 or 29 bit ID, Message object to use */
CAN0_RxInit(0x151, 0x7FFFF000UL, 8, 11, 0);
SerialASC.print("Multican is Initialized\n\r");
}
void loop() {
IfxMultican_Message msg1;
IfxMultican_Status RxStatus;
RxStatus = CAN0_ReceiveMessage(0x151, &msg1, 8);
if (RxStatus != IfxMultican_Status_noError){
SerialASC.print("ERROR: single IfxMultican_Can_MsgObj_read Message returned ");SerialASC.print(RxStatus,HEX); SerialASC.print("\n\r");
}
if (RxStatus == IfxMultican_Status_noError){
SerialASC.print("recieved");SerialASC.print(RxStatus,HEX); SerialASC.print("\n\r");
}
SerialASC.print("Multican Basic data transactions are finished\n\r\n\r");
delay(500);
}
and this what i am using to send and already confirmed with a 3rd arduino that it is being sent correctly;
#include <mcp_can.h>
#include <SPI.h>
MCP_CAN CAN0(53); // Set CS to pin 10
void setup()
{
Serial.begin(250000);
// init can bus, baudrate: 100k
if(CAN0.begin(CAN_250KBPS) == CAN_OK) Serial.print("can init ok!!\r\n");
else Serial.print("Can init fail!!\r\n");
}
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
// send data: id = 0x00, standrad flame, data len = 8, stmp: data buf
CAN0.sendMsgBuf(0x151, 0, 8, stmp);
Serial.print("sent \r\n");
delay(1000);
}
does anyone see anything wrong? i do have the 120 resistors... i can see the signal in the Rx pin with the osciloscope. i am without ideas now.
it seems stupid because there are several CAN channels in the controller but i need to ask: anyone tried using mcp_can.h and SPI.h (the ones i use in the arduino mega) for CAN communication with the shield buddy?
|
|
|
Post by Admin on Mar 8, 2017 8:23:33 GMT
As a test, please use:
CAN0_RxInit(0x151, 0x7FFFFFFFUL, 8, 11, 0);
Just in case the acceptance mask is causing the problem. I think somebody has used the normal Arduino CAN shield with the ShieldBuddy. I use a Digilent Comms shield (http://uk.rs-online.com/web/p/processor-microcontroller-development-kits/7418335/) which has two CAN transceivers on it. The toggleBit CAN shield has also been used.
The MCP_can.h cannot be used with the ShieldBuddy unless you have a normal Arduino CAN shield fitted.
|
|
|
Post by Admin on Mar 8, 2017 8:23:51 GMT
I will buy a CAN shield to make some tests!
|
|
joao
New Member
Posts: 31
|
Post by joao on Mar 8, 2017 8:36:36 GMT
As a test, please use: CAN0_RxInit(0x151, 0x7FFFFFFFUL, 8, 11, 0); Just in case the acceptance mask is causing the problem. I think somebody has used the normal Arduino CAN shield with the ShieldBuddy. I use a Digilent Comms shield (http://uk.rs-online.com/web/p/processor-microcontroller-development-kits/7418335/) which has two CAN transceivers on it. The toggleBit CAN shield has also been used. The MCP_can.h cannot be used with the ShieldBuddy unless you have a normal Arduino CAN shield fitted. How do you use the Digilent Comms shield on the shieldbuddy? Do you need anything else or you just connect it as a transciever? I saw the Rs link but the datasheet is, lets say, poor.
|
|
joao
New Member
Posts: 31
|
Post by joao on Mar 8, 2017 10:07:47 GMT
I came back to the send messages and i found a problem that i thought it was already solved.
The 2*Baudrate
void setup() { // put your setup code for core 0 here, to run once:
SerialASC.begin(250000);
CAN0_Init(125000);
/* Parameters CAN ID, Acceptance mask, data length, 11 or 29 bit ID, Message object to use */ CAN0_TxInit(0x100, 0x7FFFFFFFUL, 8, 29, 0);
SerialASC.print("Multican is Initialized\n\r");
}
void loop() { // put your main code for core 1 here, to run repeatedly: uint32_t Lowdata; uint8_t L_data[4]; uint8_t H_data[4]; uint32_t Highdata; IfxMultican_Message msg1; IfxMultican_Status RxStatus;
L_data[0] = 1; L_data[1] = 2; L_data[2] = 3; L_data[3] = 4;
H_data[0] = 5; H_data[1] = 6; H_data[2] = 7; H_data[3] = 8;
Lowdata = L_data[0]; Lowdata = (Lowdata << 8) | L_data[1]; Lowdata = (Lowdata << 8) | L_data[2]; Lowdata = (Lowdata << 8) | L_data[3];
Highdata = H_data[0]; Highdata = (Highdata << 8) | H_data[1]; Highdata = (Highdata << 8) | H_data[2]; Highdata = (Highdata << 8) | H_data[3];
CAN0_SendMessage(0x100, Lowdata, Highdata, 8); CAN0_SendMessage(0x202, Lowdata, Highdata, 8); CAN0_SendMessage(0x203, Lowdata, Highdata, 8); CAN0_SendMessage(0x204, Lowdata, Highdata, 8); SerialASC.print("sent");
delay(1000); }
and the reciever code:
#include <mcp_can.h> #include <SPI.h>
long unsigned int rxId; unsigned char len = 0; unsigned char rxBuf[8];
MCP_CAN CAN0(53); // Set CS to pin 10
void setup() { Serial.begin(250000); CAN0.begin(CAN_250KBPS); // init can bus : baudrate = 500k pinMode(2, INPUT); // Setting pin 2 for /INT input Serial.println("MCP2515 Library Receive Example..."); }
void loop() { if(CAN_MSGAVAIL == CAN0.checkReceive()){ CAN0.readMsgBuf(&len, rxBuf); // Read data: len = data length, buf = data byte(s) rxId = CAN0.getCanId(); // Get message ID Serial.print("ID: "); Serial.print(rxId, HEX); Serial.print(" Data: "); for(int i = 0; i<len; i++) // Print each byte of the data { if(rxBuf < 0x10) // If data byte is less than 0x10, add a leading zero { Serial.print("0"); } Serial.print(rxBuf, HEX); Serial.print(" "); } Serial.println(); } }
I get this in the Receiver:
ID: 100 Data: 04 03 02 01 08 07 06 05
ID: 202 Data: 04 03 02 01 08 07 06 05
ID: 203 Data: 04 03 02 01 08 07 06 05
ID: 204 Data: 04 03 02 01 08 07 06 05
can this also cause a problem in the receiving messages?
and how about CAN1 Can you tell me wich ones are CAN1 pins please.
|
|
|
Post by Admin on Mar 8, 2017 10:37:02 GMT
That's weird. Please check C:\Program Files (x86)\Arduino\hardware\aurduino\aurix\system\libaurix\source\system_tc2x.c, line 102. It should be 0x50012212 for CCUCON1:
/* 200/100 MHz @ 20MHz ext. clock */ const TPllInitValue g_PllInitValue_200_100 = { /* OSCCON, PLLCON0, PLLCON1, CCUCON0, CCUCON1, CCUCON2 */ #if defined(TRIBOARD_TC275A) || defined(APPKIT_TC275TU) 0x0007001C, 0x01017600, 0x00020002, 0x52220101, 0x50012211, 0x40000202 #else 0x0007001C, 0x01017600, 0x00020002, 0x52120112, 0x50012212, 0x40000002 /* CAN is Fspb/2 */ #endif /* TRIBOARD_TC275A || APPKIT_TC275TU */ };
|
|
joao
New Member
Posts: 31
|
Post by joao on Mar 8, 2017 10:48:50 GMT
That's weird. Please check C:\Program Files (x86)\Arduino\hardware\aurduino\aurix\system\libaurix\source\system_tc2x.c, line 102. It should be 0x50012212 for CCUCON1: /* 200/100 MHz @ 20MHz ext. clock */ const TPllInitValue g_PllInitValue_200_100 = { /* OSCCON, PLLCON0, PLLCON1, CCUCON0, CCUCON1, CCUCON2 */ #if defined(TRIBOARD_TC275A) || defined(APPKIT_TC275TU) 0x0007001C, 0x01017600, 0x00020002, 0x52220101, 0x50012211, 0x40000202 #else 0x0007001C, 0x01017600, 0x00020002, 0x52120112, 0x50012212, 0x40000002 /* CAN is Fspb/2 */ #endif /* TRIBOARD_TC275A || APPKIT_TC275TU */ }; It is as you say. const TPllInitValue g_PllInitValue_200_100 = { /* OSCCON, PLLCON0, PLLCON1, CCUCON0, CCUCON1, CCUCON2 */ #if defined(TRIBOARD_TC275A) || defined(APPKIT_TC275TU) 0x0007001C, 0x01017600, 0x00020002, 0x52220101, 0x50012211, 0x40000202 #else 0x0007001C, 0x01017600, 0x00020002, 0x52120112, 0x50012212, 0x40000002 /* CAN is Fspb/2 */ #endif /* TRIBOARD_TC275A || APPKIT_TC275TU */ }; Nothing needed to be changed. Problem continues. Meanwhile i would like to try CAN1 instead of CAN0, cann you tell me where are the pins for CAN 0 please.
|
|
|
Post by Admin on Mar 9, 2017 9:00:45 GMT
Here are the CAN pins:
Name TC275 Port ShieldBuddy Pin CAN0 RX P20.7 pin CANRX CAN0 TX P20.8 pin CANTX
CAN1 RX P14.1 J406 pin23 CAN1 TX P14.0 J406 pin22
|
|
|
Post by sparrowdclxvi on Mar 9, 2017 9:20:16 GMT
There's something different about your setup then, as mine worked correctly, with the correct CAN rates using this code:
/*** Don't worry, the normal Arduino setup() and loop() are below this block! ***/
/* LMU uninitialised data */
StartOfUninitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have no initial values here e.g. uint32 LMU_var; */
IfxMultican_Message rpmMessage;
typedef union
{
uint8 bytes[8];
uint32 dword[2];
} CANMessagePayloadType;
CANMessagePayloadType RPMCANMessage;
CANMessagePayloadType SpeedCANMessage;
CANMessagePayloadType EngineCANMessage;
CANMessagePayloadType AirbagCANMessage;
EndOfUninitialised_LMURam_Variables
/* LMU uninitialised data */
StartOfInitialised_LMURam_Variables
/* Put your LMU RAM fast access variables that have an initial value here e.g. uint32 LMU_var_init = 1; */
//Variables (Speed and RPM)
boolean increaseRPM = true;
int speed = 50;
byte speedL = 0;
byte speedH = 0;
int rpm = 1000;
short tempRPM = 0;
byte rpmL = 0;
byte rpmH = 0;
EndOfInitialised_LMURam_Variables
/* If you do not care where variables end up, declare them here! */
/*** Core 0 ***/
void setup()
{
SerialASC.begin(9600);
CAN0_Init(500000);
SerialASC.print("CAN0 is Initialized\n\r");
CAN0_TxInit(0x100, 0x7FFFFFFFUL, 8, 11, 0);
SerialASC.print("CAN0 Transmit is Initialized\n\r");
}
void loop()
{
if (rpm > 7000)
{
increaseRPM = false;
}
if (rpm < 1500)
{
increaseRPM = true;
}
if (increaseRPM)
{
rpm += 100;
speed += 5;
}
else
{
rpm -= 100;
speed -= 5;
}
tempRPM = rpm * 4;
rpmL = (tempRPM & 0xFF);
rpmH = tempRPM >> 8;
/* Build RPM CAN packet */
RPMCANMessage.bytes[0] = 0x49;
RPMCANMessage.bytes[1] = 0x0E;
RPMCANMessage.bytes[2] = rpmL;
RPMCANMessage.bytes[3] = rpmH;
RPMCANMessage.bytes[4] = 0x0E;
RPMCANMessage.bytes[5] = 0x00;
RPMCANMessage.bytes[6] = 0x1B;
RPMCANMessage.bytes[7] = 0x0E;
/* Parameters CAN ID, 32 bits low data, 32 bits high data, data length */
CAN0_SendMessage(0x280, RPMCANMessage.dword[0], RPMCANMessage.dword[1], 8);
/* Transmit Speed */
//Conversion Speed
speed = speed * 1.12; //KMH=1.12 MPH=0.62
//Conversion Low and High Bytes
speedL = ((speed << 7) & 0x80);
speedH = (speed >> 1);
/* Build RPM CAN packet */
SpeedCANMessage.bytes[0] = 0x00;
SpeedCANMessage.bytes[1] = 0x30; //speedL;
SpeedCANMessage.bytes[2] = 0x10; //speedH;
SpeedCANMessage.bytes[3] = 0x00;
SpeedCANMessage.bytes[4] = 0x00;
SpeedCANMessage.bytes[5] = 0x00;
SpeedCANMessage.bytes[6] = 0x10;
SpeedCANMessage.bytes[7] = 0xAD;
/* Parameters CAN ID, 32 bits low data, 32 bits high data, data length */
CAN0_SendMessage(0x5A0, SpeedCANMessage.dword[0], SpeedCANMessage.dword[1],
8);
// CanSend(0x5A0, 0x00, speedL, speedH, 0x0, 0, 0, 0, 0xad);
/* Build Airbag CAN packet */
AirbagCANMessage.bytes[0] = 0x00;
AirbagCANMessage.bytes[1] = 0x80;
AirbagCANMessage.bytes[2] = 0x00;
AirbagCANMessage.bytes[3] = 0x00;
AirbagCANMessage.bytes[4] = 0x00;
AirbagCANMessage.bytes[5] = 0x00;
AirbagCANMessage.bytes[6] = 0x00;
AirbagCANMessage.bytes[7] = 0x00;
/* Parameters CAN ID, 32 bits low data, 32 bits high data, data length */
CAN0_SendMessage(0x050, AirbagCANMessage.dword[0],
AirbagCANMessage.dword[1], 8);
// Send airbag
// CanSend(0x050, 0, 0x80, 0, 0, 0, 0, 0, 0);
/* Build Engine On CAN packet */
EngineCANMessage.bytes[0] = 0x01;
EngineCANMessage.bytes[1] = 0x80;
EngineCANMessage.bytes[2] = 0x00;
EngineCANMessage.bytes[3] = 0x00;
EngineCANMessage.bytes[4] = 0x00;
EngineCANMessage.bytes[5] = 0x00;
EngineCANMessage.bytes[6] = 0x00;
EngineCANMessage.bytes[7] = 0x00;
/* Parameters CAN ID, 32 bits low data, 32 bits high data, data length */
CAN0_SendMessage(0xDA0, EngineCANMessage.dword[0],
EngineCANMessage.dword[1], 8);
// Engine on and ESP enabled
// CanSend(0xDA0, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
// Immobilizer
// CanSend(0x3D0, 0, 0x80, 0, 0, 0, 0, 0, 0);
delay(50);
}
/*** Core 1 ***/
/* CPU1 Uninitialised Data */
StartOfUninitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have no initial values here e.g. uint32 CPU1_var; */
EndOfUninitialised_CPU1_Variables
/* CPU1 Initialised Data */
StartOfInitialised_CPU1_Variables
/* Put your CPU1 fast access variables that have an initial value here e.g. uint32 CPU1_var_init = 1; */
EndOfInitialised_CPU1_Variables
void setup1()
{
// put your setup code for core 1 here, to run once:
}
void loop1()
{
// put your main code for core 1 here, to run repeatedly:
}
/*** Core 2 ***/
/* CPU2 Uninitialised Data */
StartOfUninitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have no initial values here e.g. uint32 CPU2_var; */
EndOfUninitialised_CPU2_Variables
/* CPU2 Initialised Data */
StartOfInitialised_CPU2_Variables
/* Put your CPU2 fast access variables that have an initial value here e.g. uint32 CPU2_var_init = 1; */
EndOfInitialised_CPU2_Variables
void setup2()
{
// put your setup code for core 2 here, to run once:
}
void loop2()
{
// put your main code for core 2 here, to run repeatedly:
}
I didn't try to receive on the ShieldBuddy, just transmit.
|
|
frank
New Member
Posts: 18
|
Post by frank on Apr 15, 2017 17:13:12 GMT
I have also a problem to receive messages. Sending messages is no problem, so the hardware works. I have connected a CAN transceiver to CANTX and CANRX pins. The CAN ID 0x06FEF530 (Prio:6, PGN: FEF5, Source: 30) is on the CAN, I tested it with an Arduino board.
My code is as follows
void setup() { // put your setup code for core 0 here, to run once:
SerialASC.begin(250000);
CAN0_Init(250000);
/* Parameters CAN ID, Acceptance mask, data length, 11 or 29 bit ID, Message object to use */ CAN0_RxInit(0x6FEF530, 0x1FFFFFFFUL, 8, 29, 1);
SerialASC.print("Multican is Initialized\n\r");
}
void loop() {
IfxMultican_Message msg1; IfxMultican_Status RxStatus;
RxStatus = CAN0_ReceiveMessage(0x6FEF530, &msg1, 8);
if (RxStatus != IfxMultican_Status_noError){ SerialASC.print("ERROR: single IfxMultican_Can_MsgObj_read Message returned "); SerialASC.print(RxStatus,HEX); SerialASC.print("\n\r"); }
if (RxStatus == IfxMultican_Status_noError){
SerialASC.print("recieved"); SerialASC.print("\n\r");
}
SerialASC.print("Multican Basic data transactions are finished\n\r\n\r"); delay(500);
}
The output is this:
ERROR: single IfxMultican_Can_MsgObj_read Message returned 40
Multican Basic data transactions are finished
Can anyone help?
|
|
|
Post by Admin on Apr 17, 2017 11:15:40 GMT
Hi, Here is an example for 29-bit CAN. I wonder about your acceptance mask! CAN_29Bit.ino (5.45 KB)
|
|
frank
New Member
Posts: 18
|
Post by frank on Apr 17, 2017 16:51:29 GMT
Hi, Here is an example for 29-bit CAN. I wonder about your acceptance mask! Thank you, but my acceptance mask should be OK I think. With 1FFFFFFF all 29 bits of the identifier should pass. What are you wondering about? In your example the init for all IDs is for 11 bit, that I don't understand...
|
|
|
Post by Admin on Apr 17, 2017 17:40:06 GMT
Sorry, yes the example is 11-bit!
|
|
frank
New Member
Posts: 18
|
Post by frank on Apr 17, 2017 20:06:00 GMT
Also confusing, when I read out msg1.id the output is 0x608F (also when I change the ID I want to receive to another ID that is also on the CAN)
|
|