For example constant of MSBFIRST
, It used to as input in SPI.setBitOrder(MSBFIRST)
. But sadly i don't know the type data of MSBFIRST
. This is applied to like SPI_MODE0
and other.
-
short and universal answer: look in the .h files of the library for function parameter type– Juraj ♦Commented Apr 18, 2022 at 9:59
1 Answer
From SPI.h:
#ifndef LSBFIRST
#define LSBFIRST 0
#endif
#ifndef MSBFIRST
#define MSBFIRST 1
#endif
As you can see, there is no type. The compiler merely substitutes literally "1" for "MSBFIRST". So your code would read, after pre-processing:
SPI.setBitOrder(1)
To know exactly what type "1" is (I'm not sure why you need to know) then you would look up "C++ integer promotion". In other words, how are literal integers handled by the C++ compiler.
From a comment:
In which case it's better to look at the desired type of the destination function not the type of the macro or const.
Quite right. If you look further into the SPI.h file you see this:
// This function is deprecated. New applications should use
// beginTransaction() to configure SPI settings.
inline static void setBitOrder(uint8_t bitOrder) {
So, ignoring what type MSBFIRST is, you can see that the function expects uint8_t.
-
2Maybe he wants to know what the type is so he can use it as a parameter to some form of wrapper function or another form of abstraction layer? In which case it's better to look at the desired type of the destination function not the type of the macro or const.– MajenkoCommented Apr 18, 2022 at 8:38
-
@Majenko Indeed. I've amplified my reply to show this.– Nick Gammon ♦Commented Apr 18, 2022 at 9:20
-
@Majenko you are right, i want to know type so i can use it as parameter for my abstraction layer. Nevermind, I already know the data type with using
Serial.println(MSBFIRST)
, it was displaying1
in serial monitor. So i assume the data type is unsigned integer aka byte. Commented Apr 18, 2022 at 12:15