Component: Bluetooth (EB024, Generic AT) (Wireless)

From Flowcode Help
Revision as of 15:45, 16 February 2017 by BenR (talk | contribs) (XML import BR)
Jump to navigationJump to search


Author Matrix Ltd.
Version 1.2 (Release)
Category Wireless


Image Bluetooth (EB024, Generic AT) component

Low level routines for controlling a standard AT Bluetooth interface. Also available in the form of the EB024 Bluetooth E-block.

Examples

Making a device discoverable

Example program to set up the Bluetooth module to be discoverable with a pair key. Any data received is then output onto the LCD component. You can connect to the Bluetooth device using a PC with Bluetooth connection and using software such as Flowcode 6, RealTerm or HyperTerminal. Alternatively you can connect using a smart phone running a terminal emulator app or via another embedded Bluetooth board. FC6 Icon.png Bluetooth Discover Script 1 contains the AT commands to setup the Bluetooth device to be discoverable with pair key "1234".

DiscoverableScript.jpg


Searching for a device

Example program to scan for local discoverable Bluetooth devices. For each device found the MAC address is displayed on to the LCD. FC6 Icon.png Bluetooth Inquiry

Connecting to a device

Example program to connect to a specific Bluetooth device address and send data to the device. FC6 Icon.png Bluetooth Connect The device MAC address is specified using the "CreateCommandString" and "SendCommand" macros.

ConnectToMAC.jpg

Downloadable macro reference

StringRead

Returns the ASCII value of character idx of the Response string.

Parameters

BYTE idx
Needs to be a equal to or less than the string length of the response in order to retrieve a valid character.


Return value

BYTE


SendScript

Sends Script idx

Note that the general property Number of Scripts needs to be set so that it allows the scripts to be accessed and sent.

Returns 0 for success and 1 for error

Parameters

BYTE idx
Refers to the Script page to send (1-4).


Return value

BYTE


SendCommand

Sends the command buffer.

Returns 1 for success in sending the command.

Returns 0 for errors.

Parameters

BYTE ExpectEcho
Remote module automatically echos back data: 1 = On (Expect echo), 0 = off
BYTE SendCR
Automatically adds \n to the end of the command data: 1 = append CR, 0 = no CR.


Return value

BYTE


CreateCommandString

Assigns a string of characters to the Command buffer.

Returns 1 for success in adding the characters to the buffer.

Returns 0 for errors, including Buffer overflow.

Parameters

<- STRING Data
This parameter may be returned back to the caller


Return value

BYTE


StringReceive

Checks for a response string.

Returns the length of the response string if one is present otherwise returns 0.

Parameters

This macro has no parameters


Return value

BYTE


CreateCommand

Adds a single characters to the end of the Command buffer.

Returns 1 for success in adding the characters to the buffer.

Returns 0 for errors, including Buffer overflow.

Parameters

BYTE Character
ASCII value or single character,


Return value

BYTE


Send_byte

No additional information


Parameters

BYTE ByteVal


Return value

This call does not return a value


WaitForResponse

Waits for a response message of type response_code for timeout ms.

Returns: 0 for a Response of type response_code

255 (0xFF) for a timeout or invalid response

Response string length for any Response not of type response_code

Parameters

BYTE response_code
1:OK / 2:ERROR / 3:CONNECT / 4:NO CARRIER / 5:AUDIO / 6:PAIR / 7:RING
BYTE timeout
The timeout value will need to set to allow sufficient time for the response to arrive.


Return value

BYTE


Initialise

Required to be used whenever the Bluetooth component is used in a program.

Initialises the Bluetooth component ready for use.

Parameters

This macro has no parameters


Return value

This call does not return a value


Simulation macro reference

This component does not contain any simulation macros


Property reference

Channel

This property is of type Fixed list of ints and can be referenced with the variable name CHANNEL.

UART Comms Channel

Flow Control

This property is of type Fixed list of ints and can be referenced with the variable name FLOWEN.

Determines if flow control is enabled or not

Baud Rate

This property is of type Fixed list of ints and can be referenced with the variable name BAUD_LIST.

UART baud rate, specified by Bluetooth module - normally 9600 is the default

Command Buffer Size

This property is of type Unsigned integer and can be referenced with the variable name CommandBufferSize.

Maximum number of bytes that can be stored in the outgoing command buffer.

Response Buffer Size

This property is of type Unsigned integer and can be referenced with the variable name ResponseBufferSize.

Maximum number of bytes that can be stored in the incoming response buffer.

Script Count

This property is of type Fixed list of ints and can be referenced with the variable name SCRIPTS.

Controls how many AT scripts are stored into non-volatile memory

Script 1

This property is of type Multiple lines of text and can be referenced with the variable name SCRIPT1.

Data to send for script 0, each command should be terminated with a carriage return

TX

This property is of type Single digital pin and can be referenced with the variable name TX.

UART transmit pin

RX

This property is of type Single digital pin and can be referenced with the variable name RX.

UART receive pin

Data Source

This property is of type Fixed list of ints and can be referenced with the variable name DataSource.

Simulation data source

Injector

This property is of type Fixed list of ints and can be referenced with the variable name Injector.

Injector component to connect as data end point