Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART problem using dsPIC with MPLAB C30

Status
Not open for further replies.

luckyquincy

Newbie level 5
Joined
Oct 7, 2005
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,390
dspic uart

hi,
I'm new to dsPIC. I'm trying to fix my UART code.
I use dsPIC30F4012.
It didnt tranfer any value to the hyperlink.
I hope you guys can help me.
I followed the steps from the datasheet. The only thing, I'm not so sure is the part where it talk about the interrupt.
Step 5 from the data sheet:
"Enable the transmission by setting the UTXEN(UxSTA<10>) bit, which will also set the UxTXIF bit. The UxTIF bit should be cleared in the software routine that services the UART transmitt interrupt. The operation of the UxTIF bit is controlled by the UTXISEL control bit"

I'm not so sure if I did it rite.
Please, let me know where my mistake is.
I really appreciated it.
Thank you.

Here's my code below:
#include "C:\Program Files\Microchip\MPLAB C30\support\h\p30F4012.h"
#include "C:\Program Files\Microchip\MPLAB C30\support\h\uart.h"
#include "C:\Program Files\Microchip\MPLAB C30\include\stdio.h"
#include "C:\Program Files\Microchip\MPLAB C30\include\stdlib.h"

void Init_UART1(void);
void OpenUART1(unsigned int config1,unsigned int config2, unsigned int ubrg) __attribute__ ((section (".libperi")));
unsigned int ReadUART1(void) __attribute__ ((section (".libperi")));
void WriteUART1(unsigned int data) __attribute__ ((section (".libperi")));

int main (void)
{
int A = 0x42;
Init_UART1();
U1TXREG = 0x42; //Transmitt letter B to Hyperlink
}

void Init_UART1(void)
{
//Not sure if I can write the decimal value directly to the U1BRG register
//194 --> 0xC2, I tried both in hex and dec, but it still didnt give the output on the hyper terminal

U1BRG = 194; //BRG value @FCY = 30 MHz, Baud Rate = 9600
IPC2bits.U1TXIP = 3;
IPC2bits.U1RXIP = 5;
U1STA = 0;
U1MODE = 0x8000; //PDSEL<2:1> = 00 (8 bit data, no parity)
//STSEL<0> = 0 (1 Stop Bit)
//UARTEN<15> = UART ENABLE
//UTXEN<10> = 1 Transmitted Enable
U1STAbits.UTXEN=1;

}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top