1
\$\begingroup\$

I have referred http://microchipdeveloper.com/harmony:example-usart-dynamic-wf32 to configure the UART and send/receive data between PC(Putty) and my PIC32MZ.

The demo program in the link receives the data, adds one to it and transmits it back to putty.

    case APP_STATE_RX:                          // USART receive state
    {   
        // if byte received in USART instance pointed to by myUSARTHandle (USART1 in this case)
        if (!DRV_USART_ReceiverBufferIsEmpty(myUSARTHandle))
        {
           appData.rx_byte = DRV_USART_ReadByte(myUSARTHandle); // read received byte
           appData.tx_byte = appData.rx_byte + 1;  // modifying received byte confirms it was received
           appData.state = APP_STATE_TX;           // change state to TX
        }
        break;
    }

    case APP_STATE_TX:                          // USART transmit state
    {
        // make sure the transmit buffer is not full before trying to write byte 
        if(!(DRV_USART_TRANSFER_STATUS_TRANSMIT_FULL & DRV_USART_TransferStatus(myUSARTHandle)) )
        {
            DRV_USART_WriteByte(myUSARTHandle, appData.tx_byte);  // send modified byte
            appData.state = APP_STATE_RX;       // change state to RX and wait for next received byte
        }
    } 

However, whenever I enter (transmit) any data from Putty to PIC, the PIC reads it as "ý";0xff.

The PIC code adds 1 to 0xff and sends NULL;0x0 back.

PIC32 code variables after trying to transmit any data from serial port

The putty screen is always blank.

How can I transmit/receive proper data between my PIC and pc?

UART settings Putty settings

Thanks in advance!

Edit:- I double-checked the clock settings for the UART etc, however every-time I send something from puty (characters or numbers) all I receive in UART_Rx buffer is "ý";0xff.

\$\endgroup\$
  • \$\begingroup\$ I would take a step back and verify the bit rates are good by simply sending a readable ASCII character like 'R' back to the PC instead of incrementing. The trouble with 0xff and 0x00 is that they're common values after the C code inits and could hide the nature of the problem. \$\endgroup\$ – isdi Nov 30 '18 at 14:58
  • \$\begingroup\$ Hi isdi, thank you for your comment. Actually I tried sending the letter 'A', 'R', but if produces that same result. I even sent 0x55 and 0xAA alternately, however, everytime I encounter 0xff and NULL. Putty remains blank as always. \$\endgroup\$ – Sandrocottus Nov 30 '18 at 15:27
  • \$\begingroup\$ I'm sorry having a hard time parsing your statement. Do you mean to say that even if try sending a hard-coded 'A' from the PIC (in response to you sending the PIC a character), the putty screen does not show an 'A', but instead it shows nothing or some "junk" character? Remember that some ASCII characters are not really printable. Also your appData.tx_byte is defined as a byte, correct? I noticed you mentioning sending 32 bit data across, binary data will not be "readable". \$\endgroup\$ – isdi Nov 30 '18 at 15:41
  • 1
    \$\begingroup\$ This is a common symptom of using different baud rates or other settings on each end. \$\endgroup\$ – pjc50 Nov 30 '18 at 15:47
  • 1
    \$\begingroup\$ Hey @Scott Seidman, Thanks a lot. I had missed out on the "POSCMOD" clock setting. Configured it and now I can see the data in putty as required. \$\endgroup\$ – Sandrocottus Dec 3 '18 at 15:39
1
\$\begingroup\$

For all questions regarding timing, I recommend starting with something dirt simple that confirms all the system clock configurations. Flashing an LED at a known rate is one way to do this.

Clock setup can be tricky, and step 1 is to make sure you got it right. Even if you get your clock config all screwed up, PICs tend to find a mode to start up in. I start pretty much every project making sure I have the clock right.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.