|
Post by lukint on Mar 20, 2018 14:17:26 GMT
Hi, I'd like to build up a datalogger for incoming CAN-Data, which should be stored on SD-Card. First I tried this with an arduino due but it was even too slow, so I went to to ShieldBuddy. So I tried to just print out the CAN-Messages to the Serial Monitor, with the library provided by SeeedStudio, but that didn't work. The program didn't come out of setup() and didn't even print out the Failed or succes message. I attached the used library and my little test programm (which worked on the Due). Test_CAN.cpp (2.74 KB) CAN_BUS_Shield_V2.zip (30.25 KB) Later on I would like to use the SdFat library for storing the data on SD. Has anybody used this library with the ShieldBuddy before? Thanks for your help.
|
|
|
Post by Admin on Mar 20, 2018 15:53:23 GMT
Hi, The mcp_can.cpp in the Seedstudio v2.0 CAN driver contains some debug statements that use Serial.print. For the ShieldBuddy these need to be converted to SerialASC.print: #if DEBUG_EN SerialASC.print("Enter normal mode fall\r\nSet filter fail!!\r\n"); #else delay(10); #endif See: mcp_can.cpp (42.26 KB) The SDfat should work. If you are concerned about performance, you could run the SD card software on core 1.
|
|
|
Post by lukint on Mar 21, 2018 14:51:53 GMT
Ok, thank you very much. The CAN-Bus communication is now working. But I'm still struggeling with the implementation of SD functionalities. I try to do sd.begin(4) but every time I tried it failed. So could it be a problem, that I use the SPI-Bus for CAN and SD? For the used shield I had to set up the CS pins to pin 9 for CAN and pin 4 for SPI.
|
|
|
Post by Admin on Mar 21, 2018 14:57:56 GMT
The SD card should work on SPI CS= pin4. The Ethernet shield uses pin10 for the Ethernet SPI chipselect and pin 4 for the SD card chipselect and this works fine. There is an example sketch "main_SD.ino" which drives just the SD card on pin4. See if this works. That would prove that the SD card on the Seeed CAN shield works. main_SD.ino (3 KB)
|
|
|
Post by lukint on Mar 21, 2018 15:22:49 GMT
Ok, this is working. But I tried to run this example with the SdFat, and it is not working. With SdFat it says initialization failed!
|
|
|
Post by Admin on Mar 21, 2018 16:49:30 GMT
The SD file system used in the main_SD example is FAT32. Is this not what you want?
|
|
|
Post by lukint on Mar 22, 2018 8:20:36 GMT
The Fat File system is ok for me, but the performance of the standard SD library is too less. So that is why I want to use the SdFat library, which I attached here. SdFat-1.0.5.zip (195.67 KB) And with this library I have the problems I discribed above.
|
|
|
Post by Admin on Mar 22, 2018 9:59:48 GMT
The basic problem is that the SD card driver is hard-wired into the ShieldBuddy Arduino library so the SdFAT library is ignored. It looks like the SdFAT library is much faster than the standard one is because it uses a DMA-based SPI driver. Theoretically this is possible on the ShieldBuddy also but we have not implemented it yet.
The SdFAT library can be used but you will have to remove the hard-wired one. This is done by editing the platform.txt in "C:\Program Files (x86)\Arduino\hardware\aurduino\aurix".
platform.txt (11.23 KB)
Make sure you save the original one!
Delete the "C:\Program Files (x86)\Arduino\hardware\aurduino\aurix\libraries\SD" directory
The SdFAT library is then used. However we have not extensively tested this and there is no guarantee it will work properly. Running the SPI at 50MHz will not work. 10MHz is a safe starting point!
We will look at properly supporting SdFAT or using DMA-driven SPI in the next release.
|
|
|
Post by lukint on Mar 22, 2018 12:39:50 GMT
Ok, it's working now with the SdFat lib and a SPI rate of 12MHz but that is much too slow. A single call of myFile.print(buf1) takes 13ms when operating with core0 and 22ms in core1! That's weird, isn't it? My aim is to work with 2ms per print command. Would this be improved with the next release? And do you have a date, when the release is planned for?
|
|
|
Post by Admin on Mar 22, 2018 14:41:30 GMT
Have you tried increasing the bit rate? Theoretically it can go up to 40MHz.
|
|
|
Post by lukint on Mar 22, 2018 14:47:21 GMT
Yeah I did this, but over a SPI speed of 12 MHz the SD-Card intialisation fails every time.
|
|
|
Post by Admin on Mar 23, 2018 13:24:56 GMT
Sometimes the SD write cycle time is the limiting factor rather than the SPI speed. How many bytes are you storing in a single operation?
|
|
|
Post by lukint on Mar 27, 2018 6:16:23 GMT
Hi, I'm storing 2,3 KByte per cycle. I have reached a writing time around 2 ms with an arduino Due, but I have to do this completely parallel to the reading of CAN, so thats why I use the ShieldBuddy.
|
|
|
Post by Admin on Mar 27, 2018 11:12:58 GMT
I did some tests and the SD card type is the dominant factor when it comes to write speed. Using a Sandisk SDHC card, the approximate write speed is 89kbyte/sec. Using a Kingston SD the write speed is only 11kbyte/sec. This was using the default 4Mbit/s SPI speed. Increasing the SPI speed to 6MBit/sec made virtually no difference!
|
|
|
Post by lukint on Mar 27, 2018 12:00:09 GMT
Ok, I get a rate of around 120 kbytes/sec with a spi speed of 15MHz, so I do think that when I could increase the spi speed to 40/50 MHz I can improve the writing speed in a relevant way. So my question is, why can't I set the spi speed to a higher rate than 15MHz, and are there any opinions how I can solve this problem?
Many thanks.
|
|