Recent

Author Topic: default pin settings, atmega328p, ds18b20 example code FPC-AVR  (Read 349 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 292
Hey to all my FPC people,

https://github.com/ccrause/fpc-avr/blob/master/src/examples/ds18b20/onewire_config.inc

Code: Pascal  [Select][+][-]
  1.   // Define the port to which the oneWire data pin is connected
  2.   {$define dataPORT := PORTB}
  3.   {$define dataDDR  := DDRB}
  4.   {$define dataPINs  := PINB}
  5.   // Define the pin connected to the oneWire data pin
  6.   {$define oneWirePin  := 0}
  7.  


for the Atmega328P, just use this default pin settings called, PB0 ?
Or must ik change it for example to INT0/INT1 ?

Greets, PascalBythree

ccrause

  • Hero Member
  • *****
  • Posts: 1117
Re: default pin settings, atmega328p, ds18b20 example code FPC-AVR
« Reply #1 on: April 18, 2026, 11:45:37 am »
The name of the pin is not important, the pin number is.  The oneWirePin definition is used for example here. The code:
Code: Pascal  [Select][+][-]
  1. dataPort := dataPort and not(1 shl oneWirePin);
is interpreted by the compiler (after substitution of the macro definitions) as:
Code: Pascal  [Select][+][-]
  1. PORTB := PORTB and not(1 shl 0);

Note that in FPC 3.2.2 there are no named constants declared for pins (e.g. PB0 for pin 0 on portB).  This is in my opinion unfortunate, since pin names are used in the hardware documentation.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 292
Re: default pin settings, atmega328p, ds18b20 example code FPC-AVR
« Reply #2 on: April 23, 2026, 02:36:32 pm »
Code: Pascal  [Select][+][-]
  1.   // Define the port to which the oneWire data pin is connected
  2.   {$define dataPORT := PORTB}
  3.   {$define dataDDR  := DDRB}
  4.   {$define dataPINs  := PINB}
  5.   // Define the pin connected to the oneWire data pin
  6.   {$define oneWirePin  := 15}

Can not get it to run i am afraid.

Can someone please type over the complete .inc file for me on PB1 ? using the ATMEGA328P at 12mhz, thanks...

Thaddy

  • Hero Member
  • *****
  • Posts: 19156
  • Glad to be alive.
Re: default pin settings, atmega328p, ds18b20 example code FPC-AVR
« Reply #3 on: April 23, 2026, 03:35:43 pm »
What is possibly missing is
Code: Pascal  [Select][+][-]
  1. //first line
  2. {$MACRO ON}
Otherwise the defines will NOT work even if they are correct.
I assume they are correct and you used the datasheet to verify?

Just to make sure: it may be case sensitive for some devices, especially when virtual drivers are involved, so make sure the casing is correct. (Never ran into that, though)

https://www.freepascal.org/docs-html/prog/progse5.html

And yes, a single port mapping is also an expression (of 1) thus macro's should be enabled, which is not the default.
« Last Edit: April 23, 2026, 03:53:05 pm by Thaddy »
objects are fine constructs. You can even initialize them with constructors.

ccrause

  • Hero Member
  • *****
  • Posts: 1117
Re: default pin settings, atmega328p, ds18b20 example code FPC-AVR
« Reply #4 on: April 23, 2026, 06:51:10 pm »
Code: Pascal  [Select][+][-]
  1.   // Define the pin connected to the oneWire data pin
  2.   {$define oneWirePin  := 15}
This is wrong, the pin number must be in the range 0 to 7.

Which pin are you using for one wire?

Edit: I see you mentioned PB1.  Then change the pin number as follows:
Code: Pascal  [Select][+][-]
  1.   // Define the pin connected to the oneWire data pin
  2.   {$define oneWirePin  := 1}
« Last Edit: April 24, 2026, 07:17:10 am by ccrause »

 

TinyPortal © 2005-2018