0
votes

I am using PIC32MX Clicker (PIC32MX534F064H microcontroller) for transmitting data through UART and receiving the same on PC using a USB to serial converter at baudrate 115200.

When I try to send the data through PIC32 and read on my PC, I recieved data but, which are different. Please see below for code snippets. It would be great if anyone could suggest me what to modify to get the uart working. Thanks

#define GetSystemClock()      (80000000ul)
#define GetPeripheralClock()  (GetSystemClock()/(1 << OSCCONbits.PBDIV))
#define GetInstructionClock() (GetSystemClock())

void initSerial(){
UARTConfigure(UART5,UART_ENABLE_PINS_TX_RX_ONLY);
 UARTSetFifoMode(UART5, UART_INTERRUPT_ON_TX_NOT_FULL
         | UART_INTERRUPT_ON_RX_NOT_EMPTY);
 UARTSetLineControl(UART5, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
UARTSetDataRate(UART5, GetPeripheralClock(), 115200);
UARTEnable(UART5, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
}


void writeSerial(uint8_t c){
while(!UARTTransmitterIsReady(UART5));
UARTSendDataByte(UART5, c);
while(!UARTTransmissionHasCompleted(UART5));
}
1

1 Answers

0
votes

Below is how I configure my 9600 UART5 on a PIC32MX795F512L for use to communicate with a GPS chip. This should be the same just replace with 115200 and it should work. If it doesn't try 9600 on the off chance you have a fake FTDI USB<->Serial converter, the fake ones can be very fickle.

    UARTConfigure(UART5, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(UART5, UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART5, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    /* configPERIPHERAL_CLOCK_HZ = 40000000 */
    UARTSetDataRate(UART5, configPERIPHERAL_CLOCK_HZ, 9600);
    UARTEnable(UART5, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
    INTSetVectorPriority(INT_VECTOR_UART(UART5), configKERNEL_INTERRUPT_PRIORITY + 1);
    INTSetVectorSubPriority(INT_VECTOR_UART(UART5), INT_SUB_PRIORITY_LEVEL_2);
    INTEnable(INT_SOURCE_UART_RX(UART5), INT_ENABLED);