板载的蓝牙+WiFi模块(村田LBEE5KL1DX-883)芯片是CYW4343W,规格是WiFi4(IEEE 802.11n)和蓝牙5.1(BE/EDR+BLE双模),这里STM32H747XI作host,CYW4343W做RCP射频协处理器,各自的控制通道不一样,WLAN是SDIO v3,Bluetooth是HCI,其中BLE就是UART7来下发HCI命令的,

试了下mbed的例程包括Firmata->StandardFirmataBLE并没有适配Giga R1 WiFi,需要自己区定义HAL,尝试了一下报很多错误,这里想起来ArduinoBLE本身就有BLE库,于是导入之后用BLE成功添加GATT数据库、广播并建立连接,

代码如下:
void setup() {
Serial.begin(9600);
while (!Serial);
// set LED pin to output mode
pinMode(ledPin, OUTPUT);
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("Arduino Giga R1 Wifi");
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);
// add service
BLE.addService(ledService);
// set the initial value for the characteristic:
switchCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for Bluetooth® Low Energy peripherals to connect:
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
// print the central's MAC address:
Serial.println(central.address());
// while the central is still connected to peripheral:
while (central.connected()) {
// if the remote device wrote to the characteristic,
// use the value to control the LED:
if (switchCharacteristic.written()) {
if (switchCharacteristic.value()) { // any value other than 0
Serial.println("LED on");
digitalWrite(ledPin, LOW); // will turn the LED off
} else { // a 0 value
Serial.println(F("LED off"));
digitalWrite(ledPin, HIGH); // will turn the LED on
}
}
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
}
}
我要赚赏金
