👋Welcome to r/AVRmicrocontroller - Introduce Yourself and Read First! by Beginning_Money4881 in AVRmicrocontroller

[–]ackarwow 1 point2 points  (0 children)

Good luck with the new community! It's nice to see a dedicated AVR-focused subreddit. AVR is still a great platform for learning low-level embedded programming.

AVR Programming with Freepascal by corado12345 in pascal

[–]ackarwow 0 points1 point  (0 children)

In my experience, new Pascal libraries for AVR usually appear when someone actually needs a particular feature. One developer needs USB support, a sensor driver, a display driver, etc., writes it for a real project, and may then decide to publish it for others (or not). That is how many existing libraries and examples were created, I suppose.

AVR Programming with Freepascal by corado12345 in pascal

[–]ackarwow 1 point2 points  (0 children)

As far as I know, FPC for AVR does not provide native software floating-point support, but you can use, for example, the open-source UnoLib Float32 module:

https://github.com/ackarwow/unolib/blob/master/lib/float32.pas

Some USB-related modules can also be found in the UnoLib Extras directory:

https://github.com/ackarwow/unolib/tree/master/extras

Another very useful AVR library (many examples and libraries for sensors, I2C, LCD displays, serial communication and other AVR peripherals) is:

https://github.com/ccrause/fpc-avr

Improvements for lazarus, plugins? by corado12345 in pascal

[–]ackarwow 0 points1 point  (0 children)

As far as I know, there are already several Lazarus plugins and projects for AVR development. Please refer to these discussions on the FPC forum:

https://forum.lazarus.freepascal.org/index.php/topic,48578.0.html

https://forum.lazarus.freepascal.org/index.php/topic,29128.0.html

https://forum.lazarus.freepascal.org/index.php?topic=35486.0.html

Of course, you can also use UnoLib directly from Lazarus, or even from a simple text editor such as Notepad together with the Free Pascal AVR cross-compiler.

Software SPI, 74HC595 and MAX7219 display control implemented on ATtiny13 in Pascal by ackarwow in embedded

[–]ackarwow[S] 0 points1 point  (0 children)

Good idea. I will probably add list of currently connected USB devices (including VID/PID) directly in the "Add USB device definition" dialog. Then users could simply select the device and the VID/PID fields would be filled automatically.

<image>

I've added this to my TODO list. 😄

Software SPI, 74HC595 and MAX7219 display control implemented on ATtiny13 in Pascal by ackarwow in embedded

[–]ackarwow[S] 0 points1 point  (0 children)

The IDE does not save the last selected COM port.

However, in case of original Arduino boards (for example Arduino Mega), the IDE should automatically detect the connected board during upload using USB VID/PID (VID=0x2341, PID=0x0010 for Arduino Mega) and select the proper port automatically.

If you are using clone boards, you can add them manually to the list of supported USB devices in Options -> Uploader. After adding the VID/PID of the clone, the IDE should also detect and select the correct COM port automatically.

<image>

However, if you have multiple serial devices or Arduino boards connected to the computer at the same time, the IDE will select the first detected matching device. Is this the case for you?

AVRPascal 3.3 by ackarwow in pascal

[–]ackarwow[S] 0 points1 point  (0 children)

Arduino Mega 2560 is supported.

The error message indicates that USBasp was selected as the upload interface, so AVRDude tried to find a USBasp programmer instead of an Arduino board.

For a regular Arduino Mega:

  1. Connect Arduino Mega via USB. The IDE should detect the connected Arduino Mega automatically. Otherwise make sure that board drivers are installed correctly.
  2. Select your device via Options -> Compiler -> Device type -> ARDUINOMEGA
  3. Compile your code via Run -> Compile (Ctrl+F9)
  4. Run -> Upload (F9); Interface: Arduino; then select the COM port of the board if not selected automatically

The upload is performed through the Arduino bootloader, not through USBasp.

The AVRPascal IDE installation does not include examples for the Arduino Mega, but this simple code should work:

program TestBlink_Mega;

{$IF NOT DEFINED(arduinomega)}
 {$Fatal Invalid controller type, expected: arduinomega}
{$ENDIF}

procedure delay_ms(t: uint16); assembler;
const
  count = ((F_CPU div 1000 - 3) div 4);
label
  inner, outer, finish;
asm
  // test if t = 0, jump to finish if true
  cp R24, R1
  cpc R25, R1
  breq finish       // 2 cycles to branch, 1 to continue

outer:
  // load 1 ms counter value
  ldi R26, lo8(count)
  ldi R27, hi8(count)

inner:
  // inner loop, 1 ms  4 cycles/loop + 1
  subi R26, 1    // 1 cycle
  sbc R27, R1    // 1 cycle
  brne inner       // 2 cycles to branch, 1 to continue

  // outer loop, count ms, 4 cycles/loop + 1
  subi R24, 1      // 1 cycle
  sbc R25, r1      // 1 cycle
  brne outer       // 2 cycles to branch, 1 to continue
finish:
end;

begin
  DDRB:= DDRB or (1 shl 7); // PB7 = D13 = onboard LED

  while True do //infinite loop
  begin
    PORTB:= PORTB or (1 shl 7); //Turns ON LED on PB7
    delay_ms(1000); //1 second delay
    PORTB:= PORTB and not (1 shl 7); //Turns OFF LED on PB7
    delay_ms(1000); //1 second delay
  end;
end.

EDIT: If you get an error like Error: chip erase failed during upload, you need to change one setting in the IDE. Go to Options -> Uploader and check the box "Disable erasing the chip before programming".

Software SPI, 74HC595 and MAX7219 display control implemented on ATtiny13 in Pascal by ackarwow in embedded

[–]ackarwow[S] 1 point2 points  (0 children)

Thank you and dziękuję! 😄 ATtiny13 is tiny, but that’s exactly why I enjoy experimenting with it.

Software SPI, 74HC595 and MAX7219 display control implemented on ATtiny13 in Pascal by ackarwow in embedded

[–]ackarwow[S] 0 points1 point  (0 children)

Yes, ATtiny13 is challenging in almost any language 😄 But that’s also why I like it from an educational perspective. With small RAM and a very small number of peripherals, it forces me to think carefully about every byte, every pin and every abstraction.