Electronic – SYSTEMConfigPerformance not executing in PIC32

cfrequencypic

I have PIC32MX795F512L MCU and I am working on its UART communication. I have made the program and its working fine. I was curious about the frequency my PIC is running so I searched a little bit and found this online document which says that :

SYSTEMConfigPerformance() is a very helpful library function used to easily optimize the performance of the PIC32. You provide the system (instruction) clock frequency and this function will do the rest. It will perform the following tasks for you:

  1. Enable instruction and data caching
  2. Enable instruction prefetch
  3. Configure the Flash and SRAM for minimum wait states
  4. Maximize the peripheral bus clock frequency

So when I included the SYSTEMConfigPerformance(FCY) in my code, my UART communication stops and I was receiving some random chars. When I excluded the SYSTEMConfigPerformance(FCY) it wwas working fine. I don't know the reason behind this strange behavior. I am using 8MHZ crystal with PLL and finally running my PIC at 72MHZ frequency. Following is the code I am using:

#define FCY 72000000UL
#define FPB (FCY/2)
#define BAUDRATE    9600
#pragma config POSCMOD=HS,FNOSC=PRIPLL 
#pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1
#pragma config FPBDIV=DIV_2, FWDTEN=OFF, CP=OFF, BWP=OFF

int main()
{
  SYSTEMConfigPerformance(FCY); //<-- Problem is at this line.
  OpenUART1( UART_EN | UART_NO_PAR_8BIT | UART_1STOPBIT, UART_RX_ENABLE | UART_TX_ENABLE, (FPB/16/BAUDRATE)-1 );
  while(1)
  {
     putsUART1("Hello\n");
  }
}

void DelayMs( unsigned t)
{
T1CON = 0x8000;
while (t--)
{
    TMR1 = 0;
    while (TMR1 < FPB/1000);
}
}

Best Answer

Maybe this is late but when you are including SYSTEMConfigPerformance(FCY); you will also have to change OpenUART1(). Try following :

int x;
x = SYSTEMConfigPerformance(FCY);
OpenUART1( UART_EN | UART_NO_PAR_8BIT | UART_1STOPBIT, UART_RX_ENABLE | UART_TX_ENABLE, (x/16/BAUDRATE)-1 );

Replace FPB with x. It should work.!