Forum > Embedded - AVR

Embedded avr writeln to serial port

(1/2) > >>

diego bertotti:
hi

i try to write to avr serial port using writeln, but it dont work.

in fpc documentation say about write funciton, if it used without specify output file, then stdout will be used.

I think stdout, in avr embedded, must be....serial port!, but dont work.

i can compile, have no errors!

¿whats wrong?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---s:= 'Hello World';Write(s); 
and assembles was:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---#  CPU AVR5# [260] s:= 'Hello World';        ldi     r24,lo8(U_sPsENCODER_ss_S)        ldi     r25,hi8(U_sPsENCODER_ss_S)        ldi     r20,lo8(_sENCODERs_Ld2)        ldi     r21,hi8(_sENCODERs_Ld2)        ldi     r22,-1        mov     r23,r1        call    fpc_shortstr_to_shortstr# [261] Write( s);        call    fpc_get_output        movw    r2,r24        ldi     r18,lo8(U_sPsENCODER_ss_S)        ldi     r19,hi8(U_sPsENCODER_ss_S)        movw    r20,r2        mov     r22,r1        mov     r23,r1        mov     r24,r1        mov     r25,r1        call    fpc_write_text_shortstr        call    fpc_iocheck        movw    r24,r2        call    fpc_write_end        call    fpc_iocheck  
who konws !!!

where can i found documentation specific about avr embedded?

thanks

kupferstecher:

--- Quote from: diego bertotti on June 10, 2019, 01:50:38 am ---I think stdout, in avr embedded, must be....serial port!, but dont work.
--- End quote ---

I don't think that could work like that. The compiler would have to set up the UART, which is different for different devices. Also which UART settings should be used... occupying port -pins...

Perhaps you can redirect the StdOut and forward it to the serial port.


--- Quote ---where can i found documentation specific about avr embedded?
--- End quote ---
There's not too much documentation.

You probably already found that:
http://wiki.freepascal.org/AVR_Programming

A tutorial in German:
http://wiki.freepascal.org/AVR_Embedded_Tutorial/de

Project wizard:
https://github.com/kupferstecher/LazPackageEmbeddedAVR

Thaddy:
The syntax should probably be something like:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---write(PortID,'Hello, World'); since a single AVR can address more than one port.I believe PortID can be the actual address, but I have no AVR or docs available ATM.

kupferstecher:
I just tried to redirect the StdOut. The following works for me on STM32, but I believe the code works also for AVR.

usage:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses  uStdOutRedirect;begin   StdOutRedirectInit;   write('Hallo');end;
Unit uStdOutRedirect:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit uStdOutRedirect; {$mode objfpc} INTERFACE   Procedure StdOutRedirectInit;  IMPLEMENTATION Uses  consoleio, uUART; function WriteToUART(ACh: char; AUserData: pointer): boolean; forward;function EmptyWrite(ACh: char; AUserData: pointer): boolean; forward;function EmptyRead(var ACh: char; AUserData: pointer): boolean; forward;  Procedure StdOutRedirectInit;begin  OpenIO(StdOut,@WriteToUART,@EmptyRead,fmOutput,nil);   //OpenIO(Input, @EmptyWrite, @EmptyRead, fmInput, nil);  //OpenIO(Output, @EmptyWrite, @EmptyRead, fmOutput, nil);  //OpenIO(ErrOutput, @EmptyWrite, @EmptyRead, fmOutput, nil);  //OpenIO(StdOut, @EmptyWrite, @EmptyRead, fmOutput, nil);  //OpenIO(StdErr, @EmptyWrite, @EmptyRead, fmOutput, nil);end; function WriteToUART(ACh: char; AUserData: pointer): boolean;  begin    UART.SendChar(ACh);    Result:=true;  end; function EmptyWrite(ACh: char; AUserData: pointer): boolean;begin Result:=true; end; function EmptyRead(var ACh: char; AUserData: pointer): boolean;begin    Result:=true;    ACh:=#0;end; end.
The UART has to be set up seperately, in my example the data is sent with the UART.SendChar procedure.

Thaddy:
Note that on AVR it is a good idea to compile in {$I-} state.

Navigation

[0] Message Index

[#] Next page

Go to full version