November 07, 2024, 05:45:57 PM

PIC32-HMZ144 - UART code

Started by Jorgen, February 17, 2021, 11:23:41 AM

Previous topic - Next topic

Jorgen

I have used MPLABX and Harmony 3 to create a simple Hello World project, but nothing comes out of the UART. The UART FIFO gets filled up, but it never transmits a single byte.
I would appreciate a code example as simple as the Blink example i.e. all code in the main.c file for example, but using one UART to transmit data.
Does anyone have such a code that is tested and works on a PIC32-HMZ144 board?
The Blink example runs as it is supposed to. I have compiled it and loaded it down on the board using an ICD4, but I can't make the UART work.

kyrk.5

Normal UART or USB? I have used USB in the past. But not sure if that project is still compiling. It was a port from GRBL.

Can you show your code? Maybe something is missing. Did you configured the interrupt and the port pins too?

Jorgen

Dear kyrk.5,

Thank you for replying to my cry for help.
I have de-installed all Microchip MPLABX versions, all compilers, all plugins and cleaned all files holding configurations from one version to the next of MPLABX.
After that I downloaded and installed the latest version of MPLABX, XC8-, XC16- and XC32-compilers, MCC and HARMONY 3.
Then, I followed Microchip TB3259 to create and run a Hello World project using a UART. I modified the PPS settings to the pins on my PIC32-HMZ144.
The project compiled and loaded as it should, but the UART was just filling its 8 byte deep FIFO buffer. Nothing came out.
Then I changed to the Blink project of OLIMEX. That compiled, loaded and the LED was blinking. Fine.
Then I step by step transferred code from the Hello World to the Blink, and finally the UART is running, but I still do not know exactly why. There are some differences in the configuration bits, but when I read the PIC32MZ Family Reference, these differences should not matter.
In summary, my UART code is running. There is no need to configure the port pins for input or output. The UART does that automatically. Setting PPS is necessary.
I have also tried the OLIMEX provided Demo project, but that is by far too complicated to be useful for this kind of troubleshooting. I wish OLIMEX had some projects like Blink, but one for UART, one for SPI, one for timer etc. It would be most helpful. 

kyrk.5

"UART was just filling its 8 byte deep FIFO buffer"
Hmm. Normally it should start sending the bytes if the module is enabled and configured. Maybe it is not enabled. So the fifo is filled but nobody is consuming the bytes. Another problem is that it is enabled, it will send the bytes, but the interrupt is not coming to refill the fifo. But there you just see only the first 1 or 4 or whatever deep the fifo is bytes. Which is here not the case.

You can try to compare the working and not working projects. Just before you fill the very first byte of the fifo, you compare all of the registers. Or maybe that one, where you think it would be important. Like ISR, UART. Sadly Microchip MPLAB X is not the best tool for debugging (ok I am honest, I hate it so much that I hacked MPLAB 8 to support PICs that are even not present there so that I have not to use MPLAB X), so comparing a register is not a thankfully job. But this can help some times to pinpoint out the rootcase of the problem.