Hi,
i connected two boards via CAN Bus, both boards have a PIC18F2685 and a CAN Transceiver. Everything works fine if i send IDs up to 2047 (standard ID). But i want to use extended IDs. In the properties for the CAN Module i selected "standard & extended". Both boards run with 125kb/s. As soon i use an ID above 2047 (2048 and up) there is no more communication between the board.
Anyone an idea, what i can do to make extended IDs run?
Thanks a lot
maridd
CAN Bus Extended ID
Moderator: Benj
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: CAN Bus Extended ID
Hi.
It will be helpful if you post your Flowchart to the topic that people can see your code and help you.
Question
It will be helpful if you post your Flowchart to the topic that people can see your code and help you.
Question
- what variable type are you using for the ID. Byte, unsigned Integer or unsigned Long.
Are you using Mask and filters
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
Re: CAN Bus Extended ID
Hi,
sorry for the imcomplete information (is my first post ever...). I am new to Flowcode so i try to figure out how things work with Flowcode. Its just ja testcircuit for me to learn programming a canbus with Flowcode.
I declared the variables as ULONG, this is given in the macro for canbus (as far as i understand it). I set the receive filter to "accept all".
I attach the two Flowcharts for transmission and receiption.
Thanks...
maridd
sorry for the imcomplete information (is my first post ever...). I am new to Flowcode so i try to figure out how things work with Flowcode. Its just ja testcircuit for me to learn programming a canbus with Flowcode.
I declared the variables as ULONG, this is given in the macro for canbus (as far as i understand it). I set the receive filter to "accept all".
I attach the two Flowcharts for transmission and receiption.
Thanks...
maridd
- Attachments
-
- CAN_Send_Test.fcfx
- (23.36 KiB) Downloaded 173 times
-
- CAN_Receive_Test.fcfx
- (29.81 KiB) Downloaded 135 times
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: CAN Bus Extended ID
Hi.
Looking at your FC flowchart a few things that I will change and try again(I do not have a 2685 chip to check for you)
1- It does not mean if you send an ID(2018) from TX buffer 0 in your send code it will end up in Rx Buffer 0 in the receiver
2- You have to check (poll in your case Interrupt driven is better) both Rx Buffers then decide which buffer has a valid message and read that buffer and check if the ID is 2048 for example.
3- In the sending Flowchart you have to send the message at a specified cycle time (10 or 20 or 100 msec for example) but at a fixed cycle time
4- In the receiver mode having delay of 100 msec to toggle leds is not a good idea you should read the CAN buffer faster than you send them
Normally these Rx messages the buffers are read then in a case structure contain a case of all the message this node will Rx an then in these cases the appropriate actions/code is execute for each ID
Hope this helps in some way
Looking at your FC flowchart a few things that I will change and try again(I do not have a 2685 chip to check for you)
1- It does not mean if you send an ID(2018) from TX buffer 0 in your send code it will end up in Rx Buffer 0 in the receiver
2- You have to check (poll in your case Interrupt driven is better) both Rx Buffers then decide which buffer has a valid message and read that buffer and check if the ID is 2048 for example.
3- In the sending Flowchart you have to send the message at a specified cycle time (10 or 20 or 100 msec for example) but at a fixed cycle time
4- In the receiver mode having delay of 100 msec to toggle leds is not a good idea you should read the CAN buffer faster than you send them
Normally these Rx messages the buffers are read then in a case structure contain a case of all the message this node will Rx an then in these cases the appropriate actions/code is execute for each ID
Hope this helps in some way
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
Re: CAN Bus Extended ID
Hi QMESAR,
thanks a lot for your ideas and suggestions. I will try all this when at home but this will take a week or two... . I will then post the result.
Thanks again
maridd
thanks a lot for your ideas and suggestions. I will try all this when at home but this will take a week or two... . I will then post the result.
Thanks again
maridd
Re: CAN Bus Extended ID
Hi QMESAR,
i changed the Receiver Testprogramm and used a TIMER0 Interrupt (about 8ms) to check for a new CAN Message in Buffer0. I still use only Buffer0 and whatever i did - it works with Extended ID. On the Transmitter side i send a message every 50ms, i changed this intervall to 1s and it works.
I am glad it works, but its a little bit disappointing to me not to know why it now works.
Anyway... Thanks again for your support
maridd
i changed the Receiver Testprogramm and used a TIMER0 Interrupt (about 8ms) to check for a new CAN Message in Buffer0. I still use only Buffer0 and whatever i did - it works with Extended ID. On the Transmitter side i send a message every 50ms, i changed this intervall to 1s and it works.
I am glad it works, but its a little bit disappointing to me not to know why it now works.
Anyway... Thanks again for your support
maridd
- Attachments
-
- CAN_Send_Test.fcfx
- (11.8 KiB) Downloaded 178 times
-
- CAN_Receive_Test.fcfx
- (17.28 KiB) Downloaded 165 times
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: CAN Bus Extended ID
Hi
Happy you had some progress,
I will take a look at your Flowcharts when I have a bit of time.
Just another input is that it would be better if you use the CAN RX interrupt on the receiver then you only read when there is an message in the Rx buffer,In your case as is now not that important but when the bus load is high say 20 messages at 10-20 mSec intervals then this get critical
good luck
Happy you had some progress,
I will take a look at your Flowcharts when I have a bit of time.
Just another input is that it would be better if you use the CAN RX interrupt on the receiver then you only read when there is an message in the Rx buffer,In your case as is now not that important but when the bus load is high say 20 messages at 10-20 mSec intervals then this get critical
good luck
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
Re: CAN Bus Extended ID
Hi,
yes, its definitely better to use an interrupt. At the time of my last post i didn`t know, how to get an CAN RX Interrupt to run (there is no predefined interrupt for CAN).
Since then i learned how to create customer interrupts and with the help of the datasheet and some hints from this forum i managed to get the CAN RX Interrupt for Buffer 0 running and i stopped polling the RX Buffer with the help of TIMER0 Interrupt.
Thanks
maridd
yes, its definitely better to use an interrupt. At the time of my last post i didn`t know, how to get an CAN RX Interrupt to run (there is no predefined interrupt for CAN).
Since then i learned how to create customer interrupts and with the help of the datasheet and some hints from this forum i managed to get the CAN RX Interrupt for Buffer 0 running and i stopped polling the RX Buffer with the help of TIMER0 Interrupt.
Thanks
maridd
- QMESAR
- Valued Contributor
- Posts: 1287
- Joined: Sun Oct 05, 2014 3:20 pm
- Location: Russia
- Has thanked: 384 times
- Been thanked: 614 times
- Contact:
Re: CAN Bus Extended ID
Hi.
This sounds good, keep going nice to see your progress
This sounds good, keep going nice to see your progress
https://www.flowcodexchange.com/
Regards QMESAR
Regards QMESAR
Re: CAN Bus Extended ID
Hi,
i have to reactivate this post... What i figured out - If i use the component macro to set the extended CAN ID (SetTxIdent) for a CAN Bus transmission the transmission works but with a lot of bit errors (stuffing error, TX errors). I used C Code to proramm the extended TX ID directly into the registers of the PIC (TXB0SIDH, TXB0SIDL, TXB0EIDH, TXB0EIDL) and wow- the transmission was without any errors (all seen with a PEAK CAN Dongle). I use the PIC18F2685 with a TJA1050 transceiver. My conclusion- there seems to be an error in the component macro?
maridd
i have to reactivate this post... What i figured out - If i use the component macro to set the extended CAN ID (SetTxIdent) for a CAN Bus transmission the transmission works but with a lot of bit errors (stuffing error, TX errors). I used C Code to proramm the extended TX ID directly into the registers of the PIC (TXB0SIDH, TXB0SIDL, TXB0EIDH, TXB0EIDL) and wow- the transmission was without any errors (all seen with a PEAK CAN Dongle). I use the PIC18F2685 with a TJA1050 transceiver. My conclusion- there seems to be an error in the component macro?
maridd