Lazarus

Programming => Embedded => Operating Systems => Embedded - AVR => Topic started by: pascalbythree on December 04, 2021, 12:41:03 pm

Title: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 04, 2021, 12:41:03 pm
I successfully installed FPC-AVR and dit compile some example code to blink the LED on my AVR.

PROBLEM: The .HEX files are created but the LED does nog blink...

AnyBody help?

Greets, Wouter

PS: Does anybody know weither this is a 'FAKE' licence ?
Title: Re: FPC-AVR hex file does not make LED blink
Post by: ccrause on December 04, 2021, 01:28:11 pm
There are many potential points of failure, so to help identify the problem here are some questions/request for information:
If the above doesn't identify something, the next step would be a photo or diagram of your hardware setup.

PS: Which license are you referring to?
Title: Re: FPC-AVR hex file does not make LED blink
Post by: d.ioannidis on December 04, 2021, 03:48:58 pm
Hi,

  adding to ccrauce's very reasonable reply, could you please post the content of the .elf file ?

  ( If the .hex file is created most probably there will be also an .elf file )

regards,
Title: Re: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 04, 2021, 03:57:35 pm
So you are mister ccrause from

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

himself?

Can you please awnser again weither the source code from fpc-avr is finished far enoug to really run it on the AVR chip? / or not in final stage?

elf file:

Title: Re: FPC-AVR hex file does not make LED blink
Post by: d.ioannidis on December 04, 2021, 05:04:36 pm
Hi,

  why don't you give some more information as ccrause asked ?

PS: ( it seems that you're using ATMEGA16A mcu correct ? )

PS2: ( And also, It seems that you configured the PIND7 as an Input Pin. Is the led connected to Vcc or to Ground ? This is all I can do if you don't provide any more information .)

regards,

Title: Re: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 04, 2021, 05:48:41 pm
Code: Pascal  [Select][+][-]
  1. program blink;
  2.  
  3. uses delay;
  4.  
  5. var
  6. PuertoD: bitpacked array [0..7] of boolean absolute PORTD;
  7. PinesD: bitpacked array [0..7] of boolean absolute PinD;  
  8.  
  9. begin
  10.  
  11. repeat
  12.  PuertoD[7]:= true;
  13.  PinesD[7]:= True;
  14.  delay_ms(255);
  15.  
  16.  PuertoD[7]:= false;
  17.  PinesD[7]:= false;
  18.  delay_ms(255);
  19. until 1=2;
  20.  
  21. end.
  22.  
  23.  

This is the code i use. I can get it to work myself if i spend lots of time on it.
so this is somehow ever going to work? Like more people on this forum have ?

Title: Re: FPC-AVR hex file does not make LED blink
Post by: ccrause on December 04, 2021, 06:03:51 pm
So you are mister ccrause from

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

himself?

Yes.
Quote

Can you please awnser again weither the source code from fpc-avr is finished far enoug to really run it on the AVR chip? / or not in final stage?
Alll examples were tested on hardware. Mostly on FPC trunk/main.
Atmega328p & attiny85 and similar families should also compile with FPC 3.2.2
Title: Re: FPC-AVR hex file does not make LED blink
Post by: d.ioannidis on December 04, 2021, 06:05:15 pm
Hi,

  take a look at this AVR Embedded Tutorial - Simple GPIO on and off output (https://wiki.freepascal.org/AVR_Embedded_Tutorial_-_Simple_GPIO_on_and_off_output#Blink_example) and this ATmega16A_Datasheet 12.2.1 Configuring the Pin (https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-8154-8-bit-AVR-ATmega16A_Datasheet.pdf#G1.1054287) .

Try this code :

Code: Pascal  [Select][+][-]
  1. program blink;
  2.  
  3. uses delay;
  4.  
  5. var
  6. PuertoD: bitpacked array [0..7] of boolean absolute PORTD;
  7. //PinesD: bitpacked array [0..7] of boolean absolute PinD;  
  8.  
  9. begin
  10.  
  11. DDRD := DDRD or (1 shl 7);
  12.  
  13. repeat
  14.  PuertoD[7]:= true;
  15. // PinesD[7]:= True;
  16.  delay_ms(255);
  17.  
  18.  PuertoD[7]:= false;
  19. // PinesD[7]:= false;
  20.  delay_ms(255);
  21. until 1=2;
  22.  
  23. end.

EDIT: Add atmega16a datasheet .

regards,
Title: Re: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 05, 2021, 10:36:19 am
Thank you very much everyone! it got to work. Now i am continuing for the UART1 example!

Incase problems you will hear from me !.
Title: Re: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 05, 2021, 01:39:17 pm
And allready, does anyone have example code for FPC-AVR for the UART, that compiles?

 ;D
Title: Re: FPC-AVR hex file does not make LED blink
Post by: d.ioannidis on December 05, 2021, 03:05:08 pm
Hi,

And allready, does anyone have example code for FPC-AVR for the UART, that compiles?

 ;D

  in the wiki exists a section regarding AVR Embedded (https://wiki.freepascal.org/AVR_Embedded_Tutorials) programming and more.

  Here it is a UART Example (https://wiki.freepascal.org/AVR_Embedded_Tutorial_-_UART).

regards,
 
Title: Re: FPC-AVR hex file does not make LED blink
Post by: ccrause on December 06, 2021, 09:18:23 am
Can you please awnser again weither the source code from fpc-avr is finished far enoug to really run it on the AVR chip? / or not in final stage?
Alll examples were tested on hardware. Mostly on FPC trunk/main.
Atmega328p & attiny85 and similar families should also compile with FPC 3.2.2
Just remembered, everything except the blinktiny15 example were tested on hardware  :-X.  I don't have an attiny15 controller, but wanted to test the code generation capability of the compiler for a controller with no RAM.
Title: Re: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 06, 2021, 04:42:39 pm
Mzz.. Only seems to compile for the Atmega328P

Anybody got more UART code for the Atmega16A ?

Greets W.

BTW does FPC-AVR suppport PWM signals or do i have to loop myself?
Title: Re: FPC-AVR hex file does not make LED blink
Post by: ccrause on December 06, 2021, 06:11:24 pm
Mzz.. Only seems to compile for the Atmega328P

Anybody got more UART code for the Atmega16A ?
There isn't a uniform nomenclature for the different peripherals across different controller families.  This means one has to confirm the register names, capabilities and bit settings for each controller type.  When using a hardware abstraction layer library (e.g. Arduino), these details are hidden inside the libraries.  FPC doesn't supply a HAL, only the controller specific definitions, so the user needs to take care of these differences.

For example the differences in nomenclature between atmega328P and atmega16A timer registers:
Atmega328PAtmega16A
UDR0UDR
UCSRA0UCSRA
UCSRB0UCSRB
UCSRC0UCSRC
UBRR0LUBRRL
UBRR0HUBRRH

Also the different controllers may have different capabilities and bit fields in the registers may be in different positions, so always refer to the datasheets for the specific controller to ensure the correct settings for that particular controller model is used.  An example of this is that the 328P has a master SPI mode for the USART, while the 16A doesn't.  This is important to know, because it means that bit 7 of the UCSRCx register has a different meaning for these two controllers, while bits 6 - 0 have identical meaning.

Quote
BTW does FPC-AVR suppport PWM signals or do i have to loop myself?
FPC doesn't have a a HAL library, so one has to either use and configure a hardware timer for PWM mode, or write your own software bitbang PWM code loop.
Title: Re: FPC-AVR hex file does not make LED blink
Post by: pascalbythree on December 14, 2021, 03:05:01 pm
Code: Pascal  [Select][+][-]
  1. unit i2c;
  2.  
  3. interface
  4.  
  5. type
  6.   { TI2CMaster }
  7.   TI2CMaster = object
  8.     retVal: byte;
  9.     procedure init(bitRate: byte);
  10.     // Address should be left adjusted 7-bit value
  11.     function start(address: byte; readTransaction: boolean): boolean;
  12.     function readByte(out data: byte; ack: boolean): boolean;
  13.     function writeByte(data: byte): boolean;
  14.     function stop: boolean;
  15.   end;
Code: Pascal  [Select][+][-]
  1. program WVW_BURN;
  2.        
  3. uses
  4.   uart, i2c, delay;
  5.  
  6. var
  7.   i2c_master: TI2CMaster;
  8.   i,x: byte;
  9.   c: char;
  10.   counter : byte;
  11.   S: String;
  12.  
  13. begin
  14.    S := 'I2C MASTER SLAVE';
  15.    
  16.    // Initialize UART that is interrupt controlled
  17.    UART_Init1(9600,true);
  18.    uart_transmit('WVW UART TEST STRING  ');
  19.      
  20.      
  21.   i2c_master.init(I2C_100kHz);
  22.   i2c_master.start(0, false);  
  23.            
  24.   Counter := 0;
  25.   repeat
  26.        Counter := Counter + 1;
  27.        if counter = 100 then counter := 1;
  28.        
  29.        uart_transmit('Inside MAIN loop SUPERS TRING 2 '#10#13);
  30.                        
  31.          
  32.        i2c_master.ReadByte(i,true);          
  33.                    
  34.        uart_transmit(i); uart_transmit(#10#13);      
  35.        
  36.        delay_ms(55);
  37.              
  38.   until 1=2;
  39.        i2c_master.stop;        
  40.  
  41. end.



Hey www.freepascal.org crew!
Can somebody advice me the right values of

i2c_master.start(0, false);

and if it has to be placed in the main program loop or just like above ?
Greets, Wouter van Wegen

PS: I am trying to I2C from my RPI3 on freepascal to my AVR on freepascal FPC-AVR
Title: Re: FPC-AVR hex file does not make LED blink
Post by: ccrause on December 14, 2021, 06:47:19 pm
Hey www.freepascal.org crew!
Can somebody advice me the right values of

i2c_master.start(0, false);

and if it has to be placed in the main program loop or just like above ?
Greets, Wouter van Wegen

Typically you should use the address of the I2C device you want to communicate with. Using address 0 is the general call address (https://www.i2c-bus.org/addressing/general-call-address/), which may or may not be what you are trying to do.

There is a simple example to show how to read time from a DS1307 (https://github.com/ccrause/fpc-avr/blob/master/src/examples/i2c/i2ctest.pp#L94).

Quote
PS: I am trying to I2C from my RPI3 on freepascal to my AVR on freepascal FPC-AVR
To do this one side needs to be the I2C master and the other side the slave.  The I2C library you are referring to is for the AVR acting as the I2C master.  If you want to use this, then the AVR needs to read data from the RPi, so the RPi needs to be running an I2C slave app.  There are quite a number of discussions on this topic if you search for Raspberry Pi as I2C slave.

But it will be easier in my opinion if you get a cheap I2C device such as a DS1307 real time clock, there are many examples on the internet on how to read this via I2C.
TinyPortal © 2005-2018