CC2541 迷你开发套件使用心得分享+ my love
[复制链接]
一个SimpleBLEPeripheral项目。用到了UART,蓝牙通信不是用的串口,CC2541实现蓝牙通信可以不用串口。
attWriteReq_t req;
req.pValue = GATT_bm_alloc( simpleBLEConnHandle, ATT_WRITE_REQ, 1, NULL );
if ( req.pValue != NULL )
{
req.handle = simpleBLECharHdl;
req.len = 1;
req.pValue[0] = simpleBLECharVal;
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
蓝牙主模块、CC2541连接成功。
CC2541往蓝牙主模块发送数据,蓝牙主模块是可以接收到的。
发送代码:
if(BL_Flag==9)
{
BL_Flag=0;
HAL_UART_Transmit (&huart1 ,(uint8_t *)(START),1,1500);
flag=1;
}
if(BL_Flag==1)
{
BL_Flag=0;
HAL_UART_Transmit (&huart1 ,(uint8_t *)(STO),1,1500);
}
接收代码:
attWriteReq_t req;
req.pValue = GATT_bm_alloc( simpleBLEConnHandle, ATT_WRITE_REQ, 1, NULL );
if ( req.pValue != NULL )
{
req.handle = simpleBLECharHdl;
req.len = 1;
req.pValue[0] = simpleBLECharVal;
req.sig = 0;
req.cmd = 0;
status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId );
|