How to Interface UART with dsPIC Friendly

Interfacing UART with dsPIC30F4011

Tags: UART interface with dspic30f4011,c source code for dspic30f4011 uart,schematics to interface uart with dspic30f4011, C Program to display a text in PC from DSPIC30F4011, Testing the UART0 with DSPIC30F4011,
Overall rating
DsPIC30F4011 Evaluation Board

The dsPIC30F4011 Evaluation board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s dsPIC30F (dsPIC30F4011), Evaluation Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 16-bit Microcontrollers.


UART (Universal Asynchronous Receiver Transmitter) are one of the basic interfaces which provide a cost effective simple and reliable communication between one controller to another controller or between a controller and PC.

RS-232 Level Converter

Usually all the digital ICs work on TTL or CMOS voltage levels which cannot be used to communicate over RS-232 protocol. So a voltage or level converter is needed which can convert TTL to RS232 and RS232 to TTL voltage levels. The most commonly used RS-232 level converter is MAX232.

This IC includes charge pump which can generate RS232 voltage levels (-10V and +10V) from 5V power supply. It also includes two receiver and two transmitters and is capable of full-duplex UART/USART communication.

  • RS-232 communication enables point-to-point data transfer. It is commonly used in data acquisition applications, for the transfer of data between the microcontroller and a PC.
  • The voltage levels of a microcontroller and PC are not directly compatible with those of RS-232, a level transition buffer such as MAX232 be used.

Interfacing UART

Fig. 1 shows how to interface the UART to microcontroller. To communicate over UART or USART, we just need three basic signals which are namely, RXD (receive), TXD (transmit), GND (common ground). So to interface UART with DSPIC30F4011, we just need the basic signals.


Fig. 1 Interfacing UART to Microcontroller

Interfacing UART with DSPIC30F4011

We now want to display a text in PC from DSPIC30F4011 Evaluation Board by using UART module. In DSPIC30F4011 Evaluation Board contains two serial interfaces that are UART1 & UART2. Here we are using UART1. The Transmitter pins send the data into PC and the receiver pin receives the data from PC. The PC and microcontroller speed are denoted by using baud rate. When the baud rates of both PC and Microcontroller are same, then only the data transmit and receive correctly otherwise not.

Pin Assignment with DSPIC30F4011


UART DB-9 Connector


Processor Lines

Serial Port Section







* Turn ON RXD1 and TXD1 of     CONFIG switch

* Connect USART1(P1) with PC     using serial cable

* Configure HyperTerminal at 9600

* Press RESET Once (If Necessary)








Output: The string "USART1 Demo Program" will be displayed

Circuit Diagram to Interfacing UART

Source Code

The Interfacing of UART with DSPIC30F4011 program is very simple and straight forward, which display a text in PC from DSPIC30F4011 Evaluation Board through UART1. Some delay is occurring when a single data is sent to PC. C programs are written in Mplab software. The baud rate of microcontroller is 9600.

C Program to display a text in PC from DSPIC30F4011


#include "p30f4011.h"

#include "delay.c"







#define XTFREQ        10000000

#define FOSC              XTFREQ/4

#define BAUDRATE   9600

#define BRGVAL        ((FOSC/BAUDRATE)/16)-1


unsigned char i;

unsigned char Msg[]="USART1 Demo Program";


int main(void)


       U1MODE= 0x8000;

       U1STA = 0x8400;

















      return 0;



                        void putch(unsigned int SendDat)









To compile the above C code you must need the MPLAB software & Microchip C30 Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without DSPIC30F4011 Evaluation Board.

The PICKIT2 software is used to download the hex file into your microcontroller IC DSPIC30F4011 through USB.

Testing the UART0 with DSPIC30F4011

Give +9V power supply to DSPIC30F4011 Evaluation Board; the serial cable is connected between the DSPIC30F4011 Evaluation Board and PC. Open the Hyper Terminal screen, select which port you are using and set the default settings. Now the screen should show some text messages.

If you are not reading any text from UART1, then you just check the jumper connections & just check the serial cable is working. Otherwise you just check the code with debugging mode in Mplab. If you want to see more details about debugging just see the videos in below link.

  • How to create & Debug a Project in Mplab using dsPIC30F

General Information

Join the World's Largest Technical Community

we respect your privacy.