Usart_Write_Buf

Post your requests and ideas on the future development of mikroPascal.
Post Reply
Author
Message
javor.pas
Posts: 98
Joined: 16 Mar 2007 11:25
Contact:

Usart_Write_Buf

#1 Post by javor.pas » 31 Oct 2007 13:21

I think this will help and improve the USART library.
Something like

procedure Usart_Write_Buf(var Buf : array [20] of byte)

or something that sends an array of bytes, and not just one byte. It will be better than using a cycle and in its body to call Usart_Write N times.
The reason I'm posting this is that if you have an array of char or a string and fill it with some bytes and after that use Usart_Write_Text if there's a $00 byte somewhere in the string the text is sent up to the $00 byte. The procedure Usart_Write_Text stops sending when it meets a $00 byte. Other ideas are welcome to solve this problem :roll:
Also - what I saw (as a problem maybe) was on a 18F4620 with a 10MHz, using PLL, i.e. 40MHz, using the UART on 115200 calling 10 times Usart_Write sends incorrect bytes. Putting a delay of 1ms between each call solved the problem, but that's not the idea.

matrix
Posts: 203
Joined: 26 Jan 2006 07:21
Location: Bulgaria
Contact:

#2 Post by matrix » 31 Oct 2007 14:55

Look at this fragments of my network protocol and you may write what you need based on them:

Code: Select all

function Usart_Write_Byte(data_to_send : byte) : boolean;
begin
  if TXSTA.TRMT = 1 then
    begin  //send
      TXSTA.TXEN := 0;
      TXREG := data_to_send;
      TXSTA.TXEN := 1;
      Result := True;
    end
  else
    begin  //don't send
      //TXSTA.TXEN := 0;
      Result := False;
    end;
end;

Code: Select all

ns_SEND_FRAME :
      begin
        buffer_addr := @Tx_Buffer + frame_offset;  //send current byte
        if Usart_Write_Byte(buffer_addr^) then
          Inc(frame_offset);                        //prepare for next byte
        if (frame_offset >= (FRAME_LENGTH_MIN + databytes)) and
           (frame_offset <= FRAME_LENGTH_MAX - 2) then
          frame_offset := FRAME_LENGTH_MAX - 2;       //to send EOF and BCC
        if frame_offset >= FRAME_LENGTH_MAX then
          NETWORK_STATUS := ns_SEND_FRAME_END;        //goto wait for last byte to be sended
      end;

Post Reply

Return to “mikroPascal Wish List”