-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG & Fix] LPC1768 and LPC1769 will not compile when trying to use Adafruit MAX31865 board & PT100 sensor #20132
Comments
This is actually expected behaviour, at least from my lpc176x frameworks point of view, it is not a standard compliant Arduino framework implementation so I don't advertise it as such by setting the Some general purpose Arduino libraries have been tested and/or modified to work with my framework but in general they don't tend to be supported. Not sure what the correct solution for Marlin would be in this case, other than me making the framework actually Arduino compliant. |
@p3p I was not aware that LPC1768 and LPC1769 were not meant to run Adafruit MAX31865 boards. Tomorrow, I will actual bench test my above suggestion just to see if a SKR V1.3 or SKR V1.4 or SKR 1.4 Turbo will work with the Adafruit MAX31865 library. I will hook up an Adafruit MAX31865 with PT100 sensor via hardware spi to these boards one at a time. After I run the test, I will report my results back here. Let me run the test to see if this hack will allow SKR V1.3 or SKR V14 or SKR V1.4 Turbo boards to work with the Adafruit MAX31865 library. So please leave this ticket open until I can document whether or not these boards from Bigtreetech can or can not work with Adafruit MAX31865. Thank you for responding so quickly. |
@p3p I am still testing, please leave this open until I have told you I have given up trying. Thanks for your patience |
@p3p I have a question for you: In Marlin/src/HAL/LPC1768/include/SPI.h file you have the CLASS SPISettings which has a Method called SPISettings. This is the method I am asking about: SPISettings(uint32_t spiRate, int inBitOrder, int inDataMode) {
init_AlwaysInline(spiRate2Clock(spiRate), inBitOrder, inDataMode, DATA_SIZE_8BIT);
}
.
.
.
static inline uint32_t spiRate2Clock(uint32_t spiRate) {
uint32_t Marlin_speed[7]; // CPSR is always 2
Marlin_speed[0] = 8333333; //(SCR: 2) desired: 8,000,000 actual: 8,333,333 +4.2% SPI_FULL_SPEED
Marlin_speed[1] = 4166667; //(SCR: 5) desired: 4,000,000 actual: 4,166,667 +4.2% SPI_HALF_SPEED
Marlin_speed[2] = 2083333; //(SCR: 11) desired: 2,000,000 actual: 2,083,333 +4.2% SPI_QUARTER_SPEED
Marlin_speed[3] = 1000000; //(SCR: 24) desired: 1,000,000 actual: 1,000,000 SPI_EIGHTH_SPEED
Marlin_speed[4] = 500000; //(SCR: 49) desired: 500,000 actual: 500,000 SPI_SPEED_5
Marlin_speed[5] = 250000; //(SCR: 99) desired: 250,000 actual: 250,000 SPI_SPEED_6
Marlin_speed[6] = 125000; //(SCR:199) desired: 125,000 actual: 125,000 Default from HAL.h
return Marlin_speed[spiRate > 6 ? 6 : spiRate];
} This method or routine is called by the Adafruit_MAX31865.cpp code as shown below: static SPISettings max31865_spisettings =
SPISettings(500000, MSBFIRST, SPI_MODE1); The thing that worries me is that your SPISettings calls spiRate2Clock(spiRate). The Adafruit_MAX31865.cpp is not aware that Marlin uses index to speed. It just provides the 500,000 as its SPI speed. So with your code when Adafruit_MAX31865 calls SPISettings the actual speed will be set to 125000 because the spiRate is greater than 6 in the call. This is 1/4 of the speed that it should be. I am trying to decide if this is a non issue? I have changed the Adafruit call to SPISettings(4, MSBFIRST, SPI_MODE1); but I have not seen a difference. I am looking for your opinion. The maximums SPI speed the MAX31865 can do is 5MHz. I am still testing. I want to see if I can now use TMC2130 in SPI mode and see how that effects my setup. If you can get back to me about the above issue I would be grateful. Also do you know of a way to get the linker to include the Arduino.h file without having to change the Adafruit_MAX31865.h file? I am older than you and I might not be aware of new changes in compiler and linker directives so I am asking. In my time this was not possible. |
Marlin SPI usages is not very “standard” right now. We are working on in a better class and interface for that. But it’s a working in progress. I will take a look in your issue. |
@rhapsodyv and @p3p I can get the SKR V1.4 Turbo to run the Adafruit MAX31865 board in software SPI and Hardware SPI when SDCARD_CONNECTION is set for LCD. I have another question: if I change SDCARD_CONNECTION to ONBOARD does the default hardware SPI bus change from SPI-0 bus to SPI-1 bus (from "EXP2 connector" to "onboard SD card reader")? EDIT: well I just tested it and this is what I found.
If SDCARD_CONNECTION is ONBOARD with SDSUPPORT enabled the default SPI bus is SPI-1:
|
This issue has had no activity in the last 30 days. Please add a reply if you want to keep this issue active, otherwise it will be automatically closed within 7 days. |
This issue is still under review because the pull request that fixes this issue is still going through the review process. |
This issue is resolved because the PR #20447 has now been merged in bugfix branch |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Description
When I compile Marlin for SKR PRO V1.x board and use TEMP_SENSOR_0 set to -5, I can compile without a problem because in .vscode\c_cpp_properties.json file for SKR PRO V1.x boards it includes an ARDUINO constant set for 10808. This ARDUINO constant is used in Adafruit MAX31865::Adafruit_MAX31865.h file which in turn is used by Marlin's temperature.cpp file.
The PROBLEM: If ARDUINO constant is not set then Adafruit_MAX31865.h will include WProgram.h which is not what we want for the LPC1768 and LPC769 environments. The Adafruit_MAX31865.h file has the following code:
I am sure the above code was included to allow 8-bit boards to access the Adafruit MAX31865 library. But, it look like a problem arose and the .vscode\c_cpp_properties.json file for (SKR V1.3, SKR V1.4, SKR V1.4 TURBO,etc) LPC1768 and LPC1769 environments only have ARDUINOLPC constant set to 10805. The ARDUINO constant is NOT set for LPC1768 and LPC1769 envirnoments. In fact, the ARDUINO constant is NULL when the code hits the Adafruit_MAX31865.h file.
So when Marlin compiles and the compiler hits the include for the Adafruit MAX31865 library in temperature.cpp the Marlin code will load WProgram.h file instead of loading the correct Arduino.h file.
This means non of the LPC1768 or LPC1769 can use the PT100 with Adafruit MAX31865 boards on either TEMP_SENSOR_0 or TEMP_SENSOR_1. In other words, LPC1768 and LPC1769 can not use TEMP_SENSOR_0 set to -5 or TEMP_SENSOR_1 set to -5.
This bug report applies to both the release branch of Marlin and the bugfix-2.0.x branch of Marlin!
Configuration Files
Configuration files for LPC1768 env:
Configuration_files_LPC1768.zip
Configuration files for LPC1769 env:
Configuration_files_LPC1769.zip
In the above two zip files I also included the Adafruit_MAX31865.h file I changed to temporarily get around the problem:
Since Marlin defines the ARDUINOLPC constant instead of ARDUINO constant that the Adafruit Library wants I added code to the Adafruit_MAX31865.h header file :
I know this is a third party library. But the above fix allows the LPC1768 and LPC1769 environments to now compile without issue when they have TEMP_SENSOR_0 set to -5 in configuration.h file.
Here are the .vscode\c_cpp_properties.json files from LPC1768, LPC1769 and BIGTREE_SKR_PRO environments for your consideration:
c_cpp_properties.json files.zip
Steps to Reproduce
or
Try to compile the code and you will get the following errors (below shows the LPC1769 environment compiler output):
Log Output
Expected behavior:
I expect the Marlin code to compile when I want use MAX31865 in hardware spi on a SKR V1.4, SKR V1.3 or SKR V1.4 Turbo board.
Actual behavior:
See the above compiler error.
Additional Information
Here is the configuration files for this bug report and a video showing the problem:
Configuration files:
Configuration_Issue#1.zip
Video of Issue#1: https://drive.google.com/file/d/1xdhI9QNYdjAKTzIfNopnHdkLFYAhaBGN/view?usp=sharing
When I try to add the compiler directive -DARDUINO=10808 to the LPC1768 environment the compile still gets a fatal error and the compiler throws a lot of warnings from the U8glib-HAL code:
Log Output
When I apply my code fix to the Adafruit_MAX31865.h file:
In Adafruit MAX31865::Adafruit_MAX31865.h file:
Original statement:
How I fixed the issue:
Compiler output (error free) when I added ARDUINOLPC compiler constant to Adafruit MAX31865::Adafruit_MAX31865.h file for LPC1769 environment is shown below::
Log Output
The text was updated successfully, but these errors were encountered: