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;
}