Recent

Author Topic: FPC-AVR hex file does not make LED blink  (Read 12824 times)

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
FPC-AVR hex file does not make LED blink
« 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 ?
« Last Edit: December 04, 2021, 12:43:37 pm by pascalbythree »

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: FPC-AVR hex file does not make LED blink
« Reply #1 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:
  • What compiler version are you using?
  • Which controller or board are you using?
  • Show your code
  • Does your setup work with any other test code, e.g. an Arduino blink example?
  • Show fuse settings of controller (if using avrdude: avrdude <your settings for controller, programmer and port> -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h
  • Show avrdude output when programming controller, in case something goes wrong in this step.
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?

d.ioannidis

  • Full Member
  • ***
  • Posts: 221
    • Nephelae
Re: FPC-AVR hex file does not make LED blink
« Reply #2 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,

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: FPC-AVR hex file does not make LED blink
« Reply #3 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:


d.ioannidis

  • Full Member
  • ***
  • Posts: 221
    • Nephelae
Re: FPC-AVR hex file does not make LED blink
« Reply #4 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,

« Last Edit: December 04, 2021, 05:20:04 pm by Dimitrios Chr. Ioannidis »

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: FPC-AVR hex file does not make LED blink
« Reply #5 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 ?


ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: FPC-AVR hex file does not make LED blink
« Reply #6 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

d.ioannidis

  • Full Member
  • ***
  • Posts: 221
    • Nephelae
Re: FPC-AVR hex file does not make LED blink
« Reply #7 on: December 04, 2021, 06:05:15 pm »
Hi,

  take a look at this AVR Embedded Tutorial - Simple GPIO on and off output and this ATmega16A_Datasheet 12.2.1 Configuring the Pin .

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,
« Last Edit: December 04, 2021, 06:41:35 pm by Dimitrios Chr. Ioannidis »

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: FPC-AVR hex file does not make LED blink
« Reply #8 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 !.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: FPC-AVR hex file does not make LED blink
« Reply #9 on: December 05, 2021, 01:39:17 pm »
And allready, does anyone have example code for FPC-AVR for the UART, that compiles?

 ;D

d.ioannidis

  • Full Member
  • ***
  • Posts: 221
    • Nephelae
Re: FPC-AVR hex file does not make LED blink
« Reply #10 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 programming and more.

  Here it is a UART Example.

regards,
 

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: FPC-AVR hex file does not make LED blink
« Reply #11 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.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: FPC-AVR hex file does not make LED blink
« Reply #12 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?
« Last Edit: December 06, 2021, 05:17:47 pm by pascalbythree »

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: FPC-AVR hex file does not make LED blink
« Reply #13 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.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: FPC-AVR hex file does not make LED blink
« Reply #14 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

 

TinyPortal © 2005-2018