I’ve been trying to use Hserin in a project where quite long sequences of characters are being received and it would be difficult to process the characters and not miss any arriving characters - but I’ve been very disappointed with Hserin.
To demonstrate my problem, I’ve set up this test situation. I have an HC-12 connected to pin b.2 of an 18M2 and I’m sending it the letters “ABCDEFGHIJKLMNOP” from another HC-12. The HC-12’s are setup in FU3 mode at 4800 baud.
When I use this program running on the 18M2 at 16MHz, I get the 16 letters printed correctly.
However when I use this program (largely copied from the manual) which utilizes the hardware serial and I run the 18M2 at 32MHz, I largely get garbage.
This is an example of the garbage I receive.
The first letter always gets through and you can see some of the later characters have also got through but its different every time. I’ve tried running the 18M2 at slower frequencies but they all seem to perform similarly and only ever reliably receive the first character.
I also tried setting the sending serial port to 2 stop bits so there was a slightly bigger gap between characters but it didn’t seem to make any difference.
If I send the 16 characters from a Picaxe terminal, all the letters get through presumably because that terminal inserts sizable gaps between the sent characters.
I would have expected that Hserin would perform better than Serin and I’d hoped to be able to do a couple of other things between arriving characters.
At a baud rate of 4800, characters arrive about every 2 msecs so with Hserin having a 2 byte buffer and the 18M2 running at 32 MHz, I expected to be able to run a number of lines of code and not miss any characters.
Is Hserin really this hopeless or am I doing something silly?
To demonstrate my problem, I’ve set up this test situation. I have an HC-12 connected to pin b.2 of an 18M2 and I’m sending it the letters “ABCDEFGHIJKLMNOP” from another HC-12. The HC-12’s are setup in FU3 mode at 4800 baud.
When I use this program running on the 18M2 at 16MHz, I get the 16 letters printed correctly.
Code:
#picaxe 18m2
#no_data
setfreq m16
do
bptr=28
serin [5],b.2,T4800_16,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc
if bptr>28 then
b0=bptr-1
for bptr=28 to b0
sertxd (@bptr)
next bptr
endif
loop
However when I use this program (largely copied from the manual) which utilizes the hardware serial and I run the 18M2 at 32MHz, I largely get garbage.
Code:
#picaxe 18m2
#no_data
setfreq m32
hsersetup B4800_32, %1000 ; baud 4800 at 32MHz, no hserout
do
w1 = $FFFF ; set up a non-valid value
hserin w1 ; receive 1 byte into w1
if w1 <> $FFFF then ; if a byte was received
sertxd (w1)
endif
loop
Code:
A¨(TGHI©Š5NOý
I also tried setting the sending serial port to 2 stop bits so there was a slightly bigger gap between characters but it didn’t seem to make any difference.
If I send the 16 characters from a Picaxe terminal, all the letters get through presumably because that terminal inserts sizable gaps between the sent characters.
I would have expected that Hserin would perform better than Serin and I’d hoped to be able to do a couple of other things between arriving characters.
At a baud rate of 4800, characters arrive about every 2 msecs so with Hserin having a 2 byte buffer and the 18M2 running at 32 MHz, I expected to be able to run a number of lines of code and not miss any characters.
Is Hserin really this hopeless or am I doing something silly?