HSerial_ChangeBaud question


Go to last post By: keytapper
Today 12:29
Forum: Proton Plus Compiler v3
Starter: towlerg
Views: 0
Replies: 4
Today 12:25
Forum: The Lounge
Starter: towlerg
Views: 0
Replies: 0
Today 12:21
Forum: PICKAT
Starter: davutnacikaya
Views: 0
Replies: 1
Go to last post By: tumbleweed
Today 10:46
Forum: Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C / Master and Slave modes
Starter: CharlieBrown
Views: 1780
Replies: 14
Today 09:40
Forum: The Lounge
Starter: Tim
Views: 0
Replies: 2
Yesterday 23:22
Forum: Projects discussion
Starter: creatv
Views: 0
Replies: 5
Go to last post By: charliecoultas
Yesterday 20:43
Forum: The Lounge
Starter: pic-ignorant
Views: 0
Replies: 4
Yesterday 20:26
Forum: Proton Plus Compiler v3
Starter: Frizie
Views: 0
Replies: 7
Yesterday 18:31
Forum: LCD module
Starter: charliecoultas
Views: 0
Replies: 40
+ Reply to Thread
Results 1 to 8 of 8

Thread: HSerial_ChangeBaud question5 days old

  1. #1
    Member Frizie's Avatar
    Join Date
    Apr 2003
    Posts
    174
    Thumbs Up
    Received: 12
    Given: 1
    Total Downloaded
    586.09 MB

    0 Not allowed!

    Question HSerial_ChangeBaud question

    Hi people.

    Is it possible that HSERIAL_CHANGEBAUD is not (correct) working on a 16F648A?


    Code:
    DEVICE 16F648A                ;We gebruiken dit PIC type
    CONFIG HS_OSC, WDT_OFF, PWRTE_ON, LVP_OFF, BODEN_OFF, MCLRE_OFF
    
    
    DECLARE ALL_DIGITAL   = TRUE  ;Alle ingangen digitaal
    DECLARE XTAL          = 20    ;Gebruik een kristal van 20MHz
    DECLARE HSERIAL_BAUD  = 38400 '19200 '38400 '9600 '4800 '38400 '2400 '9600 '38400 '2400 ;Het instellen van de Bluetooth module d.m.v. zijn AT commando's kan alleen met 38400 Baud
    DECLARE HSERIAL_RCSTA = %10010000 ;Bit7:Enable serial port / Bit4:Continu ontvangen
    DECLARE HSERIAL_TXSTA = %00100000 ;Bit5:Transmitpin ingeschakeld (TXEN (Transmit ENable) = 1) / Bit4:0=USART asynchroon mode
    DECLARE HSERIAL_CLEAR = ON
    
    
    ON_INTERRUPT GOTO InterruptAfhandeling ;Spring naar label als data is ontvangen door de USART
    
    
    ;Programmaconstanten
    SYMBOL GIE          = INTCON.7
    SYMBOL PEIE         = INTCON.6
    SYMBOL RCIE         = PIE1.5  ;USART ReCeive Interrupt Enable
    
    
    ;Algemene constanten
    SYMBOL Wachttijd    = 2500    ;Niet alle commando's kunnen snel na elkaar door de Bluetooth module verwerkt worden
    
    
    ;Poortnamen
    SYMBOL SerieelIn    = PORTB.1 ;Ontvangt via HSERIN data van de BT-module (B.1 = USART ingang, RX) rechtstreeks (dus zonder weerstanden) afkomstig van TXD_BT-MODULE
    SYMBOL SerieelUit   = PORTB.2 ;Stuurt via HSEROUT data naar de BT-module (B.2 = USART uitgang, TX)- (via 1k/2k (of 4k7/10k) netwerk  (3,3V!)  PORTB.2 ---[1k ]---(RXD_BT-MODULE)---[2k ]--- GND
    
    
    ;Variabelen declareren
    DIM Buffer[21]      AS BYTE
    DIM OntvangenData   AS BYTE   ;Bevat de ontvangen 8-bits data vanuit USART
    DIM BD1             AS BYTE   ;Byte Dummy 1
    DIM BD2             AS BYTE   ;Byte Dummy 2
    
    
    CLEAR                         ;Wis alle RAM geheugen
    DELAYMS 500                   ;Stabilisatie signalen
    
    
    GIE  = 1                      ;GIE  (Global Interrupt Enable) activeren
    PEIE = 1                      ;PEIE (PEripheral Interrupt Enable) activeren
    RCIE = 1                      ;RCIE (USART ReCeive Interrupt Enable) activeren
    
    
    GOTO Main                     ;Spring over subroutine(s)
    
    
    
    
    ;======== SUBROUTINES ========
    InterruptAfhandeling:         ;Uitlezen en leegschuiven van buffer gebeurt in hoofdprogramma
    CONTEXT SAVE                  ;CONTEXT SAVE weglaten bij gebruik van Proton LITE-1
      HSERIN 5, Verder, [OntvangenData]               ;Time out staat op 5mSec ingesteld
      FOR BD1 = 0 TO 19           ;Buffer 
        IF Buffer[BD1] = 0 THEN   ;Bufferplaats nog leeg? Dan...
          Buffer[BD1]  = OntvangenData ;...hierin de ontvangen data plaatsen, en...
          BREAK                   ;...uit de FOR...NEXT lus springen
        ENDIF
      NEXT
    Verder:                       ;In het geval van een time-out, hier verder gaan
    CONTEXT RESTORE               ;Restore en ga terug naar de plek waar de interrupt ontstond
    
    
    
    
    ;====== HOOFDPROGRAMMA =======
    Main:
    HSEROUT ["AT+ORGL\r\n"]                 ;Zet alle parameters terug naar origineel (default)
    DELAYMS Wachttijd
    
    HSEROUT ["AT+ROLE=0\r\n"]               ;Instellen dat de rol vd BT-module slave is - Returns "OK" - 0=slave / 1=master / 2=slave-loop (Als de HC-05 module als master is ingesteld, is deze niet meer zichtbaar (te scannen) op bijvoorbeeld een smartphone)
    DELAYMS Wachttijd
    
    HSEROUT ["AT+RESET\r\n"]                ;Herstart als je van ROLE hebt veranderd (of doe spanning er even af)
    DELAYMS Wachttijd
    
    
    '============================
    HSERIAL_CHANGEBAUD 2400           ;<<<<<<<<<  DOES THIS COMMAND WORK?
    '============================
    DELAYMS 2000
    
    
    WHILE
      IF Buffer[0] > 0 THEN                 ;Zolang er zich een opdracht in de buffer bevindt, dan...
        GIE = 0
        FOR BD2 = 0 TO 19
          Buffer[BD2] = Buffer[BD2 + 1]     ;Schuif de waarden die in de buffer zitten 1 verder door
        NEXT
        Buffer[19] = 0                      ;Maak laatste bufferplaats leeg (opdracht en waarde wissen)
        GIE = 1
      ENDIF  
    
    WEND
    I have to set a HC05 bluetooth module at a speed of 38400 Baud, but the communication speed between the Bluetooth module and PIC should continue with 9600 Baud.
    I want to change this with HSERIAL_CHANGEBAUD 9600 during program execution.
    But I think this instruction doesn't works.
    If I do it in 2 strokes (so first do the settings from the Bluetooth module (via the PIC) with 38400 Baud, and then reprogram the PIC again with DECLARE HSERIAL_BAUD = 9600 for communication, then it works fine.

    Also tried HSERIAL_CHANGEBAUD 2400 Baud, but didn't matter.
    Does any one worked with the HSERIAL_CHANGEBAUD instruction?

    Regards,
    Frizie.
    Ohm sweet Ohm: www.picbasic.nl

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    59
    Thumbs Up
    Received: 14
    Given: 0
    Total Downloaded
    144.28 MB

    0 Not allowed!

    Default Re: HSerial_ChangeBaud question

    I have to ask, Why are you changing the baud rate every time you run the code? Why not just set the HC05 to communicate at a fixed baud rate. There are "AT" commands to do just that and then on powerup the HC05 will already be at the correct baud rate. I do this all the time. I set the baud rate for 19,200 so I can use the boot loader.

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,300
    Thumbs Up
    Received: 381
    Given: 137
    Total Downloaded
    1.60 GB

    0 Not allowed!

    Default Re: HSerial_ChangeBaud question

    Examining the code produced by Hserial_ChangeBaud for a PIC16F648A running at 20MHz, everything looks fine. For example:

    The command; Hserial_ChangeBaud 2400, produces the asm code:

    movlw 8
    bsf STATUS ,5
    movwf SPBRG
    bsf TXSTA ,2


    Which is correct.

    This can be checked by setting the Declare Hserial_Baud to 2400 and looking at the asm code produced for that, which is:

    ; UART1_ACTUALBAUD = 2399.23
    ; UART1_BAUDERROR = 0.0416667

    bsf STATUS ,PP_RP0
    movlw 8
    movwf SPBRG
    movlw 36
    movwf TXSTA
    bcf STATUS ,PP_RP0
    movlw 144
    movwf RCSTA


    Notice that the SPBRG SFR is loaded with the same value, and bit 2 of the TXSTA SFR is set.

    In your BASIC code, there is now no need for the Declares; HSERIAL_RCSTA and HSERIAL_TXSTA. The compiler automatically calculates the values for the SFRs by the Baud rate used Declare. i.e. Declare Hserial_Baud.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member Frizie's Avatar
    Join Date
    Apr 2003
    Posts
    174
    Thumbs Up
    Received: 12
    Given: 1
    Total Downloaded
    586.09 MB

    0 Not allowed!

    Question Re: HSerial_ChangeBaud question

    Thanks for response Les.

    It doesn't always work as far as I can test.

    For example:
    If I have set the HC05 bluetooth module parameter to 4800 baud and I place at the top of the PIC program:
    Code:
    DECLARE HSERIAL_BAUD  = 4800
    DECLARE HSERIAL_RCSTA = %10010000  ;bit 4 = continu receive
    DECLARE HSERIAL_TXSTA = %00100000  ;bit 5 = TXEN transmit enable)
    DECLARE HSERIAL_CLEAR = ON
    
    'and a little further:
    
    'HSerial_ChangeBaud 4800   '<< Same Baud value as above
    
    If I set the remark quote for HSerial_ChangeBaud, the program works fine at 4800 Baud. (because HSerial_ChangeBaud is now remarked, thus not active).
    If I remove the remark quote (Hserial_ChangeBaud is then active), then the same program does not work, while this should not matter, because the baud rate is the same as specified above.



    Quote Originally Posted by top204 View Post
    In your BASIC code, there is now no need for the Declares; HSERIAL_RCSTA and HSERIAL_TXSTA. The compiler automatically calculates the values for the SFRs by the Baud rate used Declare. i.e. Declare Hserial_Baud.
    I don't understand this.
    What if I want to set bit 4 from RCSTA (continu receive), or bit 5 from TXSTA (transmit enable) or other bits?


    Note:
    it is in no hurry for me to resolve this Les.
    I am quite busy, but I just want to report this.
    Maybe in the weekend I can do a few more tests.


    _____________


    OFF TOPIC:
    Quote Originally Posted by Dave Purola View Post
    I have to ask, Why are you changing the baud rate every time you run the code? Why not just set the HC05 to communicate at a fixed baud rate. There are "AT" commands to do just that and then on powerup the HC05 will already be at the correct baud rate.
    I know that Dave.
    But as far as I know you can only set the parameters from the HC05 module at 38400 Baud.
    The example above is not complete, because the question goes about HSerial_ChangeBaud.
    I only put a few HC05 commands to make the question more clear.

    What I build is a PIC program where also the parameters in the HC05 (if necessary) by the user can be changed (via a menu).
    This is only possible at 38400 Baud (as far as I know).
    But the normal communication speed isn't 38400 Baud, but lower, for example 19200, 9600 or 4800.
    That's why I need HSerial_ChangeBaud.
    Ohm sweet Ohm: www.picbasic.nl

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    59
    Thumbs Up
    Received: 14
    Given: 0
    Total Downloaded
    144.28 MB

    0 Not allowed!

    Default Re: HSerial_ChangeBaud question

    Here is the document for the HC05 Blue tooth module.

    Damm website wont let me down load the entire document because it's too big (83.7k).
    Attached Files Attached Files

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    59
    Thumbs Up
    Received: 14
    Given: 0
    Total Downloaded
    144.28 MB

    0 Not allowed!

    Default Re: HSerial_ChangeBaud question


  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Member Frizie's Avatar
    Join Date
    Apr 2003
    Posts
    174
    Thumbs Up
    Received: 12
    Given: 1
    Total Downloaded
    586.09 MB

    0 Not allowed!

    Default Re: HSerial_ChangeBaud question

    Dave,

    AT+UART is the communication speed.
    To set this kind of parameters, I do it to bring the module in AT mode.
    This has to be done only at 38400 Baud (again, as far as I know).
    The parameter itself can indeed have values from 4800...1382400 Baud (for HC05)

    Frizie.
    Ohm sweet Ohm: www.picbasic.nl

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Junior Member Dave Purola's Avatar
    Join Date
    Jul 2004
    Posts
    59
    Thumbs Up
    Received: 14
    Given: 0
    Total Downloaded
    144.28 MB

    0 Not allowed!

    Default Re: HSerial_ChangeBaud question

    Yes that is correct. After you set the required baud rate and power down the module, the next time you power it up it will be at the baud rate you set. I always send the "RESET" command before powering down the module after setting the new baud rate to verify it is not at the default baud rate. From this point on the HC05 will always be at the baud rate you set it for. It is stored in the onboard eeprom of the HC05.

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. For...next question
    By heliaddict in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 9th January 2009, 14:53
  2. Question !!!
    By eleckits in forum Proton Plus Compiler v3
    Replies: 6
    Last Post: 29th June 2007, 10:40
  3. Very OT question
    By Tim in forum The Lounge
    Replies: 6
    Last Post: 11th June 2007, 23:21
  4. [SOLVED !] question
    By ieosooo in forum The Lounge
    Replies: 1
    Last Post: 22nd May 2006, 11:56
  5. OT PC question
    By Tim in forum The Lounge
    Replies: 7
    Last Post: 24th September 2005, 12:28

Members who have read this thread : 45

Actions :  (Set Date)

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

Posting Permissions

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