[SOLVED] Potential UART/Serial Conflict?

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 :sleepy:
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.

I meant for the test, to get an unobstructed view of the timing.
After that you know what your up against and then you can go async bit by bit.

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!

2 Likes

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.

Any chance you could share?

Many thanks!

Matthew

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.

cheers,

Hooman

Hi @G65434_2 can you please you code snippet which is working.