Jump to content
 

Contributors to this blog

Using the CDC Serial port on the PIC18F47K40 Xpress Evaluation Board

Orunmila

103 views

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

 

 



0 Comments


Recommended Comments

There are no comments to display.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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