1
votes

i have a PIC32MX460F512L. I am setting up a UART communication with raspberry Pi 3. And i made also some tests with mi PC Windows serial terminal (Putty, Teraterm etc.). I am having stucking problems, because the raspberry sends and receives only rubbish. Then i tested it with putty on Windows and i noticed strange things. For example the uart baud rate on the board is set as 9600, and to send and receive data on windows i have to set putty's baud rate to 130 !! Then i had a look to my PCLK settings on pic and it seems like everything is correct since there is an external clk oscillator of 8MHz. I post the code below .

PIC CODE:

#define GetSystemClock() (80000000ul) // Hz
#define GetInstructionClock() (GetSystemClock()/1)
#define GetPeripheralClock() (GetInstructionClock()/1) //

long Baud_Rate;





    Baud_Rate = 9600;
    TRISFbits.TRISF8 = 0; // Set UART1TX like output
    TRISFbits.TRISF2 = 1; // Set UART1RX like input
    U1MODE = 0x00008000;
    U1STA = 0x00001400; // RXEN set, TXEN set

    U1BRG = ((USART_Clock_Source)/(Baud_Rate/16))-1;

May it be a fault on the external oscillator or maybe is there an error on the baud rate calculation? I cannot understand.

1

1 Answers

0
votes

Here is an error:

U1BRG = ((USART_Clock_Source)/(Baud_Rate/16))-1;

it should be:

U1BRG = ((USART_Clock_Source)/(Baud_Rate*16))-1;

And this:

#define GetSystemClock() (80000000ul) // Hz

should be

#define GetSystemClock() (8000000ul) // Hz

In this calculation is 8 MHz the instruction frequency not the clock frequency. The instruction frequency is half of the clock.