Hserout/Hserin via bluetooth


Results 1 to 6 of 6

Threaded View

  1. #1

    Default Hserout/Hserin via bluetooth

    Hello boys,

    I need a little alignment about serial communication via HC-5 bluetooth modules. I try to send via bluetooth 8bit ADC value from one MCU to another MCU and this value feed to MCP41010 digital pot.
    I succesfully setuped and paired the bluetooth modules but I have trouble with receiving data. If I feed the data on receiver side to serial monitor on PC I saw changing correct values from 0 to 255 as I changing the pot value on transmitter side.
    But in "datain" variable (on LCD) I dont have a correct value like 0 to 255. Value from 0 to 9 is correct but next is "random" numbers.
    What is the right way to receive these value to datain variable?

    Thanks.

    The codes for
    receiver:
    Code:
    ; device PIC 16F688 
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
     __CONFIG cfg
    #ENDCONFIG
     
    DEFINE OSC 8      ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    
    DEFINE HSER_RCSTA 90h ; Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ; Enable transmit, BRGH = 1
    DEFINE HSER_BAUD 9600 ; 9600 Baud
    DEFINE HSER_CLROERR 1 ; Clear overflow automatically
    
    Define LCD_DREG PORTC
    Define LCD_DBIT 0
    Define LCD_RSREG PORTA
    define LCD_RSBIT 4
    define LCD_EREG PORTA 
    define LCD_EBIT 5 
    define LCD_BITS 4
    define LCD_LINES 2
    define LCD_COMMANDUS 2000
    define LCD_DATAUS 50
    
    ANSEL = 0          ; Set all digital
    CMCON0 = 7
    TRISA = %000000    ; Set all output
    TRISC = %000001    ; Set RC.5 input
    
    SCK     var     PORTA.0     ; Alias PORTA.0 to SCK (serial data clock)
    SDO     var     PORTA.1     ; Alias PORTA.1to SDO (serial data out)
    CS      var     PORTA.2     ; Alias PORTA.2 to C_EN (chip enable)
    
    datain var byte
    
    PAUSE 500 : LCDOUT $FE,1 : PAUSE 250 ; Initialize LCD  
    HIGH    CS                           ;Chip enable high to start MCP41010 digital pot
    high    sck                          ; Mode 1,1 SCK idles high
    pause 10
     
    Pot0 con %00010001                   ; digital pot command setting
    
    Main:
    LCDOUT $FE,1
    HSerin 500,main,[dec datain]         ; read from bluetooth. Value between 0 - 255
    pause 30
    lcdout $FE,$80,dec datain            ; lcd out only for information
    pause 30
    
    low CS                                ; Make digital pot chip active
    pause 1                              
    shiftout  sdo,sck,5,[pot0,datain]     ; Mode 1,1 / Mode 5 - clock idles high, datain value shift out
    high CS 
    pause 1
    
    goto main
    transmitter:
    Code:
    ; device PIC 16F688
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
     __CONFIG cfg
    #ENDCONFIG
                               
    DEFINE OSC 8            ; Use a 8 MHZ internal clock 
    OSCCON = %01110000
    
    Define ADC_BITS     8   ; Set number of bits in result
    Define ADC_CLOCK    3   ; Set clock source (3=rc)
    Define ADC_SAMPLEUS 50  ; Set sampling time in uS
    
    DEFINE HSER_RCSTA 90h ; Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ; Enable transmit, BRGH = 1
    DEFINE HSER_BAUD 9600 ; 9600 Baud
    DEFINE HSER_CLROERR 1 ; Clear overflow automatically
    
    adval var byte
    
    ANSEL = %10000000   ; Set AN7 analog input, rest digital
    CMCON0 = 7
    TRISA = %000000    ; Set all output
    TRISC = %001000    ; Set RC4 output TX pin
    
    let adval = 0
    
    main:
    ADCIN 7, adval
    pause 20
    hserout [dec adval,10]   ; hserout adval to bluetooth HC-05
    pause 20
    GOTO Main
    Last edited by louislouis; - 31st January 2017 at 21:01.

Similar Threads

  1. HSERIN and HSEROUT Pins
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd March 2014, 21:08
  2. Problem with HSEROUT/HSERIN
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd July 2013, 09:43
  3. HSERIN and HSEROUT problems
    By amindzo in forum General
    Replies: 2
    Last Post: - 31st August 2006, 06:51
  4. Hserin/hserout ?
    By Scott in forum General
    Replies: 6
    Last Post: - 27th April 2005, 23:46
  5. Bluetooth wireless with PIC / HSERIN / DAC
    By rpatel in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th December 2004, 22:13

Members who have read this thread : 0

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