chipKIT® Development Platform

Inspired by Arduino™

problem with UART on chipKIT Max32 board

Created Mon, 01 Feb 2016 20:34:31 +0000 by berthe


berthe

Mon, 01 Feb 2016 20:34:31 +0000

I generated a code for my USART on a chipkit Max32 board using MPLab Harmony based on the tutorial given at this link http://microchip.wikidot.com/harmony:example-usart-static-wf32-steps. The code compiles well and uploads to my board but when I try to interface it with my laptop it keeps reading 0xFF on the RX buffer and even when I tried sending a character (e.i: 0x20) the terminal on my computer won't see it. I tried with different terminal emulators (YAT, Realterm), I also downloaded the FTDI driver from http://www.ftdichip.com/Drivers/VCP.htm but nothing seems to fix or change a thing about my issue. I am using Windows 10, the latest version of MPLab X and the XC32 compiler. I selected the correct board in the Project properties. I have also tried the example code provided with MPLab Harmony but that also doesnt work. One thing I should mention is that the receive buffer knows when I character has been sent to it but it returns the wrong value.


lstandage

Tue, 02 Feb 2016 00:19:08 +0000

You've got two different boards to deal with. The MAX32 is not the same as the WF32.

The WF32 uses UART 1 for the FTDI chip, but the MAX32 uses UART 2.

Try changing the UART and see if that helps.


berthe

Tue, 02 Feb 2016 01:15:36 +0000

I just changed the USART_ID_1 to USART_ID_2 and this is what the configuration looks like now: PLIB_USART_BaudRateSet(USART_ID_2, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), 9600); PLIB_USART_HandshakeModeSelect(USART_ID_2, USART_HANDSHAKE_MODE_FLOW_CONTROL); PLIB_USART_OperationModeSelect(USART_ID_2, USART_ENABLE_TX_RX_USED); PLIB_USART_LineControlModeSelect(USART_ID_2, USART_8N1); PLIB_USART_TransmitterEnable(USART_ID_2); PLIB_USART_TransmitterInterruptModeSelect(USART_ID_2, USART_TRANSMIT_FIFO_NOT_FULL); PLIB_USART_ReceiverEnable(USART_ID_2); PLIB_USART_ReceiverInterruptModeSelect(USART_ID_2, USART_RECEIVE_FIFO_ONE_CHAR); PLIB_USART_Enable(USART_ID_2);

Also, to check the receive buffer I am calling this function DRV_USART0_ReceiverBufferIsEmpty(). other functions have the same prefix DRV_USART0. Does that map to the FTDI?


berthe

Tue, 02 Feb 2016 03:05:03 +0000

After changing the USART ID to 2, now the function call PLIB_USART_ReceiverDataIsAvailable(USART_ID_2) doesnt return true anymore even after sending data from my laptop. It used to detect it when I hadthe ID set to 1 however. It just kept reading 0xFF.


lstandage

Tue, 02 Feb 2016 04:19:56 +0000

Okay. I should have read the schematic a little closer...

It is supposed to be UART 1. This is what I have in my Initialize, and it does seem to work.

/* Initialize USART */
    PLIB_USART_BaudRateSet(USART_ID_1, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), 9600);
    PLIB_USART_HandshakeModeSelect(USART_ID_1, USART_HANDSHAKE_MODE_FLOW_CONTROL);
    PLIB_USART_OperationModeSelect(USART_ID_1, USART_ENABLE_TX_RX_USED);
    PLIB_USART_LineControlModeSelect(USART_ID_1, USART_8N1);
    PLIB_USART_TransmitterEnable(USART_ID_1);
    PLIB_USART_TransmitterInterruptModeSelect(USART_ID_1, USART_TRANSMIT_FIFO_NOT_FULL);
    PLIB_USART_ReceiverEnable(USART_ID_1);
    PLIB_USART_ReceiverInterruptModeSelect(USART_ID_1, USART_RECEIVE_FIFO_ONE_CHAR);

    PLIB_USART_Enable(USART_ID_1);

And this is my APP_Tasks function:

/* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            appData.state = APP_STATE_RX;
            break;
        }

        case APP_STATE_RX:
        {
            if (!DRV_USART0_ReceiverBufferIsEmpty())
            {
                appData.rxByte = DRV_USART0_ReadByte();
                appData.txByte = appData.rxByte + 1;
                appData.state = APP_STATE_TX;
            }
            break;
        }
        
        case APP_STATE_TX:
        {
            DRV_USART0_WriteByte(appData.txByte);
            appData.state = APP_STATE_RX;
            break;
        }
        
        /* The default state should never be executed. */
        default:
        {
            /* TODO: Handle error in application's state machine. */
            break;
        }
    }

lstandage

Tue, 02 Feb 2016 04:20:53 +0000

So the next question is going to be, what baud rate is your terminal set for?


berthe

Tue, 02 Feb 2016 05:05:53 +0000

I'm using YAT terminal and the baud rate is set for 9600. Here is a screenshot of my settings and you can notice on the background the null values Im getting (in purple) whenever I send in a character (in blue).[attachment=0]screenshot.jpg[/attachment]


lstandage

Tue, 02 Feb 2016 06:08:02 +0000

Everything looks right from the settings perspective.

Do you have a way to capture the actual waveforms on the TX and RX pins? Like an oscilloscope or logic analyzer?


majenko

Tue, 02 Feb 2016 11:47:01 +0000

This certainly does look like a baud rate error. If you can capture a waveform in some way you might like to try it on a constant stream of the letter 'U'. U is a magic character in that its binary code is 0b01010101 which, when coupled with the start and stop bits, turns into 0b1010101010, and if you stream that constantly you end up with 0101010101010101010101.... I.e., a nice square wave at exactly 50% of the selected baud rate.

You can even measure it with a DMM that has a frequency measurement setting (and even most cheap ones do these days). For 9600 baud you should, of course, measure it at 4800Hz.


berthe

Thu, 04 Feb 2016 09:43:36 +0000

Thanks for the help guys. I finally got it to work. I had to make a new project and reconfigure it. I must have done a bad configuration before.