I have tried disabling all other software timers etc. but I might try a fully isolated test tomorrow.
Unfortunately I don't think this will work because it will block the asynchronous nature of the program. As you'll see from the Metro_HAL_UsartTxStart function I posted at #20, the execution is designed to work one byte at a time. Perhaps if I rearrange some of the ST example code I could do this. I suppose I didn't expect to have to though as the library was written for this device.
As I said to @ScruffR, sending all 5 bytes / receiving all 5 bytes at once would require changing around the library that I'm using - and I may still have to do this. I'm just perplexed at what is causing this, I think it has to be something with how the Particle serial API works (not saying it's a bug) just perhaps different in timing than what the lower level HAL calls that the original library used were.
Anyway, it's 1am so I better admit defeat for another night
Thanks all for your help again, will have another go tomorrow...
returnData ought to be an int, so you can differentiate between error (-1) and data (0xFF)
the while(available()==0) effectively makes this a blocking read, which is what your abstraction layer is expecting. That should have helped.
However, if the framing gets out of sync, youāre going to stay out of sync.
Still not sure how your framing is getting out of sync in the first place.
Right before āTX Start calledā, I would add a delay (to make sure your frames arenāt back-to-back), and I would print out availableForWrite() and available(). Iām guessing that availableForWrite() is 64 and available() is non-zero.
Guys, just letting you know Iāve fixed the issue. The only change required in the end was adding
Serial4.read();
to the end of the parent function Metro_HAL_UsartTxStart (post #20) - where āDisable the peripheralā is written.
The example firmware must have dealt with the issue by discarding the extra frame when the UART is disabled at the end of each TX call. I think this only happens once and then everything is in sync and no further frame discarding is required. A little hard to explain but there you have it.
I didnāt find any other forums/example code for this device on the internet apart from the ST provided. So a few tags for anyone looking - STPM32 STPM33 STPM34 Metering.
Thanks again for everyoneās help, by the way, the Saleae logic analyzer is awesome, couldnāt have fixed it without it!
Hi, Iāve followed this thread, and I wondered if you would be willing to share the updated library that allows you to communicate with the STPM32? Iām having quite the time trying to get it working. Iām also using the Saleae, followed the pointers in the post.
Hi Matthew did you manage to get it working? Iāve just started a project and need to communicate between a particle photon and the STPM32. sample code/wiring etc. would be appreciated.