+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2016
    Posts
    33

    Default UART communication problem

    Hello,

    I am trying to use following code in a PIC18F14K50 to change configuration of a rn42 Bluetooth Module and it goes to command mode but then it gets stuck:


    As an example I want to change name of bluetooth module and then reboot it.
    Code:
    DEFINE LOADER_USED 1
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_BAUD 115200
    DEFINE HSER_SPBRG 12 
    DEFINE HSER_CLOERR 1
    
    DEFINE OSC 24
    
    ADCON0 = 011100
    ADCON1 = 000000
    ADCON2 = 110101
    
    ANSEL = 001000      
    ANSELH = 000011  
    
    TRISC.4 = 0 
    TRISC.0 = 0
    TRISC.1 = 1
    TRISB.5 = 1 
    TRISB.7 = 0 
    
    tx1 VAR PORTB.7
    rx1 VAR PORTB.5
       
    LED VAR PORTC.4
    
    Mybutton VAR PORTC.1
      
    mainloop:
       If Mybutton = 0 Then 
          HIGH LED      ' Turn on LED
                Hserout ["$$$"]                             'enter command mode
                Pause 100        
                Hserout ["SN,MyBT"]                       'Change name to MyBT
                Pause 100
                Hserout ["R,1"]                               'Reboot                      
          Pause 500
       Else
          LOW LED     ' Turn off LED
          Pause 500
       Endif
       Goto mainloop   ' Do it forever
    I receive the data on serial monitor when I use a UART-USB converter so I know the strings are being sent.

    However,the module starts blinking after $$$ but it doesn't perform the rest of commands.The similar Arduino code works without any problem.

    Any idea why it doesn't work?

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,259

    Default Re: UART communication problem

    Hi,
    Never used the RN42 but shouldn't there be some sort of line termination characters after each command, like a LF or CR?
    How else would it distinguish between for example MyBT and R, perhaps you wanted to change the name to MyBTR....


    EDIT: Yeah, the command reference seems to indicate CR is what it expects.
    /Henrik.
    Last edited by HenrikOlsson; - 26th September 2016 at 08:25.

  3. #3

    Default Re: UART communication problem

    You also have a typo, you have DEFINE HSER_CLOERR 1 it should be DEFINE HSER_CLROERR 1

  4. #4
    Join Date
    May 2016
    Posts
    33

    Default Re: UART communication problem

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Never used the RN42 but shouldn't there be some sort of line termination characters after each command, like a LF or CR?
    How else would it distinguish between for example MyBT and R, perhaps you wanted to change the name to MyBTR....


    EDIT: Yeah, the command reference seems to indicate CR is what it expects.
    /Henrik.
    AWESOME! That was the problem and it's working now.

Similar Threads

  1. Replies: 9
    Last Post: - 1st June 2016, 06:04
  2. uart problem
    By OYMYAKON in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th March 2011, 11:52
  3. Problem using Microloader and Uart Comm at the same time
    By guanerrr in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 3rd August 2007, 09:31
  4. Problem with UART... here is a real challenge
    By matias in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 5th May 2007, 08:30
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts