I am switching a code from Arduino Uno R3 to Arduino Uno R4 Wifi due to the limitation of RAM spaces on R3. I use a thermocouple shield and SD Card read/write shield with the project, which requires me to transfer between mode 3 and mode 0 on R3. However, when I try to do the following code on R4:
SPI.setDataMode(SPI_MODE3);
The IDE told me that SPI does not have a function named setDataMode. I tried to run the program without using setDataMode, but it does not seem work correctly (SD Cards with empty data).
Compilation error: 'class arduino::ArduinoSPI' has no member named 'setDataMode'
Thank you all for helping. the issue is resolve by using SPISettings
variable along with SPI.beginTransaction(SPISettings)
and SPI.endTransaction(SPISettings)
-
The text is pretty much what described in the question, it says: Compilation error: 'class arduino::ArduinoSPI' has no member named 'setDataMode', which this is the command to change data mode using Arduino UNO R3Bh4– Bh42024年11月27日 18:48:12 +00:00Commented Nov 27, 2024 at 18:48
-
the message text belongs in the question. not in a comment ... added it for you ... you can delete the commentjsotola– jsotola2024年11月27日 19:37:13 +00:00Commented Nov 27, 2024 at 19:37
-
The first paragraph of the SPI.setDataMode() documentation said "This function should not be used in new projects. Use SPISettings. with SPI.beginTransaction(). to configure SPI parameters". I wish they could be more explicitly saying "This function is deprecated since 2014 and only exist for backward compatibility reason".hcheung– hcheung2024年11月28日 01:14:27 +00:00Commented Nov 28, 2024 at 1:14
-
See my answer to a similar question for further explanation.hcheung– hcheung2024年11月28日 01:20:33 +00:00Commented Nov 28, 2024 at 1:20
-
Thank you for the help @hcheung, the issue is resolved with 'SPISettings' and SPI.beginTransaction(SPISettings)Bh4– Bh42024年11月28日 03:27:56 +00:00Commented Nov 28, 2024 at 3:27
1 Answer 1
I looked at SPI.h in the R4 core here: https://github.com/arduino/ArduinoCore-renesas/blob/main/libraries/SPI/SPI.h
It looks like you have to set up a configuration struct and pass to a different function:
arduino::SPISettings const DEFAULT_SPI_SETTINGS = arduino::SPISettings(1000000, MSBFIRST, arduino::SPI_MODE0);
arduino::SPISettings _settings = arduino::SPISettings(0, MSBFIRST, arduino::SPI_MODE0);
Then in beginTransaction
you have the opportunity to pass in those settings:
virtual void beginTransaction(arduino::SPISettings settings);
I'm not 100% sure how that all works, but at least this should get you going in the right direction.
-
Thanks for the help, you can reply to me either here or on the forum. I will be looking at both sides, and I will post solutions either from forum or from here once we have a solutionBh4– Bh42024年11月28日 00:46:19 +00:00Commented Nov 28, 2024 at 0:46
-
It would be better if you had only one post. It's mostly the same people on both sites. Your post there is probably better because there are a few of us that have been digging really deep on the R4.Delta_G– Delta_G2024年11月28日 02:14:56 +00:00Commented Nov 28, 2024 at 2:14
-
Have you tried this? Create the settings you need following the model in this answer and then try passing that to
beginTransaction
Delta_G– Delta_G2024年11月28日 02:16:28 +00:00Commented Nov 28, 2024 at 2:16
Explore related questions
See similar questions with these tags.