I have been whining for quite sometime (mostly in private) about not being able to send multiple bytes of data with "Hsersend". While not a perfect solution this method is relatively simple and works quite well. Here's what I did.
Create an array (buffer) to hold the bytes to be sent
Create a subroutine to send the data loaded into the buffer
Test
This routine makes hsersend a little less cumbersome when sending data packets of various lengths
The main applications would be to send raw data from a microcontroller to another device. The other device could be another micrcontroller, an RF module, a serial LCD Display, etc.
I used an Arduino Uno R3, but any other GCB supported microcontroller with sufficient memory and an USART will work with the same code. If the chip does not have a USART, this method could be adapted for use with software serial "Sersend"
Here is the working code:
#chip mega328p, 16#define USART_BAUD_RATE 9600#define USART_BLOCKING#define USART_TX_BLOCKING#define CR 13 '// Carriage return#define LF 10 '// Line FeedDIMHserData(64)'// Max 64 bytes (Reduce or increase size as needed)DIMVar1,Var2,Var3,Var4asByte'// For testingDIMChksumasByteWait200ms' stabilize'Starting ValuesVar1=48Var2=56Var3=59var4=87Chksum=Var1+Var2+var3+var4'--------- Main Routine Begins Here ------------- Do'*** Send Test Packet 1 (5 Bytes) ***HserData=Var1,Var2,Var3,Var4,Chksum:HserSendData'*** Send Test Packet 2 ( 14 Bytes) ***HserData=14,8,19,88,56,22,12,99,74,13,59,34,101,172:HserSendDataVar1++'// Increment all by 1Var2++Var3++Var4++Chksum=Var1+Var2+Var3+Var4'// Re-Calculate ChksumWait200ms'// Between PacketsLoop'========== Subs Below ========================SubHserSendDataForii=1toHserData(0)'// number of bytes to sendHserSendHserData(ii)NextEndSub
Last edit: William Roth 2017-03-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have been whining for quite sometime (mostly in private) about not being able to send multiple bytes of data with "Hsersend". While not a perfect solution this method is relatively simple and works quite well. Here's what I did.
This routine makes hsersend a little less cumbersome when sending data packets of various lengths
The main applications would be to send raw data from a microcontroller to another device. The other device could be another micrcontroller, an RF module, a serial LCD Display, etc.
I used an Arduino Uno R3, but any other GCB supported microcontroller with sufficient memory and an USART will work with the same code. If the chip does not have a USART, this method could be adapted for use with software serial "Sersend"
Here is the working code:
Last edit: William Roth 2017-03-12
Very useful!
Thank you!!