一、硬件介绍
SYN6288是一款语音播报芯片,可以将文字转化为语音并通过喇叭播放。
二、引脚连接
模块引脚如下:可见通信方式为串口
模块引脚定义如下:
BN0和BP0:接喇叭
BUSY:忙信号检测,可不接
TX:接单片机RX
RX:接单片机TX
三、软件实现
1. 串口配置
本例程通过串口2进行测试。
void bsp_usart3_gpioConfig(void)
{
rcu_periph_clock_enable(BSP_USART3_GPIO_RCU);
gpio_af_set(BSP_USART3_TX_PORT, GPIO_AF_7, BSP_USART3_TX_PIN);
gpio_af_set(BSP_USART3_RX_PORT, GPIO_AF_7, BSP_USART3_RX_PIN);
gpio_mode_set(BSP_USART3_TX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, BSP_USART3_TX_PIN);
gpio_output_options_set(BSP_USART3_TX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BSP_USART3_TX_PIN);
gpio_mode_set(BSP_USART3_RX_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, BSP_USART3_RX_PIN);
gpio_output_options_set(BSP_USART3_RX_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, BSP_USART3_RX_PIN);
}
void bsp_usart3_usartConfig(uint32_t bound)
{
rcu_periph_clock_enable(BSP_USART3_RCU);
usart_deinit(BSP_USART3_USART);
usart_baudrate_set(BSP_USART3_USART, bound);
usart_receive_config(BSP_USART3_USART, USART_RECEIVE_ENABLE);
usart_transmit_config(BSP_USART3_USART, USART_TRANSMIT_ENABLE);
usart_enable(BSP_USART3_USART);
}
2. SYN6288播放函数
static uint8_t dri_syn6288_sendText(uint8_t backSound,uint8_t *text)
{
uint8_t tempBuf[DRI_SYN6288_BUFFER_LENGTH],i,crc = 0;
uint16_t textLength;
textLength = strlen((uint8_t*)text);
tempBuf[0] = 0xFD;
tempBuf[1] = 0x00;
tempBuf[2] = (textLength & 0xff) + 3;
tempBuf[3] = 0x01;
tempBuf[4] = 0x01|(backSound << 4);
for(i = 0; i < 5; i++)
{
crc = crc ^ tempBuf[i];
}
for(i = 0; i < textLength; i++)
{
crc = crc ^ text[i];
}
memcpy(&tempBuf[5], text, textLength);
tempBuf[5 + textLength] = crc;
DRI_SYN6288_SEND_BUFFER(tempBuf,5 + textLength + 1);
}
原作者:卢阿涛
|