PDA

View Full Version : SEROUT2 Byte Array In HEX Format



rsocor01
- 30th April 2022, 22:02
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,



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.



SEROUT2 PORTC.1,84,[hex2 STR SquaresArray\32, ","]


Any ideas on how I can do this? Thanks.

mpgmike
- 1st May 2022, 09:51
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:



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

HenrikOlsson
- 1st May 2022, 11:56
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?

richard
- 1st May 2022, 14:00
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

rsocor01
- 1st May 2022, 21:47
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



SEROUT2 PORTC.1,84,[hex2 STR SquaresArray\32, ","]

rsocor01
- 1st May 2022, 21:49
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?

HenrikOlsson
- 2nd May 2022, 05:47
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.

Ioannis
- 2nd May 2022, 16:26
This string is 65 bytes long and has a space after the CC.

Is that correct?

Ioannis

rsocor01
- 3rd May 2022, 01:08
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.

rsocor01
- 3rd May 2022, 01:11
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.

rsocor01
- 5th May 2022, 03:03
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-about-hc-05-bluetooth-module-connection-with-android/#:~:text=It%20uses%20the%202.45GHz,%2C%2038400%2C% 2057600%2C%20etc.

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



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?

HenrikOlsson
- 5th May 2022, 05:38
No, I don't see anything wrong with that code. Have you tried increasing the delay between packages?

Ioannis
- 5th May 2022, 08:08
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

rsocor01
- 5th May 2022, 15:04
Thanks, I will try both of your suggestions.