ESP32 Bluetooth is working. How to use Interrupt?

For general Flowcode discussion that does not belong in the other sections.
stefan.erni
Valued Contributor
Posts: 756
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

ESP32 Bluetooth is working. How to use Interrupt?

Post by stefan.erni »

Hi Ben

I did the change you wrote in

viewtopic.php?f=5&t=16


#
# Bluetooth controller
#
# CONFIG_BTDM_CTRL_MODE_BLE_ONLY is not set
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y
# CONFIG_BTDM_CTRL_MODE_BTDM is not set
Now Bluetooth is working with my samsung phone and with my computer.

How can I use a RX interrupt?

What about the speed from the SPP? My terminalprogram is always working even if I choose 9600Bd or 115000Bd

regards

Stefan

BenR
Matrix Staff
Posts: 1733
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 439 times
Been thanked: 602 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by BenR »

Hi Stefan,
What about the speed from the SPP? My terminalprogram is always working even if I choose 9600Bd or 115000Bd
The data is sent digitally via the SPP protocol at the SPP data baud rate and as such is never output as a digital signal in bits per second hence the baud rate on the terminal program makes no difference.
How can I use a RX interrupt?
We are currently working on UART interrupts but this wouldn't work with the SPP Bluetooth component. I'll see if there is a way of enabling an interrupt so you don't have to poll the component for incoming data.

stefan.erni
Valued Contributor
Posts: 756
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by stefan.erni »

Hi Ben
I'll see if there is a way of enabling an interrupt so you don't have to poll the component for incoming data.
Did you found a way for the interrupt?


I wrote a small program. It's connect a Pic32mz via uart to a ESP32 . The ESP32 is connected to the computer with USB C.

It's simple to send a string from the PIC to the computer (via ESP) and from the computer to the PIC (via ESP).

this is made with Interrupt on the both UART.

So the goal is to do the same but in the ESP32 to use the Bluetooth with interrupt.

ps; I used the M5 Atom with the groove connector to connect to the PIC32

Regards

Stefan
FC9_M5STACK Modul Atom Matrix_uart2fcfx.fcfx
(23.18 KiB) Downloaded 140 times

BenR
Matrix Staff
Posts: 1733
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 439 times
Been thanked: 602 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by BenR »

Hi Stefan,

I've upgraded the ESP32 Bluetooth SPP component and CAL now and added both COM Port simulation and RX interrupt support. Just enable the interrupt and select the interrupt callback macro using the component properties.

Please note that the callback macro should have no parameters and also please note that there might not be a 1:1 on bytes received and callbacks if a number of bytes are received in one go. Use the ReceiveCount macro to determine how many bytes have been received.

Let me know how you get on.

stefan.erni
Valued Contributor
Posts: 756
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by stefan.erni »

Hi Ben

If I init the Bluetooth_SPP_ESP32 an compile to the chip, the uart(USB) is sending nonstop even I did not send data
When I remove the Bluetooth_SPP_ESP32 init it's ok again.

rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)<\r><\n>
configsip: 188777542, SPIWP:0xee<\r><\n>
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00<\r><\n>
mode:DIO, clock div:2<\r><\n>
load:0x3fff0030,len:7064<\r><\n>
load:0x40078000,len:14292<\r><\n>
load:0x40080400,len:3688<\r><\n>
entry 0x40080678<\r><\n>
<27>[0;32mI (54) boot: ESP-IDF v4.3 2nd stage bootloader<27>[0m<\r><\n>
<27>[0;32mI (54) boot: compile time 15:34:55<27>[0m<\r><\n>
<27>[0;32mI (54) boot: chip revision: 1<27>[0m<\r><\n>
<27>[0;32mI (57) boot_comm: chip revision: 1, min. bootloader chip revision: 0<27>[0m<\r><\n>
<27>[0;32mI (64) boot.esp32: SPI Speed : 40MHz<27>[0m<\r><\n>
<27>[0;32mI (69) boot.esp32: SPI Mode : DIO<27>[0m<\r><\n>
<27>[0;32mI (73) boot.esp32: SPI Flash Size : 2MB<27>[0m<\r><\n>
<27>[0;32mI (78) boot: Enabling RNG early entropy source...<27>[0m<\r><\n>
<27>[0;32mI (83) boot: Partition Table:<27>[0m<\r><\n>
<27>[0;32mI (87) boot: ## Label Usage Type ST Offset Length<27>[0m<\r><\n>
<27>[0;32mI (94) boot: 0 nvs WiFi data 01 02 00009000 00006000<27>[0m<\r><\n>
<27>[0;32mI (102) boot: 1 phy_init RF data 01 01 0000f000 00001000<27>[0m<\r><\n>
<27>[0;32mI (109) boot: 2 factory factory app 00 00 00010000 00100000<27>[0m<\r><\n>
<27>[0;32mI (117) boot: End of partition table<27>[0m<\r><\n>
<27>[0;32mI (121) boot_comm: chip revision: 1, min. application chip revision: 0<27>[0m<\r><\n>
<27>[0;32mI (128) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=347e4h (215012) map<27>[0m<\r><\n>
<27>[0;32mI (218) esp_image: segment 1: paddr=0004480c vaddr=3ffbdb60 size=05014h ( 20500) load<27>[0m<\r><\n>
<27>[0;32mI (226) esp_image: segment 2: paddr=00049828 vaddr=40080000 size=067f0h ( 26608) load<27>[0m<\r><\n>
<27>[0;32mI (238) esp_image: segment 3: paddr=00050020 vaddr=400d0020 size=e56b4h (939700) map<27>[0m<\r><\n>
<27>[0;32mI (593) esp_image: segment 4: paddr=001356dc vaddr=400867f0 size=186d8h (100056) load<27>[0m<\r><\n>
<27>[0;32mI (636) esp_image: segment 5: paddr=0014ddbc vaddr=50000000 size=00010h ( 16) load<27>[0m<\r><\n>
<27>[0;31mE (636) esp_image: Image length 1302000 doesn't fit in partition length 1048576<27>[0m<\r><\n>
<27>[0;31mE (641) boot: Factory app partition is not bootable<27>[0m<\r><\n>
<27>[0;31mE (646) boot: No bootable app partitions in the partition table<27>[0m<\r><\n>
ets Jun 8 2016 00:22:57<\r>

BenR
Matrix Staff
Posts: 1733
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 439 times
Been thanked: 602 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by BenR »

Hello,

This one is working well for me without spamming the console.
ESP32 BluetoothRXIntDemp.fcfx
(11.96 KiB) Downloaded 176 times
If you're getting console spam then it could be the watchdog timer is resetting the board. Make sure you have a sizable delay in your main program loop.

Or if you want to force watchdog clears then maybe you can do this.
https://www.flowcode.co.uk/forums/viewt ... ?f=3&t=646

stefan.erni
Valued Contributor
Posts: 756
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by stefan.erni »

Hi Ben

I have a delay in the main loop.... I will have a look what else I did wrong.

Your program is working but to much answer.

I send Hallo\r\n
and receive much more

from my terminal program:
<27>[0;32mI (185433) BT_SPP: ESP_SPP_DATA_IND_EVT len=7 handle=129<27>[0m<\r><\n>
Hallo<\r><\n>
<27>[0;32mI (186433) BT_SPP: event: 13<27>[0m<\r><\n>
<27>[0;32mI (193653) BT_SPP: event: 13<27>[0m<\r><\n>

BenR
Matrix Staff
Posts: 1733
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 439 times
Been thanked: 602 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by BenR »

Hi Stefan,

Aha ok I see, I could add a property that would allow the verbose Bluetooth debug to be switched on or off if that would help. Probably same for WIFI too.

stefan.erni
Valued Contributor
Posts: 756
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 149 times
Been thanked: 171 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by stefan.erni »

Hi Ben

Yes please add a property and also add a property for the wlan.

What about a command to turn the interrupt on/off?

Is it possible to change the standard config for Bluetooth to set the SPP on?
# CONFIG_BTDM_CTRL_MODE_BLE_ONLY is not set
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=y

In my Bluetooth Interrupt-testprogram there was few component

RTC_ESP_NTP,
Wlan_ESP32,
LED_ws2811

I removed all of them and after this the Bluetooth Interrupt was working fine and no more " spamming the console"

regards

Stefan

BenR
Matrix Staff
Posts: 1733
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 439 times
Been thanked: 602 times

Re: ESP32 Bluetooth is working. How to use Interrupt?

Post by BenR »

Hi Stefan,

Property is there now and defaults to no diagnostic data, same for Wifi so maybe these have made a difference.

As for turning the interrupt on and off, hmm might need to think on this one. You could always have the rx macro being called but have a decision in the macro on whether to collect the data or not.

Post Reply