Arduino CAN bus SparkFun CAN

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by LeighM »

That does sound odd. I suspect the SPI, could you try running it slower, or perhaps change the sample point to “Middle”?

fredrikah
Posts: 31
Joined: Fri Dec 17, 2010 7:57 am
Has thanked: 1 time
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by fredrikah »

thanks for your reply.

yep, it acts very strange.

what is the setting for running it slower?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by LeighM »

Try Prescale = Fosc/32 ... etc

fredrikah
Posts: 31
Joined: Fri Dec 17, 2010 7:57 am
Has thanked: 1 time
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by fredrikah »

oh yes, now the setting that was magic came.


Before, with "Sample point End"
then i had to use CheckRx(1) to triger "RX Buffer 0"

now when i change to "Sample point Middle"
then i can use CheckRx(0) to triger "RX Buffer 0"

and now it works.

I will do some more test now.

fredrikah
Posts: 31
Joined: Fri Dec 17, 2010 7:57 am
Has thanked: 1 time
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by fredrikah »

Further test:

Prescale did no difference with Sample point End.


Sample point Middle did it.
now it works :-)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by LeighM »

Phew, glad to hear :D

fredrikah
Posts: 31
Joined: Fri Dec 17, 2010 7:57 am
Has thanked: 1 time
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by fredrikah »

Great thanks!!

Next question.

GetRxIDLo function:

when i send ID 0x1 with my CAN analyser
GetRxIDLo returns 20 (hex)

when i send ID 0x2 with my CAN analyser
GetRxIDLo returns 40 (hex)

when i send ID 0x3 with my CAN analyser
GetRxIDLo returns 60 (hex)

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by LeighM »

If you hover your mouse over the function names of the CAN component in the Project Explorer you will see the hint text.
The GetRxIDLo reads the raw device register, so see the CAN controller datasheet to see the reason for the apparent data shift.
You more likely need to use GetRxIdent instead of GetRxIDLo/Hi

fredrikah
Posts: 31
Joined: Fri Dec 17, 2010 7:57 am
Has thanked: 1 time
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by fredrikah »

All tested, works perfect!

Now next question that i have got into.


I have 2 shields, as you can see ealier in this tread.

it works to send from CAN1 -> CAN2.

and I should also send from CAN2 -> CAN1

but when i send from CAN1 -> CAN2, then i guess that it goes into the buffer of CAN2? and this will be triggered to send back to CAN1 then,
and then i have a loop.

I was thinking that before i send from CAN1 -> CAN2, then i would switch off CAN2 RX Buffer0
and then when i have sent, then i switch it on again.

what settings should i do? I currently have Accept all.
But Accept all, and reject all, this i cant put into this box:
Attachments
SetBufferCAN2.PNG
SetBufferCAN2.PNG (92.97 KiB) Viewed 3405 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by LeighM »

To accept all, just set the mask to 0
To reject all, set the mask to 0x7ff (in the case of standard IDs) and the filter to 0
e.g. SetRxMask(0,0x7ff) and SetRxFilter(0,0)
A read of the Microchip CAN controller datasheet is well worth the time.
You will need this to understand which mask each filter is associated with, and how these work.

fredrikah
Posts: 31
Joined: Fri Dec 17, 2010 7:57 am
Has thanked: 1 time
Contact:

Re: Arduino CAN bus SparkFun CAN

Post by fredrikah »

Many thanks! :D

Post Reply