I've learned USART of PIC16F883, and I want to learn UART of dsPIC33FJ64MC802.(Actually I need to learn dsPIC, but I learned PIC16F883 first since I thought it's easier to learn.)
Here's my circuit diagram of PIC16F883 in Proteus simulator(I can send messages to virtual COM port):
enter image description here
And here's the code:
void main() {
char ch;
UART1_Init(19200);
Delay_ms(100);
while(1)
{
if(UART1_Tx_Idle())
UART1_Write_Text("OK2\r\n");
Delay_ms(500);
}
}
I have found some resources teaching dsPIC UART, but I can hardly read the sample code. And I don't know how to what's the circuit of the sample code and how to learn. Can anyone provide some help? How can I learn dsPIC UART based on the what I've learned from PIC?
1.UART Example for DSPIC33 (DSPIC33FJ128GP802)
2.Setting up RS232 transmission on a dsPIC
3.dsPIC33F UART transmission problem
4.Thread: [dspic33] UART - Transmits ok, but receives garbage
EDIT:
An easy way to run dsPIC UART is using mikroC for dsPIC, it's very user friendly. It provides sample code and the code is easy to understand.
3 Answers 3
You have unfortunately not learned much from your previous UART experience if that is all the code you have. Here it seems like you have used a couple of libraries (i.e header files) which has implemented all the "tricky" stuff for you.
I would suggest that you take a look in your code and open up the UART1_Init()
function. This is most likely included as uart.c
and uart.h
, where the .c-file is the actual implementation.
Here you will find how UART actually works, and when you have learned this you can move on to other controllers. As a matter of fact, look in to all of your uart-functions and study them, finding out what every line means. This is the most common way to learn code: To study code, understanding it and write your own.
If you really want to learn the UART, take a look at my canned UART code for PIC and dsPIC. This should be included in the PIC Development Tools release at http://www.embedinc.com/pic/dload.htm. Look for files with "uart" in their names in the SOURCE> PIC and SOURCE> DSPIC directories within the software installation directory.
For example, source/pic/uart.ins.aspic implements a highly configurable low level interface to most 8 bit PIC UARTs. You can specify whether it uses interrupts or polling, input and output FIFOs, etc. The dsPIC counterpart will be source/dspic/uart.ins.aspic. One nice thing about the dsPIC architecture is that each interrupt is individually vectored, so it is possible write a self-contained UART module that handles interrupts and all in the same file.
I suggest looking at the Microchip XC16 documentation that comes in the \docs folder of the installation, specifically 16-Bit_Language_Tools_Libraries_51456.pdf (for XC16 version 1.11). This has lots of UART examples and explains how to use the XC16 library functions to control the UART.
I also suggest Microchip's Embedded Code Source site, as there are lots of samples available there.