Hi,
I'm guessing I should be using BPTR to store the values, this was the simplest I could make it.
I can use some help with HSERIN command and anything else that you'd like me to try.
Yes, it's much better to receive the data via a string of @BPTRINC variables. Personally, I reserve all the single-digit variables (i.e. up to b9) for "global" or general purpose use, so would initialise BPTR to 10, but it could be set to 28 (or even higher) to leave all the regular variables for general usage. Even an 08M2 has RAM up to byte 127 (and the other M2s up to 511).
It's interesting that you're using a
T4800 baud setup (i.e. "True", "TTL" or Idle-High) which is what I would have expected, except that page 3 of the Reyax Data Sheet (linked in #3) shows an Idle-Low waveform with the specific statements :
"Keep Low before power on / off". That might be intended to prevent "Phantom Powering" and strictly there should be a
HIGH C.1 at the start of the program to set the correct Idle level. But how could the program "know" when a Power OFF might occur, to activate a
LOW C.1 ?
There seems to be quite an "overhead" with the number of (non-data) characters transmitted and received (which might suggest why the default baud rate is set as high as 115k baud). But I believe that LoRa is much more aimed at Long Range communications rather than a High Data Rate. It would be interesting to know the time gaps between characters at both 4800 baud and at a/the higher rate. If you don't have a 'Scope or Logic Analyser, then the PICaxe might be programmed to estimate the time entirely by software. I had hoped to post a simple test program to do this (and emulate HSERIN), but it's quite complicated because the SERIN command contains a (unknown variable delay) loop that waits for the arrival of the next Start Pulse(s). Thus a program cannot easily make a direct measurement between the end of a Stop Pulse and the beginning of the next Start Pulse.
________
The HSERIN command (with
M2 chips) is very different to the SERIN command. First, it cannot receive multiple bytes and it generally returns a single
Word variable so it cannot directly use the @BPTR variable, let alone @BPTRINC which may exhibit some "unexpected behaviour" (aka a Bug). Furthermore, the command doesn't (wait to) "receive" a Serial Data byte, it only examines the (on-chip) Hardware Receive Buffer which might (or might not) contain a previously-received "valid" data byte. Generally, the High Byte of the returned word is used to determine
IF the Low Byte contains a valid data Byte that the program can process.
But if not all of the potential 256 received byte values are "possible", then one of these can be used as the marker instead.
The above is a four-stage process in a Basic Program: i.e. : Pre-Load a "marker" byte/word > Use HSERIN to "Update" the Byte/Word > Check if the marker has been changed (overwritten) > If so, extract the data byte. This seems no faster than working directly with the Hardware Receive Register(s) via two PEEKSFR commands, i.e. : Read the buffer flags (byte) > Has a (new) byte been received? > If so, then Read the received byte from the buffer. And that is before we consider a potential "Bug" in the HSERIN command :
The "Base PIC's" Serial Receive Buffer can store only two Bytes and if a third arrives before the first has been Read (by the Program) then this last byte is "lost" and the hardware (intentionally) locks up until it is Reset. This is a "fatal" error because at least one byte has been lost and probably more whilst the error is detected and the relevant Hardware is reset. This obviously sets an upper limit to the rate that complete characters can be received (and processed), but much higher baud rates are still possible, provided that there are sufficiently long gaps between the characters. The problem (Bug) with the HSERIN command is that sometimes it "thinks" that an overrun has occurred, even when it hasn't.
Thus it Resets the hardware, effectively corrupting the subsequent character(s), if they follow closely after the previous one.
A few years ago I devised an alternative to HSERIN, which could reliably receive at up to 4,800 baud with a 4 MHz clock (equivalent to 38,400 baud at 32 MHz), of "concatonated" (i.e. adjoining) characters, and optionally interrupt-driven. However, looking back at that program code now, perhaps it was too "ambitious" for general purpose use, because code with an upper limit of 2,400 baud at 4 MHz (i.e. still up to 19,200 at 32 MHz) should be much easier to use and understand. I'll take another look at those programs to see if I can offer something suitable to receive High(er) baud rates (than SERIN) and to optionally measure the inter-character gap times.
Cheers, Alan.