Author Topic: UART in MPLAB Harmony  (Read 2797 times)

0 Members and 1 Guest are viewing this topic.

Offline nithiATopic starter

  • Newbie
  • Posts: 4
  • Country: th
UART in MPLAB Harmony
« on: July 14, 2016, 03:39:50 pm »
Hi
I am using MPLAB X IDE 3.35 and Harmony 1.06.02 with PIC32MX1/2/5 Starter Kit and I/O Expansion Board.
I tried to use UART with bluetooth BTM511.
I programmed BTM511 that if I push a button, e.g. GPIO5, it will send text GPIO5,1 via UART TX of the BTM511.
The problem is when my PIC received the data, it received random text like '(' or 'ï'.
I check the received by assign to a char parameter.

Is there anyone can suggest how to solve this to be able to received 'GPIO5,0'?
Thank you.
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1610
  • Country: gb
Re: UART in MPLAB Harmony
« Reply #1 on: July 15, 2016, 01:07:21 am »
It is unlikely given the information that anyone can know exactly whats wrong with your code/setup.  All anyone can do is recommend you double check your connections, and write a simple program to test the UART.  Are you sure that the PIC's TX is connected to the BTM511's RX?  Is the baud you set in your PIC the same as the Bluetooth module is expecting?  Separate the problem into different parts, and test one at a time - then hook them together one by one.
 

Offline nithiATopic starter

  • Newbie
  • Posts: 4
  • Country: th
Re: UART in MPLAB Harmony
« Reply #2 on: July 15, 2016, 02:47:39 am »
Hi Buriedcode
Thank you for your comment.

Are you sure that the PIC's TX is connected to the BTM511's RX?

I am sure I have correct connection because I can send some character out from PIC's TX and receive some character back from BTM511.
PIC TX >>> RX BTM511
PIC RX <<< TX BTM511
PIC RTS >>> CTS BTM511
PIC CTS <<< RTS BTM511
However, the received character is weird. For example, if I sent 'a', I should get 'a' back from BTM511.

When I use the USB to UART chip (FT232) on BTM511 Evaluation Board, it works just fine. For example, if I sent 'a', I got 'a' back from BTM511.
Please see the BTM's schematic from the below link.
https://www.dropbox.com/s/5vb1yhlnulg5uz6/Board%20Schematics%20-%20BTM511.pdf?dl=0

When I use PIC to send a character, I have to disable the FT232 by using jumper at J8.
However, the received character from BTM511 to PIC is weird. For example, if I sent 'a', I got 'ÿ' back from BTM511.

In the schematic, since FT232 is using DCD, DTR, DSR, RI signals, DO I NEED TO USE THESE SIGNALS?

Is the baud you set in your PIC the same as the Bluetooth module is expecting?

The baud is set to 9600 as default on BTM511 and I also set 9600 on PIC.

My MPLAB Harmony code for APP_Tasks program in app.c is below
Code: [Select]
void APP_Tasks ( void )
{
    /* Check the application's current state. */
    switch ( appData.state )
    {
        /* Application's initial state. */
        case APP_STATE_INIT:
        {
            appData.state = APP_STATE_1;
            break;
        }
       
        case APP_STATE_1:
        {
            if(!DRV_USART0_ReceiverBufferIsEmpty())
            {
                appData.rx_data1 = DRV_USART0_ReadByte();
                appData.rx_data2 = DRV_USART0_ReadByte();
                appData.rx_data3 = DRV_USART0_ReadByte();
                appData.rx_data4 = DRV_USART0_ReadByte();
                appData.rx_data5 = DRV_USART0_ReadByte();
                appData.state = APP_STATE_2;
            }
            break;
        }
       
        case APP_STATE_2:
        {
            if(!DRV_USART0_ReceiverBufferIsEmpty())
            {
                appData.rx_data1 = DRV_USART0_ReadByte();
                appData.rx_data2 = DRV_USART0_ReadByte();
                appData.rx_data3 = DRV_USART0_ReadByte();
                appData.rx_data4 = DRV_USART0_ReadByte();
                appData.rx_data5 = DRV_USART0_ReadByte();
                appData.state = APP_STATE_1;
            }
            break;
        }

Please also see the BTM511's user guide and PIC32MX1/2/5 Starter Kit's user guide for your reference.
https://www.dropbox.com/s/m68fac23723ztf8/User%20Guide%20-%20BTM510-511%20v22.2.5.0.pdf?dl=0
https://www.dropbox.com/s/x9jhitjah00xe3c/PIC32MX1XX%3A2XX%3A5XX.pdf?dl=0

Hope anyone can help me.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf