We are trying to send/receive messages over CAN from ERIKA on Flex using the CAN modules of the multibus board. It seems not easy.. at least for us. Does anyone has a simple sample code to share?
Thanks
Sample code with CAN communication
Moderator: paolo.gai
Re:Sample code with CAN communication
Hi pau!
I hope everything is fine with you...
I know that Luigi from UNITN and Roberto from SUPSI have some CAN code working.
We are also trying to get it to put it into the default branch of EE.
I\'ll contact them, maybe we\'ll be able to have something to post soon...
Ciao!
PJ
I hope everything is fine with you...
I know that Luigi from UNITN and Roberto from SUPSI have some CAN code working.
We are also trying to get it to put it into the default branch of EE.
I\'ll contact them, maybe we\'ll be able to have something to post soon...
Ciao!
PJ
Re: Sample code with CAN communication
Any updates on this topic?
Another question: Does RT_Druid include any CAN device driver for the CAN adapter module on multibus daughter board? Or, are there any CAN drivers available for FLEX platform?
Thank you,
Moon
Another question: Does RT_Druid include any CAN device driver for the CAN adapter module on multibus daughter board? Or, are there any CAN drivers available for FLEX platform?
Thank you,
Moon
Re: Sample code with CAN communication
As long as I know:
- some code is in the repository, please check
http://svn.tuxfamily.org/viewvc.cgi/eri ... iew=markup
- scicoslab blocks for CAN are available as blocks
http://svn.tuxfamily.org/viewvc.cgi/eri ... unication/
- The code was part of the training course last year in pisa. it wil be a topic of this year course in June as well...
Ciao,
PJ
- some code is in the repository, please check
http://svn.tuxfamily.org/viewvc.cgi/eri ... iew=markup
- scicoslab blocks for CAN are available as blocks
http://svn.tuxfamily.org/viewvc.cgi/eri ... unication/
- The code was part of the training course last year in pisa. it wil be a topic of this year course in June as well...
Ciao,
PJ
Re: Sample code with CAN communication
With the source code from the repository, I was able to run a loopback test (JP1 on CAN module) with CAN module on top of Multibus daughter board. I was able to receive the message I sent through the DMA configuration.
However, when I tried to test communication between two sets of Flex Full + Multibus daughter + CAN module, it failed. Wiring is CAN+ to CAN+ and CAN- to CAN-. I put 120ohm resistors at both ends (of the CAN modules). I also tested with a single terminator and no terminator, but neither worked.
I can't tell whether it's a problem of sender, receiver, or both until a CAN bus analyzer will be delivered in a week or so. Nevertheless, any comments or advice will be appreciated.
Thank you,
Moon
However, when I tried to test communication between two sets of Flex Full + Multibus daughter + CAN module, it failed. Wiring is CAN+ to CAN+ and CAN- to CAN-. I put 120ohm resistors at both ends (of the CAN modules). I also tested with a single terminator and no terminator, but neither worked.
I can't tell whether it's a problem of sender, receiver, or both until a CAN bus analyzer will be delivered in a week or so. Nevertheless, any comments or advice will be appreciated.
Thank you,
Moon
Re: Sample code with CAN communication
Quite strange... Please note that the CAN modules already has the terminators on the module (just put jumper JP1 on the CAN module...)
Ciao,
PJ
Ciao,
PJ
Re: Sample code with CAN communication
I put jumpers on JP1 of both CAN modules and connected CAN+ & CAN- without any resistors. However, it's not working.
Please see below for my code snippet for init, send, and receive. One sender (FLEX Full+Multibus+CAN module) periodically calling Send_ECAN1() while one receiver periodically calling Receive_ECAN1(). The receiver is not blocked by calling EE_ecan1_Rx(), but the function just returns empty data (with all 0's as the associated DMA channel buffer is initialized). I also checked that both the sender task and the receiver task are invoked properly.
When I tested this code on a single board with a single task calling Send_ECAN1() and Receive_ECAN1() in a row, it worked fine. Any comments?
// init in main()
main()
{
...
EE_ecan1_Initialize();
...
}
unsigned char iter = 0;
ee_ecan_mID ecanMsg1, ecanMsg2;
void Send_ECAN1()
{
int i;
int data_len = 8;
ecanMsg1.id = 0x1FFF0000;
ecanMsg1.message_type = CAN_MSG_DATA;
ecanMsg1.frame_type = CAN_FRAME_EXT;
ecanMsg1.data_length = data_len;
for (i = 0; i < data_len; i++) {
ecanMsg1.data = iter++;
}
// send a CAN message
EE_ecan1_SendMessage(&ecanMsg1);
}
void Receive_ECAN1()
{
int i;
// receive a CAN message
EE_ecan1_Rx(&ecanMsg2);
if (ecanMsg2.data_length > 0)
{
for (i = 0; i < ecanMsg2.data_length; i++) {
EE_UART1_Send(ecanMsg2.data);
}
}
}
Please see below for my code snippet for init, send, and receive. One sender (FLEX Full+Multibus+CAN module) periodically calling Send_ECAN1() while one receiver periodically calling Receive_ECAN1(). The receiver is not blocked by calling EE_ecan1_Rx(), but the function just returns empty data (with all 0's as the associated DMA channel buffer is initialized). I also checked that both the sender task and the receiver task are invoked properly.
When I tested this code on a single board with a single task calling Send_ECAN1() and Receive_ECAN1() in a row, it worked fine. Any comments?
// init in main()
main()
{
...
EE_ecan1_Initialize();
...
}
unsigned char iter = 0;
ee_ecan_mID ecanMsg1, ecanMsg2;
void Send_ECAN1()
{
int i;
int data_len = 8;
ecanMsg1.id = 0x1FFF0000;
ecanMsg1.message_type = CAN_MSG_DATA;
ecanMsg1.frame_type = CAN_FRAME_EXT;
ecanMsg1.data_length = data_len;
for (i = 0; i < data_len; i++) {
ecanMsg1.data = iter++;
}
// send a CAN message
EE_ecan1_SendMessage(&ecanMsg1);
}
void Receive_ECAN1()
{
int i;
// receive a CAN message
EE_ecan1_Rx(&ecanMsg2);
if (ecanMsg2.data_length > 0)
{
for (i = 0; i < ecanMsg2.data_length; i++) {
EE_UART1_Send(ecanMsg2.data);
}
}
}
Re: Sample code with CAN communication
Has anyone succeeded to receive a CAN message using the code posted above? It works for "loopback" test, but I am having trouble with a two board setup, one tx and another rx. I can see the traffic on the bus using a CAN bus analyzer but the receiver never gets the messages. It seems no data is written to DMA when I monitor the ecan1msgBuf.
Any comments?
Thanks in advance,
Moon
Any comments?
Thanks in advance,
Moon
Re: Sample code with CAN communication
I know it is a little bit late as a response, but a demo on using CAN has been committed on the ERIKA repository and will be available in the next build.
The demo is on
examples/pic30/pic30_MultibusBoard_can_demo
and it has been committed in revision 1371
Ciao,
PJ
The demo is on
examples/pic30/pic30_MultibusBoard_can_demo
and it has been committed in revision 1371
Ciao,
PJ