Jump to content
 

Using the CDC Serial port on the PIC18F47K40 Xpress Evaluation Board


Orunmila

1,564 views

 Share

I recently got my hands on a brand new PIC18F47K40 Xpress board (I ordered one after we ran into the Errata bug here a couple of weeks ago).

I wanted to start off with a simple "Hello World" app which would use the built-in CDC serial port, which is great for doing printf debugging with, and interacting with the board in general since it has no LED's and no display to let me know that anything is working, but immediately I got stuck. Combing the user's guide I could not find any mention of the CDC interface or which pins to configure to make it work, so I stared at the schematic and identified a hand full of candidates which I could try as the correct pins.

Eventually I figured it out, the TX pin to send data to the PC is RB6 and the RX pin which will receive data from the PC is RB7, so if you are setting up the UART using MCC it should look like this:

image.png

 

I created a very simple little terminal application to test the board with and thought this may be something useful for others who start with this board, especially since the standard MCC UART code falls afoul of the dreaded Errata we discussed here before caught me out again even on this simple little application.

image.pngSo remember to set the linker up to implement the workaround for the Errata like so ->

The little program simply waits for a keypress (so you have time to set up your terminal application) and then (at 115200 BAUD) sends the welcome message "Hello World". After this the program will echo every character you type, but it will enclose it in a message so that you are sure you are not just fooled by the local echo in your terminal program!

 

 

 

 

 

 

Here is the whole program, the serial port and other setup is all generated using MCC.

void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();

    // Wait for a keypress before we start
    EUSART1_Read();
    
    // Say Hello
    printf("Hello World\r\n");

    while (1)
    {
        printf("Received: '%c' \r\n", EUSART1_Read());
    }
}

The full example project can be downloaded from here ADC_47K40.zip

Note: I have set the project up to automatically copy the hex file onto the board, programming it, when I build the code. This is however set up for my MAC, if you are no a PC or linux you will probably see an error when building that it could not copy the file. If you want to set this up for your platform the instructions are in the users guide for the board.

I include a screenshot of the page here for convenience.

image.png

 

 

 Share

2 Comments


Recommended Comments

This really is a nice little program to confirm operation of the xpress board! I forgot to check the stdio redirect option in for the eusart module in MCC and so was stuck for a couple minutes!

One question is with regard to how the uC is programmed. Does the program go into ram on the xpress board? I have not looked in depth yet, but the program seems to go away when the board restarts.

Keith

Link to comment
  • Member
On 11/25/2020 at 12:38 PM, KM1 said:

One question is with regard to how the uC is programmed. Does the program go into ram on the xpress board? I have not looked in depth yet, but the program seems to go away when the board restarts.

It goes into flash, the USB device has code to reprogram the device flash.

  • Like 1
Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...