The BTM-222 is a SPP (Serial Port Profile) class 1 Bluetooth module.
When BTM-222 is connected over Bluetooth, the UART of ATMEGA
is represented by virtual COM port on your computer. This is like
USB to UART adapter, but wireless.

 

The default settings of UART are as follows:

BAUD RATE: 19200bs
DATA BIT: 8
PARITY: none
STOP BIT: 1
FLOW CONTROL: none

Be sure that ATMEGA have the same settings.

 

If BTM-222 is not connected over Bluetooth, it goes to command mode and can
be configured by CPU. There is a set of AT commands for configuration:

+++
Escape
Sequence
When the device is in Data mode, it can be forced back into Command mode while maintaining the connection to the remote device. The sequence characters should be with 1000ms guard time
A
Establish connection
This command is used to establish a connection in manual master role.
A Connect to a device which has been assigned by “ATD= xxxxxxxxxxxx”
A1~A8 Connect to a device1~8 in neighborhood found through “ATF?”.
B
Display local BD address
This command display the local device BD address
B? Inquire the Local BD address
C
Flow Control
This command enable or disable flow control signals (CTS/RTS) of the COM port. Note, the setting is not affected by ATZ0 but will cause a reboot Modifiers
C0 Disable flow control.
C1 Enable flow control.
C? Inquire the current setting
D
Set remote BD address
For security purpose, We can specifies the unique remote device can be connected. In master role, it automatically inquire and search the slave even the slave is undiscoverable. In slave role, the command should be as a filter condition to accept the master’s inquiry.
D=xxxxxxxx "xxxxxxxx" is a string of 12 hexadecimal digits.
D0 Clear Remote BD address setting, inquire any slave in master mode or accept any master in slave mode.
D? Inquire the Remote BD address setting
E
Local echo
This command specifies whether the device should echo characters received from the UART back to the Host
E0 Characters received from the UART are not echoed back to the Host
E1 Characters received from the UART are echoed back to the Host.
E? Inquire the current setting
F
Find BD
This command is used to find any bluetooth device in neighborhood within 60 seconds Timeout. If any device is found, its name and address will be listed. The search ends with a message “Inquiry ends, xx device(s) found.” This command is available only when the adaptor is in the master role.
F? Inquire scan Bluetooth neighborhood devices.
H
Discoverable control
This command is used to drop connection either master or slave role. And it is used to specifiy whether the device could be discovered by remote master device. note : it will cause a reboot when ATH0 or ATH1 take the effect
H Drop current connection in Online command mode
H0 The device enters undiscoverable mode. If a pair have been made, the original connection could be connected again. Other remote master device can not discovery this device.
H1 The device enters discoverable mode.
H? Inquire the current setting
I
Information
This command is used to Inquiry the information
I0 Inquire the version Codes
I1 Listing all setting value
I2 Inquire RSSI in Online command mode
K
Stop setting
This command is used to specify one or two stop bits of COM port
K0 One Stop bit
K1 Two stop bits
K? Inquire the current setting
L
Baud rate control
This command is used to specify the baud rate of COM port
L# 1200bps
L* 2400bps
L0 4800bps
L1 9600bps
L2 19200bps
L3 38400bps
L4 57600bps
L5 115200bps
L6 230.4Kbps
L7 460.8Kbps
L8 921.6Kbps
L? Inquire the current setting
M
Parity settings
This command is used to specify the parity bit setting of COM port
M0 None Parity bit.
M1 Odd parity setting.
M2 Even parity setting
M? Inquire the current setting
N
Set name
We can specifies the device a friendly name using 0 to 9, A to Z, a to z, space and –, which are all valid characters. Note that "firs space or -, last space or – isn’t permitted". The default name is “Serial Adaptor”
N=xxxxx "xxxxx" is a character string, maxima length is 16
N? Inquire the device name
O
Auto connect setting
This command is used to enable/disable auto-connection feature in master role. By the way, it is used to online switch from command mode to data mode. Note, it will cause a reboot when ATO0 or ATO1 take effect.
O Online switch from command mode to data mode
O0 Automatically connectting to a device which is assigned in “ATD” or any available device if “ATD” was not assigned.
O1 Disable auto-connection feature, user should manually use “ATA” command to connect a remote device.
O? command to connect a remoteInquire the current setting
P
Set pin code
This command specifies the PIN number. It control to off the PIN code authorization that allow to establish a connection without PIN code. Default PIN number is "1234"
P=xxxx "xxxx" is 4~8 digit string
P0 Turn off the PIN code authorization
P? Inquire the current PIN number
Q
Result code supression
The command is used to determine if result Codes should be sent to the Host. When result Codes are supressed, the device does not generate any characters in response to the completion of a command or when an event occurs. Four Result Codes : OK,CONNECT,DISCONNECT,ERROR
Q0 The device will prompt Result Codes
Q1 The device will not prompt Result Codes
Q? Inquire the current setting
R
Set role
This command specifies whether the device could be master or slave device. If change the role, the adaptor will reboot and clear all paired addresses.
R0 The device as master role.
R1 The device as slave role.
R? Inquire the current setting
Z
Restore
This command is used to restore default setting and reboot
Z0 Restore the default setting
The underlined options are set by default. Command consist of AT and ending.
To perform command, send AT + ending, for example to set device to master role send:
ATR0
and add carriage return at end (ASCII 13).
If the command was successful, the module sends OK otherwise ERROR
To test connection you can send AT and should receive OK