I'm very much new to Microcontroller programming.
I'm using
- MplabX v3.26 as IDE
- XC16 compiler
- PICKit 3
- p33EP256MU810 (dspic)
for programing
I have written very simple program to blink LED and send few characters over UART, please refer to following source code:
#include <p33Exxxx.h>
#include <p33EP256MU810.h>
#include <libpic30.h>
#include <uart.h>
#include <stdlib.h>
#include <stdio.h>
#include <pps.h>
#include <xc.h>
#include <stdint.h>
// Configuration settings
_FOSC(FNOSC_FRCPLL);
_FWDT(FWDTEN_OFF);
int main()
{
//make all pins digital
PADCFG1 = 0xFFFF;
//set direction
TRISCbits.TRISC2 = 0;
//Initialze UART1
iPPSOutput(OUT_PIN_PPS_RP68, OUT_FN_PPS_U1TX);
//close UART
CloseUART1();
//open UART
OpenUART1( UART_EN & UART_IDLE_CON & UART_DIS_WAKE & UART_DIS_LOOPBACK & UART_DIS_ABAUD & UART_NO_PAR_8BIT & UART_1STOPBIT,
UART_TX_ENABLE & UART_INT_TX & UART_ADR_DETECT_DIS,
15);
while (1)
{
//turn on led
LATCbits.LATC2 = 1;
__delay32(3750000); // ~1 sec delay
//turn off led
LATCbits.LATC2 = 0;
__delay32(3750000); // ~1 sec delay
//Transmit data
while(BusyUART1()); //Wail till available
WriteUART1(0x55);
WriteUART1(0xaa);
while(BusyUART1()); //Wail till all bytes sent
}
return 0;
}
LED blinking part works perfectly, but I'M receiving garbage characters on other end of UART where I'm using serial monitor tool (X-CTU) to monitor data.
My major issue is that I'm not able to calculate baudrate. Please let me know if I'm doing anything wrong.
Thank you