UART in MPLAB Harmony - Page 1
Forum section: electronics / general

author: nithiA
author_rank: Newbie
timestamp: July 14, 2016, 03:39:50 pm
content: HiI 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.

author: Buriedcode
author_rank: Super Contributor
timestamp: July 15, 2016, 01:07:21 am
content: 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.

author: nithiA
author_rank: Newbie
timestamp: July 15, 2016, 02:47:39 am
content: Hi BuriedcodeThank you for your comment.Quote from: Buriedcode on July 15, 2016, 01:07:21 amI 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 BTM511PIC RX <<< TX BTM511PIC RTS >>> CTS BTM511PIC CTS <<< RTS BTM511However, 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=0When 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?Quote from: Buriedcode on July 15, 2016, 01:07:21 amThe 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 belowCode: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=0https://www.dropbox.com/s/x9jhitjah00xe3c/PIC32MX1XX%3A2XX%3A5XX.pdf?dl=0Hope anyone can help me.