You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CAN module works fine, checked in another code.
Now I decided to launch in addition to the CAN module also a module for saving data to the micro SDHC card.
I have three microSD cards - 512 MB(fat16), 8 GB(fat32) and 32 GB(fat32).
The cards are not of the best quality, the 512 MB card stopped being detected after the first attempt to consider it a SD module, and it can't even be formatted via the program.
All this is just information, for the general picture.
The work of two modules CAN bus transceiver and microSD module on one SPI bus is interesting.
Using a logic analyzer, I measured the speed of one module CAN
Two simultaneously working modules CAN and microSD
Probably screenshots are not as clear as viewing data directly in the analyzer.
As you can see, when
CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ)
is running, the pauses between sending messages to CAN are on average 6 ms.
When
CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ)
and
sd.begin(SD_CS_PIN, SD_SCK_MHZ(20))
are running, the pauses between sending messages to CAN are about 16-20 ms, which significantly affects the external device that receives data via the CAN bus - it begins to noticeably slow down with data display.
But my question is not specifically about this, my question is about how and where does the
SdFat.h
library configure the SPI bus?
The SPI bus for the CAN module is configured as follows
Regarding SdFat, I don't understand what mode is needed, I set the speed directly in the Arduino Setup section:
SD_SCK_MHZ(20)
But despite the fact that both devices have a speed of 20 MHz on the SPI bus, the analyzer shows complete nonsense, there is never a stable speed, but the problem is still not in this, as it seems to me, but in the fact that the library for the CAN module closes the SPI connection every transaction
And the SdFat library does something of its own, and I don't understand it
As you can see from the screenshot, the SdFat select pin chip occupies the SPI bus for 7 ms, and the select chip of the CAN module occupies the SPI bus for 1.18 ms.
As far as I understand, the CS pin for the operation of the microSD module begins its cycle by pressing the CS pin to 0 - label 0, then it pulls the CS pin twice and at label 1 it completes the recording cycle and then there is a pause until label 2. The CS pin of the CAN module operates between labels 1 and 2.
In general, I am not a big expert in analyzing what is happening on the SPI bus, perhaps the community will help me figure out the issue and make the operation of two devices on the SPI bus correct and coordinated.
The text was updated successfully, but these errors were encountered:
Sharing an SPI port with an SD and any device that requires quick response is a bad idea.
Run the bench example in shared and dedicated mode to see why.
Here is a quote from the SD standard:
The host should use 100 ms timeout (minimum) for single and multiple read operations
rather than using TAAC and NSAC.
The host should use a fixed timeout for write operations rather than using a timeout calculated from
the R2W_FACTOR parameter.It is strongly recommended for hosts to implement more than 500ms
timeout value even if the card indicates the 250ms maximum busy length.
In general, an SD can have occasional long delays. See the Physical Layer Simplified Specification here.
When I design a time critical app I use a dedicated SPI port for the SD, multiple threads in a RTOS or interrupts to provide fast access for sensors. Also provide sufficient buffer.
But my question is not specifically about this, my question is about how and where does the
Good day @greiman
According to
GitHub
tradition, I express my gratitude to you for your work🙂My microcontroller
stm32f411ceu6
I compile the code into
vscode
+.pio
and use theframework
I also have a
BNO08x
sensor, which is connected via theI2C
bus via the libraryBus speed is
400
kHz.I connect two different devices to it via
SPI
:CAN
bus transceivermodule with
microSD
Two device boards are connected to one
SPI
, only differentSS
contacts.The connection is very simple, I use standard contacts for the
SPI
:The
CAN
module works fine, checked in another code.Now I decided to launch in addition to the
CAN
module also a module for saving data to the microSDHC
card.I have three microSD cards -
512
MB(fat16),8
GB(fat32) and32
GB(fat32).The cards are not of the best quality, the
512
MB card stopped being detected after the first attempt to consider it aSD
module, and it can't even be formatted via the program.https://www.sdcard.org/downloads/formatter/sd-memory-card-formatter-for-windows-download/
The best and fastest working
microSD
is8GB
, itsSdInfo
report is below:All this is just information, for the general picture.
The work of two modules
CAN bus transceiver
andmicroSD module
on oneSPI
bus is interesting.Using a logic analyzer, I measured the speed of one module
CAN
Two simultaneously working modules
CAN
andmicroSD
Probably screenshots are not as clear as viewing data directly in the analyzer.
As you can see, when
is running, the pauses between sending messages to CAN are on average 6 ms.
When
and
are running, the pauses between sending messages to
CAN
are about16-20
ms, which significantly affects the external device that receives data via theCAN
bus - it begins to noticeably slow down with data display.But my question is not specifically about this, my question is about how and where does the
library configure the
SPI
bus?The
SPI
bus for theCAN
module is configured as followsWhat mode does
SdFat
use?Regarding
SdFat
, I don't understand what mode is needed, I set the speed directly in theArduino Setup
section:But despite the fact that both devices have a speed of
20
MHz on theSPI
bus, the analyzer shows complete nonsense, there is never a stable speed, but the problem is still not in this, as it seems to me, but in the fact that the library for theCAN
module closes theSPI
connection every transactionAnd the
SdFat
library does something of its own, and I don't understand itAs you can see from the screenshot, the SdFat select pin chip occupies the
SPI
bus for7 ms
, and the select chip of theCAN
module occupies theSPI
bus for1.18 ms
.As far as I understand, the
CS
pin for the operation of themicroSD
module begins its cycle by pressing theCS
pin to 0 -label 0
, then it pulls theCS
pin twice and atlabel 1
it completes the recording cycle and then there is a pause untillabel 2
. TheCS
pin of theCAN
module operates between labels1
and2
.In general, I am not a big expert in analyzing what is happening on the
SPI
bus, perhaps the community will help me figure out the issue and make the operation of two devices on theSPI
bus correct and coordinated.The text was updated successfully, but these errors were encountered: