Building a CAN API for Arduino DUE

http://togglebit.net/how-to-gateway-messages/

Hey Thank you for the fast answer.

My researches brought me to your can Shield and Im gonna buy it.

But my actual question was about, is the Clock Speed sufficient to forward 200 Messages and not only like 7. I just want to Manipulate one of these messages.

Thank you so much for your support.

Greetings

Clock speed is only a part of a more complex problem. I suggest having a read through the datasheet for the processor and inspect the underlying code you'll see there are message filters and different and more efficient ways of handling ISR's with hardware pointers, and then you have the overhead of your code, message buffer sizes, baud rate, the transmit rate of messages that are transmitted from your devices etc.

Maybe a valid first step is to simply just test the code thats written and see how far you get and optimize from there....i've not tested that particular bit of code with 200 messages.

Okey thank you so far.

I don't have a due here to try it so I have to order both.

Im just stucking if I should just go ahead with a Raspberry PI 3 where the performance would be much higher. I don't want to waste my really small budget.

Greetings.

I don't know that a PI3 has a built-in CAN controller, so you will be stuck with what you can get through SPI just something to look out for....

gaskraank: Okey thank you so far.

I don't have a due here to try it so I have to order both.

Im just stucking if I should just go ahead with a Raspberry PI 3 where the performance would be much higher. I don't want to waste my really small budget.

Greetings.

For what it's worth, I've used my library (due_can) to capture over 4000 frames per second with the Due. I can send that quickly too. I really don't think you're liable to have any trouble in forwarding 300 messages per second. I can see no reason this wouldn't work with ToggleBit's library too. The Due is plenty fast for keeping up with two CAN buses.

^What AdderD said^. Don't worry. It's lightning fast. I am receiving 1000 fps on the Due. And even doing some silly slow sprintfs on the data.

There you go, good feedback.

Hey Guys,

thank you so much for the reputation!

As soon as everything arrives I will report if it works or not. The source code to implement this should be really easy.

If have the time and opportunity I will do some measurements how fast a message gets forwarded.

Thank you all!

Greetings

Hey Guys,

my Arduino just arrived.

I wired the attached circuit together and tried to receive some messages.
Everything worked well, but when I try to use the PingPong, Echo Example nothing happens.
This means the sendFrame function is not working.

Is there anything special to be aware of?
The circuit how I done is in the attachment.
I tried to use this circuit :

I’m currently using the SN65HVD230 from Texas Instruments.

Greetings.

image3.JPG

image4.JPG

You need 120 Ohms resistors at each end of the bus.

If you have issues with your transceivers, to test your CAN software, make a CAN bus without transceivers (it works up to a few meters long):

https://www.mikrocontroller.net/attachment/28831/siemens_AP2921.pdf

Note that you would have to connect the resistor to 3.3V (and not 5V). Choose the resistor so that the current be lower than 1.6 mA.

Hey Thank you for your answer.
Okey I added the 120 Ohm and I also have a lot of traffic on the can RX side already.

If I want to send a frame this won’t work.
Do you think that’s because of the transceiver.
Greetings

Do you think that's because of the transceiver ?. The most obvous answer is NO, but there must be something wrong in your wiring.

Check all contacts on your breadboard.

The bus is supposed to be a twisted pair, althought it should not be an issue on such a short distance.

Hey,

I just breaked out CANTX on the Oscilloscope and I have a Square Signal on that. If Break-Out CANH or CANH there's only noise.

Do I have to activate Receive and Send on the transceiver could that be possible?

Greetings.

That particular transceiver has no enable pin so it is essentially always on. If you have signals on CANRX and CANTX but the CANL and CANH lines are garbage then there is likely a wiring fault on the H/L side (the actual CAN bus). What you should get is a square wave on H/L when you use L for ground on your scope and H at the scope input. Or connect to your local board ground with the scope and L will sink then return to center and H will rise and return to center. They ought to rest at essentially the exact same voltage. At rest H = L so you will measure 0 volts. When active they pull away from each other as a squarewave that ought to look like an exact mirror image of each other. The more it differs from that ideal the worse off you are.

Be careful here, if you connect the scope ground to 'L' and the Due is powered from USB, you may be shorting 'L' via mains earth (if your local mains supply has this). You're better off 'scoping both the 'L' and 'H' simultaneously.

Can (no pun intended) we have 'scope traces of the noise?

I assume you've checked that there is in fact 3v3 across the modules supply pins. (I had a board with a 5v part fitted instead of 3v3 and all I got was noise).

If you are using the 230 part instead of the 234, note that pin 5 is not supposed to be connected to 3v3, it's a reference output, forcing this to 3v3 may be why it doesn't work as expected (and could damage it).

weird_dave: Be careful here, if you connect the scope ground to 'L' and the Due is powered from USB, you may be shorting 'L' via mains earth (if your local mains supply has this). You're better off 'scoping both the 'L' and 'H' simultaneously.

Can (no pun intended) we have 'scope traces of the noise?

I assume you've checked that there is in fact 3v3 across the modules supply pins. (I had a board with a 5v part fitted instead of 3v3 and all I got was noise).

If you are using the 230 part instead of the 234, note that pin 5 is not supposed to be connected to 3v3, it's a reference output, forcing this to 3v3 may be why it doesn't work as expected (and could damage it).

Hey thank you for the helpful information.

Currently PIN 5 of the transceiver is connected to 3v3 you think it has to be connected with 5V instead?

I could do some scope traces of the noise but I will try to use the 5V first. Do you mean the modules supply pins the pins of the arduino board or of the transceiver?

AdderD: That particular transceiver has no enable pin so it is essentially always on. If you have signals on CANRX and CANTX but the CANL and CANH lines are garbage then there is likely a wiring fault on the H/L side (the actual CAN bus). What you should get is a square wave on H/L when you use L for ground on your scope and H at the scope input. Or connect to your local board ground with the scope and L will sink then return to center and H will rise and return to center. They ought to rest at essentially the exact same voltage. At rest H = L so you will measure 0 volts. When active they pull away from each other as a squarewave that ought to look like an exact mirror image of each other. The more it differs from that ideal the worse off you are.

Yes so I'm gonna do some measurements on CANTX and CANRX on the Oscillator today again and post the scope here.

I'm going to check if CANL and CANH has 0 Volts when there is nothing send. But I already checked with the multimeter and if I was Sending Frames there was still 0 Volts. If I receive Messages via CANalzyer its about 190 mV. Receiving Messages is working fantastic, do you think this could be still a wiring fault on the H/L side?

Thank you so much for all the answers.

Hey Again,

maybe this is also important to know.

I used this CAN Transceiver Board KNACRO SN65HVD230 Bought them here https://www.amazon.com/KNACRO-SN65HVD230-Communication-transceiver-Arduino/dp/B01ILU2WP6/ref=cm_cr_arp_d_pdt_img_top?ie=UTF8

So the SN65HVD230 is already wired on a breakout board an I only added the capacitors in between.

Greetings

It seems that these transceivers have already 120 Ohms resistors, no need to add them. Remove capacitors and see what happens.

Stupid website logged me out while I was replying, I'm not going through all that again

Suffice to say, don't connect anything to pin 5, it's an output! CANH and CANL should never be both 0v or both 3v3.

disconnect everything on CANL and CANH at the module and attach 2 channels of a scope to them. I would also disconnect Rx and Tx from the module, get this working then attach the Rx and TX and see if it still works, then attach to CANL and CANH, at one of these stages it will fail, indicating where the problem is. I also advise taking a look at the datasheet for the IC.