SA818 Programming Manual
SA818 Programming Manual
com SA818
which means: Baud = 9600, data bit = 8bit, Parity = None, Stop bit = 1 bit. The interface is TTL or CMOS @3.3V. The
parameters which can be configured are: Bandwidth, Tx-frequency, Rx-frequency, SQ, Tx_SubAudio(Tx_CTCSS/
Tx-CDCSS), Rx_SubAudio (Rx_CTCSS/Rx-CDCSS), Volume, Scan frequency, Audio filter, etc. When commands received,
the module will verify and reply acknowledge message; User should wait enough time to send the next command until
2. Commands List:
There are 5 commands in total to be used, below is the list:
Format:AT+DMOCONNECT <CR><LF>
Reply:+DMOCONNECT:0<CR><LF>
Parameter Description:
If 0000 is set, that means subaudio function is disable. No CTCSS and no CDCSS.
The range of Tx_CTCSS and Rx_ctcss is 1—38.
Please find below table for Tx_CDCSS and Rx_CDCSS. The table is only list the code ended with “I”, the code ended with
“N” is not shown. Actually the code ended with “N” can be used without any problems.
The code ended with “N” is the complement of the code ended with “I”.
For example:
023I = 11001000000111000110111
023N=~023I=00110111111000111001000
SQ: 0 ~ 8
0: listen mode
1—8: Different SQ Level.
3.4)Volume Configuration
Format:AT+DMOSETVOLUME=X
Reply: +DMOSETVOLUME: 0
“X” is the volume level, the range is 1---8.
Example:AT+DMOSETVOLUME=1
Reply: +DMOSETFILTER: X
“X”:
0: command succeed,
1: command failed
PRE/DE-EMPH:
1: emphasis bypass
0: emphasis normal
HIGHPASS:
1: voice_highpass_filter_bypass
0: voice_highpass_filter normal
LOWPASS:
1: voice_lowpass_filter_bypass
0: voice_lowpass_filter normal
For example:
AT+SETFILTER=0, 0, 0
+DMOSETFILTER: 0
Format: AT+SETTAIL=TAIL
Reply: +DMOSETTAIL: X
“X”:
0: command succeed,
1: command failed
TAIL:
For example:
AT+SETTAIL=0
+DMOSETTAIL: 0
Format: RSSI?
Reply: RSSI=X
“X”:
For example:
In ASCII:
RSSI?
RSSI=128
In HEX:
0x52 0x53 0x53 0x49 0x3D 0x31 0x32 0x38 0x0d 0x0a
Format: AT+VERSION
Reply: +VERSION:SA818_VX
“X”:Version of module
For example:
AT+VERSION
+VERSION:SA818_V4.0
Hex Bit
Transform Bit Pattern
Code Pattern
10
11
12
13
14
15
16
//========================
RAM DEFINE
Const unsigned char
CMD_HAND[15]={0x41,0x54,0x2B,0x44,0x4D,0x4F,0x43,0x4F,0x4E,0x4E,0x45,0x43,0x54,0x0d,0x0a};
unsigned char CMD_SET[15]={0x41,0x54,0x2b,0x44,0x4d,0x4f,0x53,0x45,0x54,0x47,0x52,0x4f,0x55,0x50,0x3d};
unsigned char
CMD_VOLUME[16]={0x41,0x54,0x2B,0x44,0x4D,0x4F,0x53,0x45,0x54,0x56,0x4f,0x4c,0x55,0x4d,0x45,0x3d};
unsigned char tx_buf[50]={0};
unsigned char rx_buf[30]={0};
unsigned char tx_len;
unsigned char rx_len;
unsigned char len_txnow;
unsigned char len_rxnow;
unsigned char status_cnt = 2;
//=======================================================
17
void uart_init()
// MCU UART Initialization (set to standard format)
{
SPBRGH = 0;
SPBRG = 23;
TXSTA = 0;
RCSTA = 0x90;
BAUDCON = 0;
TXIE = 0;
RCIE = 0;
}
//------------------------------------------------
void check_uart()
// send handshake instruction to module regularly to detect the module's connection status
{
unsigned char i;
if(Flag.in_rx == 1)
18
{
rx_cnt --;
if(rx_cnt == 0)
{
Flag.in_rx = 0;
Flag.in_tx = 0;
Flag.cn_fail = 1;
LED_CTCS = LED_OFF;
Flag.poweron = 1;
fresh_display();
return;
}
}
if((Flag.in_tx == 1)||(Flag.in_rx == 1)) // No interleave sending instruction, to ensure the module properly receiving
instruction.
return;
send_hand();
}
19
//------------------------------------------------
void uart_trans_check(void)
// judge the transmitting instructions is complete or not
{
if((Flag.in_tx == 1)&&(len_txnow > tx_len)&&(TXIF == 1))
{
stop_TX();
// Send over, close the sending UART function.
Flag.in_tx = 0;
Flag.in_rx = 1;
rx_cnt = 2;
len_txnow = 0;
len_rxnow = 0;
tx_len = 0;
clr_tx_buf();
// Initializes the related registers and flags
start_RX();
// receiving function is available
20
}
}
//------------------------------------------------
void uart_recv_ack(void)
{
if(Flag.in_rx == 0)
return;
if(len_rxnow == rx_len)
{
Flag.in_rx = 0;
if((rx_buf[rx_len-3] == 0x30)&&(rx_buf[rx_len-2] == 0x0d)&&(rx_buf[rx_len-1] == 0x0a))
21
stop_RX();
if((rx_len == 15)&&(Flag.poweron))
{
Flag.reset = 1;
Flag.poweron = 0;
}
return;
}
else if(Flag.cn_fail == 1)
return;
else
{
status_cnt -= 1;
if(status_cnt == 0)
// If the Continuous instruction returns null, the module connection failed flag bit
{
Flag.cn_fail = 1;
LED_CTCS = LED_OFF;
22
Flag.poweron = 1;
}
}
}
}
//------------------------------------------------
void send_hand()
{
unsigned char i;
for(i=0;i<=14;i++)
tx_buf[i] = CMD_HAND[i];
// Load the handshake instruction
rx_len = 15;
tx_len = 15;
// Write handshake instruction to send and receive data bytes
len_txnow = 0;
Flag.in_tx = 1;
23
clr_rx_buf();
// Clear the receive buffer
start_TX();
// send UART function is available
}
//------------------------------------------------
void send_set()
{
unsigned char i;
for(i=0;i<=14;i++)
tx_buf[i] = CMD_SET[i];
tx_buf[15] = ASCII(Flag.gbw);
tx_buf[16] = ASCII_comma;
ASCII_TFV();
tx_buf[25] = ASCII_comma;
ASCII_RFV();
tx_buf[34] = ASCII_comma;
24
tx_buf[35] = ASCII(Tx_ctcs_3);
tx_buf[36] = ASCII(Tx_ctcs_2);
tx_buf[37] = ASCII(Tx_ctcs_1);
tx_buf[38] = ASCII(Tx_ctcs_0);
tx_buf[37] = ASCII_comma;
tx_buf[38] = ASCII(sq);
tx_buf[39] = ASCII_comma;
tx_buf[40] = ASCII(Rx_ctcs_3);
tx_buf[41] = ASCII(Rx_ctcs_2);
tx_buf[42] = ASCII(Rx_ctcs_1);
tx_buf[43] = ASCII(Rx_ctcs_0);
// Instruction of sending data are ASCII
tx_buf[44] = 0x0d;
tx_buf[45] = 0x0a;
// Send instructions all ends with a carriage return line feed(0X0D,0X0A)
rx_len = 16;
tx_len = 46;
// Write handshake instruction to send and receive data bytes
25
len_txnow = 0;
Flag.in_tx = 1;
clr_rx_buf();
start_TX();
}
//------------------------------------------------
void send_vol()
{
unsigned char i;
for(i=0;i<=15;i++)
tx_buf[i] = CMD_VOLUME[i];
// load volume instruction
tx_buf[16] = ASCII(vol);
tx_buf[17] = 0x0d;
tx_buf[18] = 0x0a;
rx_len = 17;
tx_len = 19;
26
// write number of bytes to set the volume orders to send and receive data
len_txnow = 0;
Flag.in_tx = 1;
clr_rx_buf();
start_TX();
}
//------------------------------------------------
void clr_tx_buf()
// Clear the send buffer
{
unsigned char i;
for(i=0;i<=39;i++)
tx_buf[i]=0;
}
//------------------------------------------------
void clr_rx_buf()
// Clear the receive buffer
27
{
unsigned char i;
for(i=0;i<=18;i++)
rx_buf[i] = 0;
}
//------------------------------------------------
void start_TX()
// to make it can send UART
{
TXEN = 1;
TXIE = 1;
}
//------------------------------------------------
void stop_TX()
// close UARTsending
{
TXEN = 0;
28
TXIE = 0;
}
//------------------------------------------------
void start_RX()
// to make it can receive UART
{
CREN = 1;
RCIE = 1;
}
//------------------------------------------------
void stop_RX()
// close UART receiving
{
CREN = 0;
RCIE = 0;
}
//------------------------------------------------
void interrupt ISR_timer(void)
29
// interrupt handling
{
unsigned char int_temp;
if(TXIF)
{
if(Flag.in_tx == 0)
stop_TX();
// Not in delivery status, interrupted by mistake
else if(len_txnow <= tx_len)
{
TXREG = tx_buf[len_txnow];
// update sending data
len_txnow ++;
}
else
TXIE = 0;
// send over
30
if(RCIF)
{
NOP();
if(Flag.in_rx)
{
rx_buf[len_rxnow] = RCREG;
// write the returned dato to receive buffer
if((len_rxnow++) == (rx_len+1))
stop_RX();
}
else
// Not in receiving state, interrupted by mistake, invalid return values
{
stop_RX();
int_temp = RCREG;
}
31
}
}
32