Shop OBEX P1 Docs P2 Docs Learn Events
Help with Bluetooth — Parallax Forums

Help with Bluetooth

mynet43mynet43 Posts: 644
edited 2011-12-10 07:10 in Propeller 1
I have two of the Parallax Easy Bluetooth modules (#30085).

I'm doing my best to get them to talk to each other, using the code examples given in the Parallax App Note.

The sample code is given in BASIC for the BOE. I've translated this to spin for the Prop and downloaded the transmit and receive routines into the two Prop Demo boards I'm using. I'm able to send data from my PC to the receive Bluetooth module, so I know it's basically working. On the transmit module, the Bluetooth light is blinking as I tell it to send out data, so I think it's working. But they aren't communicating.

I've included debug output for each module, using two PST screens. These seem to both be working fine.

These modules are supposed to be easy to work with, using just a standard serial interface. Would someone please take a look at my code to see if you can see what I'm doing wrong? I also attached a screen shot, showing the receiver Bluetooth Device Address from my PC control panel.

Here's the receive code:
{
BT-receiver.spin 
}                                                                          

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

BRX     = 1                     ' Bluetooth Rx
BTX     = 0                     ' Bluetooth Tx
baud    = 38_400                ' Bluetooth serial baud rate

VAR                                              
  byte rxbyte                   ' Bluetooth string data
   
  
OBJ
  serio : "FullDuplexSerialPlus"
  debug : "FullDuplexSerialPlus"

DAT
  sw_ver byte "1.02",0           ' software version number

PUB Bluetooth | count
  waitcnt(clkfreq*10+cnt)       ' wait until BT initialized for transparent input
  initialize
  
  repeat
    debug.str(string("*"))      ' show that we're here, in case stuck in rx routine
    rxbyte := serio.rx          ' wait for byte from Bluetooth
    
    debug.tx(rxbyte)            ' display on terminal screen
    debug.str(string(" "))

    if count++ == 20            ' new line every 20 characters
       count := 0
       debug.tx(13)

PRI initialize
  serio.start(BRX,BTX,0,baud)   ' start Bluetooth I/O
  debug.start(31,30,0,115200)   ' start debug output
  waitcnt(clkfreq/4+cnt)


Here's the transmit code:
{
BT-transmitter.spin 
}                                                                          

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

BRX     = 1                     ' Bluetooth Rx
BTX     = 0                     ' Bluetooth Tx
baud    = 38_400                ' baud to Bluetooth device

OBJ
  serio : "FullDuplexSerialPlus"
  debug : "FullDuplexSerialPlus"

DAT
  sw_ver      byte "1.01 ",0    ' software version number
 
  bltest      byte "testing ",0

              ' BT receiver ID is:              00: 17: A0: 01: 6C: 94 reverse
  est_lnk     byte $02,$52,$0A,$08,$00,$64,$01,$94,$6C,$01,$A0,$17,$00,$01,$03
  trans_cmd   byte $02,$52,$11,$01,$00,$64,$01,$03 ' transparent command

PUB Bluetooth | count
  initialize
 
  debug.str(string(13,"Start Transmitting Data:",13))
  count := 33                   ' start with '!'
  
  repeat
    serio.tx(count)             ' output Bluetooth character
    debug.tx(count++)           ' send same data to terminal screen
    debug.str(string(" "))      ' space
    if count == 127             ' stop here, last regular character
       count := 33              ' reset to '!' character
       debug.tx(13)             ' new line to terminal
    waitcnt(clkfreq+cnt)      ' wait a second between outputs

PRI initialize
  serio.start(BRX,BTX,0,baud)   ' start Bluetooth serial output
  debug.start(31,30,0,115200)   ' start debug output
  waitcnt(clkfreq/4+cnt)
  
  debug.str(string(13,"Establish Link",13))
  send_cmd(@est_lnk)            ' establish link
  waitcnt(clkfreq*5+cnt)

  debug.str(string(13,"Transparent Mode",13))
  send_cmd(@trans_cmd)          ' transparent mode command for serial xfr
  waitcnt(clkfreq*3+cnt)

PRI send_cmd(bt_cmd_adr) | i    ' send transparent mode command to Bluetooth
  debug.str(string(13,"Start Send Command",13))
  
  repeat i from 0 to 63         ' send 8 command code message
    serio.tx(byte[bt_cmd_adr][i])      ' send the ith code data to BT receiver
    
    debug.hex(byte[bt_cmd_adr][i],2)   ' display the code
    debug.str(string(" "))             ' space
    if byte[bt_cmd_adr][i] == $03      ' end of message
      quit
     
  debug.tx(13)                  ' new line for terminal  
  debug.str(string("Exit Send Command",13))


Thank you for your help and support.

Jim
Sign In or Register to comment.