Serial monitor on Mplab for pic microcontroller

Argonexx

Joined Apr 9, 2022
1
Hi guys,

I used to use Arduino, and it's very helpful to use the serial monitor for debugging.

Actually I'm using Mplab (for pic microcontroller). Does any one know if there is a similar tool on Mplab to a serial monitor, that can be used for debugging please ?

Thanks
If you can get the UART module in your PIC to work you can just talk to PuTTY using a serial adapter (if you have one). If you dont have one I like the FTDI's like this https://www.hobbypcb.com/index.php/products/accessories/ftdi232
 

Thread Starter

guetkar

Joined Mar 9, 2022
45
Thank you,
If I got what you said, is that using the MAX232, I can interface the uC with the PC (using an RS232 for example), to read the UART sent from the uC. For that I need the terminal (such as Putty).
By sending data (on UART) from the uC, I'm supposed to recieve them on the terminal.
 

Jon Chandler

Joined Jun 12, 2008
1,652
If you use a PICkit 2 for loading the micro and the stand-alone GUI program, there's a neat trick to use the GUI's UART tool.

Set up a software UART in your code, with the receive and transmit pins corresponding to the ICSP pins used for loading code (I forget how ICSP clock and date match up to receive and transmit in the GUI UART tool but define the pins as needed), and tell the Mico software UART to invert the signals (as there's no MAX232 chip involved).

Then it's an easy matter to load code using the PICkit 2, then active the UART tool and see your messages from the micro.

I can provide details if desired. There are 2 options for updated PICkit 2 GUIs. One has been mentioned in another thread here recenting, which is a paid app. Another one I've seen recently is another forum is supposed to be very good, and it's free. If there's interest, I'll dig them out and post links.
 

nsaspook

Joined Aug 27, 2009
16,503
Many of the new curiosity boards come with the PKOB4 for programming/debug/serial comms via USB.

https://www.microchip.com/en-us/development-tool/dm182028

  • On-board debugger
    • Board identification in Microchip MPLAB X
    • One green power and status LED
    • Programming and debugging
    • Virtual COM port (CDC)
    • One logic analyzer channel (DGI GPIO)
https://ww1.microchip.com/downloads/en/DeviceDoc/PIC18F47K42_Curiosity_Nano_Schematics.pdf
https://ww1.microchip.com/downloads/en/DeviceDoc/50002899B.pdf
3.1.1 Virtual COM Port (CDC)
The Virtual COM port (CDC) is a general purpose serial bridge between a host PC and a target device.
3.1.1.1 Overview
The on-board debugger implements a composite USB device that includes a standard Communications Device Class
(CDC) interface, which appears on the host as a Virtual COM port. The CDC can be used to stream arbitrary data in
both directions between the host and the target: All characters sent from the host will be sent through a UART on the
CDC TX pin, and UART characters sent into the CDC RX pin will be sent back to the host through the Virtual COM
port.
On Windows machines, the CDC will enumerate as Curiosity Virtual COM Port and appear in the Ports section of the
Windows Device Manager. The COM port number can also be found there.
On Linux machines, the CDC will enumerate and appear as /dev/ttyACM#.
On MAC machines, the CDC will enumerate and appear as /dev/tty.usbmodem#. Depending on which terminal
program is used, it will appear in the available list of modems as usbmodem#.

https://forum.allaboutcircuits.com/threads/pic32mk-mc-qei-example.150351/page-2#post-1560795
Here I'm using the dev board PKOB4 CDC serial port to send data from the PIC32 to a PC JAVA program for display via the USB connection.

Write data to the uC UART that's connected to the tx/rx ping of the PKOB4 serial.

C:
       sprintf(cbuffer, "%2.4f %2.4f %2.4f %2.4f ", q0, q1, q2, q3);
        UART1_Write((uint8_t *) cbuffer, strlen(cbuffer));
        sprintf(cbuffer, "%3.2f %3.2f %3.2f\n\r", accel[0], accel[1], accel[2]);
        UART1_Write((uint8_t *) cbuffer, strlen(cbuffer));
Open and use the CDC device to receive data on the Linux PC in a Java program.
Java:
        SerialPort port = SerialPort.getCommPort("ttyACM0");
        port.setBaudRate(115200);
        port.setComPortTimeouts(SerialPort.TIMEOUT_SCANNER, 1, 1);
        if (port.openPort() == false) {
            System.err.println("Unable to open the serial port. Exiting.");
            System.exit(1);
        }
        Scanner s = new Scanner(port.getInputStream());
 
Last edited:

trebla

Joined Jun 29, 2019
599
If you have some newer curiosity boards (like Nano) or MPLABX XPRESS board, to here is pretty good webinar from Microchip how to use MPLABX serial monitor without any additional serial converter hardware. You need to register with your Microchip account to watch this course. The Microchip University has many interesting webinars if you want learn something new with Microchip products.
 

click_here

Joined Sep 22, 2020
548
After being inspired here to upgrade my decades old approach I've found some CP2102 based USB-serial boards, they seem like they are worth a try!
 

click_here

Joined Sep 22, 2020
548
Also an obvious answer that no one has said is to use your Arduino and the "SoftwareSerial.h" library - You can make a USART-USB converter with things that you already own :)
 

Thread Starter

guetkar

Joined Mar 9, 2022
45
Also an obvious answer that no one has said is to use your Arduino and the "SoftwareSerial.h" library - You can make a USART-USB converter with things that you already own :)
Yes, that what I was doing till now, using the arduino (and it's serial monitor).
 

Thread Starter

guetkar

Joined Mar 9, 2022
45
If you use a PICkit 2 for loading the micro and the stand-alone GUI program, there's a neat trick to use the GUI's UART tool.

Set up a software UART in your code, with the receive and transmit pins corresponding to the ICSP pins used for loading code (I forget how ICSP clock and date match up to receive and transmit in the GUI UART tool but define the pins as needed), and tell the Mico software UART to invert the signals (as there's no MAX232 chip involved).

Then it's an easy matter to load code using the PICkit 2, then active the UART tool and see your messages from the micro.

I can provide details if desired. There are 2 options for updated PICkit 2 GUIs. One has been mentioned in another thread here recenting, which is a paid app. Another one I've seen recently is another forum is supposed to be very good, and it's free. If there's interest, I'll dig them out and post links.
Thanks @Jon Chandler, even though I didn't get every thing you said !! but I'm using Pickit 3 (I guess it works also for Pickit 3).
 

Jon Chandler

Joined Jun 12, 2008
1,652
Hmmmm. If the GUI programs that support the PICkit 2 and PICkit 3 gives you the same UART tool when used with the PICkit 3, then my suggestion works. I don't have a PICkit 3 to try it.
 
Top