# P2 with canbus and sd card

**URL:** <https://community.particle.io/t/p2-with-canbus-and-sd-card/63054>\
**Category:** Hardware\
**Created:** [August 27, 2022, 7:20am UTC](https://community.particle.io/t/p2-with-canbus-and-sd-card/63054 "2022-08-27T07:20:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![atom](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@atom](https://community.particle.io/u/atom)\
**Post date:** [August 27, 2022, 7:20am UTC](https://community.particle.io/t/p2-with-canbus-and-sd-card/63054/1 "2022-08-27T07:20:00Z")

</div>

Hello,

We will use the P2 with a SD card (502774-0891), and also with CAN bus (MCP25625)  
The P2 has two SPI, how should we connect them?  
SD card to SPI and canbus to SPI1? Or other way around?

Or is it possible to connect to eg to SPI1?  
Will it be stable with the libraries, eg with callback functions?

What about the speed? Does it make any difference if SD card to SPI and canbus to SPI1?  
Or both to the SPI1?

What is the best practice?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![rickkas7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rickkas7/32/8681_2.png) [@rickkas7](https://community.particle.io/u/rickkas7)\
**Post date:** [September 8, 2022, 5:53pm UTC](https://community.particle.io/t/p2-with-canbus-and-sd-card/63054/2 "2022-09-08T17:53:53Z")

</div>

Generally speaking, you can have multiple devices on the same SPI bus. The CAN bus library is definitely compatible, as there are a large number of devices on the Tracker SPI bus.

The SDFat library is compatible if you’ve enabled transaction support in the library.

The two SPI busses are different speeds:

- SPI uses the RTL872x SPI1 peripheral (25 MHz maximum speed)
- SPI1 uses the RTL872x SPI0 peripheral (50 MHz maximum speed)

I would typically use a single SPI bus with multiple devices instead of two busses.

The main exception is that if you have one SPI peripheral that does very lengthy transactions, and one that requires low latency. That is sort of the case with SD card and CAN, since SD card erase sector can take some time to execute, and you may want to perform CAN operations at the same time. This would require separate SPI busses. However, depending on how you are using CAN, this may or may not be an issue.

---

<div class="post-metadata">

**Author:** ![atom](https://avatars.discourse-cdn.com/v4/letter/a/85f322/32.png) [@atom](https://community.particle.io/u/atom)\
**Post date:** [September 9, 2022, 8:34am UTC](https://community.particle.io/t/p2-with-canbus-and-sd-card/63054/3 "2022-09-09T08:34:21Z")

</div>

> [@rickkas7](#):
>
> ou have one SPI peripheral that does very lengthy transactions, and one that requires low latency. That is sort of the case with SD card and CAN, since SD card erase sector can take some time to execute, and you may want to perform CAN operatio

Thank you so much Rick! I think will make it on two different buses. I let you know our experience later.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)\
**Post date:** [March 10, 2023, 8:34pm UTC](https://community.particle.io/t/p2-with-canbus-and-sd-card/63054/4 "2023-03-10T20:34:37Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
