0

I'm working on lcd128x64 spi library. And was working with my Arduino Atmega328p chip.

Now I want to run the code with my maple mini board too. So I have to specify the name on the pins for each chip board. But I want to learn the basics of how to write these statements.

Could you tell me where to find the attributions for each board ?

For now I want to define the pin names for the Atmega328p and maple mini. This is my intention:

#if defined(__AVR_ATmega328P__)
    #define CS_PIN                  10
    #define MOSI_PIN                11
    #define CLK_PIN                 13
#elif defined(STM32_SERIES_F1)  
    #define CS_PIN                  PB12
    #define MOSI_PIN                PB15
    #define CLK_PIN                 PB13
#endif  

I don't think that's %100 correct, but I'm pretty sure that it's not the correct names of boards.

  • 2
    The whole point of the Arduino API is that you don't need to know the names of pins. You just need the numbers that the API assigns to them. – Majenko Mar 10 at 12:14
  • 2
    the SPI libraries know the pin numbers. you don't need to spceify them in normal case. the pins 11, 12, 13. are valid for Uno and Nano, not for ATmega328p. – Juraj Mar 10 at 12:32
  • Yeah I know but in my lcd128x64 library, I'm using both atmega328p and stm32 which is using other pins names and also it has two spi modules. Like, in this init function void lcd128x64_init(void){ pinMode(CS_PIN, OUTPUT); pinMode(CLK_PIN, OUTPUT); pinMode(MOSI_PIN, OUTPUT); digitalWrite(CS_PIN, LOW); // disable CS_PIN SPI.begin(); _delay_ms(100); // initial delay digitalWrite(CS_PIN, HIGH); // enable CS_PIN ... } the pins names are different, so I want to unify them in the header file. – R1S8K Mar 10 at 12:51
  • Also spi2 initialization for stm32 is different SPI_2.begin(); //Initialize the SPI_2 port. SPI_2.setBitOrder(MSBFIRST); // Set the SPI_2 bit order SPI_2.setDataMode(SPI_MODE0); //Set the SPI_2 data mode 0 SPI_2.setClockDivider(SPI_CLOCK_DIV16); // Use a different speed to SPI 1 pinMode(SPI2_NSS_PIN, OUTPUT); so I have put that in my lcd128x64 lib – R1S8K Mar 10 at 12:52
  • When I try to compile the code for the maple mini I get this: Arduino: 1.8.12 (Windows 10), Board: "Maple Mini, Original (17k RAM,108k Flash), 72MHz (Normal), Smallest (default)" H:\Programming\Program_Files\Arduino\libraries\lcd128x64_spi\lcd128x64_spi.cpp:14:20: fatal error: avr/io.h: No such file or directory #include <avr/io.h> ^ compilation terminated. exit status 1 Error compiling for board Maple Mini. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences. – R1S8K Mar 10 at 13:51
2

The Arduino defines to identify a board are in form of ARDUINO_<board>, where <board> is the value from <x>.build.board from boards.txt for board <x>

For example for Arduino AVR boards, in the boards.txt file is uno.build.board=AVR_UNO so the define is ARDUINO_AVR_UNO.

And Arduino has 'architecture' identification define too. This has form of ARDUINO_ARCH_<arch.name>. The <arch.name> is the uppercase version of the folder name with the boards package version. For example AVR for packages/arduino/hardware/avr/1.6.21.

| improve this answer | |
  • But I want the specific attribution that are like in this link. @microchip.com/webdoc/avrlibcreferencemanual/… I want the same for the STM32 I couldn't find its attribution. – R1S8K Mar 10 at 16:44
  • 1
    @R1S8K, use arduino board or architecture identification, not the chip identification. – Juraj Mar 10 at 17:46
  • OK but I get now fatal error that including the avr/io .. Arduino: 1.8.12 (Windows 10), Board: "Maple Mini, Original (17k RAM,108k Flash), 72MHz (Normal), Smallest (default)" H:\Programming\Program_Files\Arduino\libraries\lcd128x64_spi\lcd128x64_spi.cpp:14:20: fatal error: avr/io.h: No such file or directory #include <avr/io.h> ^ compilation terminated. exit status 1 Error compiling for board Maple Mini. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences. What to do now ? – R1S8K Mar 10 at 17:52
  • 1
    @R1S8K, ask a new question – Juraj Mar 10 at 17:54
  • 1
    @R1S8K, instead of __AVR_ATmega328P__ use ARDUINO_AVR_UNO for pin mapping defines – Juraj Mar 12 at 5:09
1

If you are working on Maple Mini, you may look in this folder, you will found the pin mapping between STM32 and Arduino nomenclature.

| improve this answer | |
  • Yep, you're right. I didn't notice the rest of the name ! I thought they are just STM chips but I found the maple mini folder there, but also couldn't find the right attribution. – R1S8K Mar 10 at 17:51
  • 1
    I don't get what you are looking for: is not enough this {&gpiob, NULL, NULL, 11, 0, ADCx}, /* D0/PB11 */ ? – fabiuz7 Mar 10 at 18:04
  • Maybe the official repo is cleaner: look at this file – fabiuz7 Mar 10 at 18:11
  • 1
    try this define, for me it worked ;) ARDUINO_MAPLEMINI_F103CB – fabiuz7 Mar 10 at 20:29
  • 1
    Which Arduino Core are you using? I had installed this one – fabiuz7 Mar 10 at 20:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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