

Unsigned char UART_RX_OUTPUT // Variable to store the UART output
#MPLAB XC8 UART SERIAL NUMBER#
Unsigned char RD_SER_NUM // Variable to store command to read serial number

Int UART_TX_Count // Counter varible for the UART1 transmitted interrupt Int UART_RX_Count // Counter variable for the UART1 receiver interrupt #pragma config FSOSCEN=OFF // Disable secondary Oscillator #pragma config OSCIOFNC=OFF // CLKO output disabled #pragma config FNOSC=PRIPLL // Oscillator selection, PRIPLL = Primary Oscillator with PLL module #pragma config POSCMOD=XT // Primary oscillator configuration, HS = HS Oscillator mode selection #pragma config BWP=OFF // Boot Flash Write-protect, 1 = OFF/Disabled #pragma config CP=OFF // Code-Protect, 1 = OFF/Disabled #pragma config FWDTEN=OFF // Watch Dog Timer (WDT) is not enabled. #pragma config FPBDIV=DIV_2 // 2 = PBCLK is SYSCLK divided by 2 (80MHz/2 = 40MHz) #pragma config FPLLODIV=DIV_1 // Postscaler for PLL, output divided by 1 #pragma config FPLLMUL=MUL_20 // Phase-Locked Loop (PPL) muiltiplier, multiplier of 20 #pragma config FPLLIDIV=DIV_2 // PLL Input Divider Value (Divide by 2)

#define GetSystemClock() (FOSC) // For delay #define FOSC 8000000 // Crystal frequency = 8 MHz This should give me the desired baudrate of 9600. So:įPLLIDIV=2, FPLLMUL=20, FPLLODIV=1, FPBDIV=2, FNOSC=PRIPLL, BRGH = 0, and U1BRG = 259. The configuration below and in void UART1_Init should set up the UART correctly. I hope this is clear enough, any help is very much appreciated
#MPLAB XC8 UART CODE#
The Delay and interrupt code can be ignored, they are working as expected, so I really believe the problem has to do with the initial setting of the PIC/buad rate. I know the data being received doesn't match the data send because i checked in the "watches" in debug mode in mplab and when I echo the data send from the terminal to the PIC32 back to the terminal it doesn't match either. Could someone please look over my code and see if someone can see a problem? Did I forget to define something? Did I define something wrong? Did I mis calculate the baud rate? I think this being caused by a mistake in my baud rate settings, but I am not sure. To convert the signal from the PIC UART to RS232 levels I am using a MAX232EPE.Īt the moment I am running into the problem that when I send 0x41 for example from the PIC32 to the terminal or vice versa, the received data doesn't match. I am trying to set up UART communication on the PIC32 and send a hex code like 0x41 for example to a terminal on my computer through RS232. In the code I specified exactly which PIC, compiler, etc I am using. I am currently working for the first time with a PIC microcontroller.
