1

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.

1
  • 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 1

2

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.

3
  • 2
    Maybe 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.
    – Majenko
    Commented 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 displaying 1 in serial monitor. So i assume the data type is unsigned integer aka byte. Commented Apr 18, 2022 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.