SEROUT2 Byte Array In HEX Format



THE BOOK of DT's INTERRUPTS is an organization of interrupt service routines and other works written by Darrel Taylor, RIP.

Interrupt routines are arranged per Darrel's original list. Darrel Taylor's Instant Interrupts are an extension of the work of Tim Box whom in October of 2002 wrote INT_CTRL.pbp

Many of the forum members felt this is a long overdue project.

THE BOOK of DT's INTERRUPTS
will be a valuable resource and a tribute to Darrel Taylor the "Fanatical Contributor".

THE BOOK of DT's INTERRUPTS is located at http://dt.picbasic.co.uk/

+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637

    Default SEROUT2 Byte Array In HEX Format

    Hi, I have an array of 32 bytes. I need to send it to a Bluetooth module in HEX format. The only way I have been able to do it is,

    Code:
        FOR I = 0 TO 31
            SEROUT2 PORTC.1,84,[HEX2 SquaresArray[I]] 
        NEXT I
        SEROUT2 PORTC.1,84,[","]
    I get many missing packages using this code. I get around 1 out of 8 missing packages. If I try the following code, it fails. I get a "Bad expression" error.

    Code:
    SEROUT2 PORTC.1,84,[hex2 STR SquaresArray\32, ","]
    Any ideas on how I can do this? Thanks.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  2. #2
    Join Date
    Apr 2014
    Location
    Northeast
    Posts
    498


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    You are probably overwriting the TXREG before it's finished sending the previous packet. You didn't mention which PIC you're using, so refer to the appropriate data sheet for the exact Register naming, but something like this:

    Code:
    FOR I = 0 TO 31
            WHILE TXIF = 0
             WEND
            SEROUT2 PORTC.1,84,[HEX2 SquaresArray[I]]
         NEXT I
        SEROUT2 PORTC.1,84,[","]

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    No, that can't be it.
    SEROUT and SEROUT2 are bitbanged routines so they don't use the (E)USART and therefor not the TXREG. HSEROUT does use the (E)USART but its smart enough to pace itself as to not overwrite TXREG.

    The receive buffer in the Bluetooth module on the other hand...what if you split the string and send it two chunks with some delay in between?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,118


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    What is a package.?
    What else is sent ?
    Are interrupts involved ?
    My best guess is that the trouble is in the code not shown and that snippets are a yet again a pointless waste of time and effort
    Warning I'm not a teacher

  5. #5
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    Quote Originally Posted by richard View Post
    What is a package.?
    What else is sent ?
    Are interrupts involved ?
    My best guess is that the trouble is in the code not shown and that snippets are a yet again a pointless waste of time and effort
    The data package looks like this 432551346666666600000000000000000000000000000000CC CCCCCCA98BB79A,. This is just 32 bytes in HEX format followed by a comma. The comma is just to delimit the packages. There are not interrupts involved. I'm trying to use the following code, but it doesn't work

    Code:
    SEROUT2 PORTC.1,84,[hex2 STR SquaresArray\32, ","]
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  6. #6
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    Quote Originally Posted by HenrikOlsson View Post
    The receive buffer in the Bluetooth module on the other hand...what if you split the string and send it two chunks with some delay in between?
    Hmm, how is that going to help? What amount of delay should I use?
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    Since you don't say which Bluetooth module you're using I can't tell what size the buffer is but if you keep feeding that buffer faster than the module is able to send the data out over the air it will eventually overflow and things happens as a result. As a test try a 1 second delay, if it seems to work you've probably found the cause and can start to think about what to do about it.

    If the Bluetooth module have flow control pins it might be a good option.

    I'm not saying this IS the issue but it's something I'd try.

  8. #8
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,274


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    This string is 65 bytes long and has a space after the CC.

    Is that correct?

    Ioannis

  9. #9
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    Quote Originally Posted by HenrikOlsson View Post
    Since you don't say which Bluetooth module you're using I can't tell what size the buffer is but if you keep feeding that buffer faster than the module is able to send the data out over the air it will eventually overflow and things happens as a result. As a test try a 1 second delay, if it seems to work you've probably found the cause and can start to think about what to do about it.

    If the Bluetooth module have flow control pins it might be a good option.

    I'm not saying this IS the issue but it's something I'd try.

    I'm using an HC-05 module to send data to a PC or cellphone.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  10. #10
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    Quote Originally Posted by Ioannis View Post
    This string is 65 bytes long and has a space after the CC.

    Is that correct?

    Ioannis
    No, that space shouldn't be there. There are 64 characters followed by a comma.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  11. #11
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    I sent these 65 bytes every 100 mS. The data rate of the HC-05 seems to be high,

    It uses the 2.45GHz frequency band. The transfer rate of the data can vary up to 1Mbps and is in range of 10 meters.
    The HC-05 module can be operated within 4-6V of power supply. It supports baud rate of 9600, 19200, 38400, 57600, etc.
    https://www.geeksforgeeks.org/all-ab...7600%2C%20etc.

    I think that the lost packages issue has to do with the way I'm sending the data,

    Code:
        FOR I = 0 TO 31
            SEROUT2 PORTC.1,84,[HEX2 SquaresArray[I]] 
        NEXT I
        SEROUT2 PORTC.1,84,[","]
    Do you see anything wrong with this code?
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,421


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    No, I don't see anything wrong with that code. Have you tried increasing the delay between packages?

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,274


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    I would also check with a terminal on a PC what the serial port of the PIC sends out.

    Maybe there is an electrical problem with the port.

    I suppose you are using without an RS232 driver since the 84 implies a true TTL level.

    For a PC sniffing you need a driver though.

    Ioannis

  14. #14
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    637


    Did you find this post helpful? Yes | No

    Default Re: SEROUT2 Byte Array In HEX Format

    Thanks, I will try both of your suggestions.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

Similar Threads

  1. Byte to Hex
    By enigma in forum General
    Replies: 7
    Last Post: - 11th July 2017, 14:39
  2. Struggling again with SEROUT2 and numbers format
    By Fanias in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 12th April 2014, 05:42
  3. Serial Byte Format
    By mbruno in forum Serial
    Replies: 2
    Last Post: - 7th February 2008, 14:27
  4. Need help converting to ASCII Hex format
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th August 2007, 19:14
  5. Word array behaving like byte array.... wierd
    By forgie in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 2nd August 2005, 15:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts