BTStack on MSPEXP430F5438.

1,044 views
Skip to first unread message

mindentropy

unread,
May 6, 2012, 2:50:54 PM5/6/12
to btstack-dev
Hi,
I am using MSPEXP430F5438 with PAN1323ETU. I have downloaded the
BTS file CC2560A for this. I am not able to connect to the BT device
which is a ez430 cc256x loaded with the TI software. I am running the
spp_accel demo in the examples. What could be the problem?

Thanks in advance.

mindentropy

unread,
May 6, 2012, 7:16:45 PM5/6/12
to btstack-dev
Debugging further I see that the program is getting stuck in
rfcomm_send_internal(...)

Matthias Ringwald

unread,
May 7, 2012, 3:25:43 PM5/7/12
to btsta...@googlegroups.com
Hi

You could try to only use one embedded board. E.g. use the spp_counter example on the MSPEXP and setup a serial port from your computer. If you use Mac or Linux, you can also get a packet log easily and see where things get stuck.

BTstack shouldn't block anywhere. Are you sure the program doesn't return from rfcomm_send_internal?

Again a note for MSP430EXP users: make sure you've got the funny adapter on RF3 - http://processors.wiki.ti.com/index.php/PAN1315EMK_User_Guide#RF3_Connector

Best
Matthias
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To post to this group, send email to btsta...@googlegroups.com.
> To unsubscribe from this group, send email to btstack-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/btstack-dev?hl=en.
>

mindentropy

unread,
Jun 5, 2012, 8:58:35 AM6/5/12
to btstack-dev
The funny adapter was the problem. I soldered the lines. Now its
working fine. BTW BTstack is awesome :)

On May 8, 12:25 am, Matthias Ringwald <matthias.ringw...@gmail.com>
wrote:
> Hi
>
> You could try to only use one embedded board. E.g. use the spp_counter example on the MSPEXP and setup a serial port from your computer. If you use Mac or Linux, you can also get a packet log easily and see where things get stuck.
>
> BTstack shouldn't block anywhere. Are you sure the program doesn't return from rfcomm_send_internal?
>
> Again a note for MSP430EXP users: make sure you've got the funny adapter on RF3 -http://processors.wiki.ti.com/index.php/PAN1315EMK_User_Guide#RF3_Con...

zeid Ayssa

unread,
Jun 8, 2012, 9:52:53 AM6/8/12
to btstack-dev
Hi,
 I am trying to use btstack on the metawatch which uses MSP430F5438A
MCU and CC2564 bluetooth module. Someone already glued the btstack to
the code

 https://github.com/electric-monk/IndependentlySmartWatch

am trying to use it as a master that can look for devices within range
and chooses one to initiate a connection with a sensor and have a
function that deals with SPP packages. I looked at the examples
specially the one called hid_demo was implemented to fit MSP430F5438
and CC256x

http://btstack.googlecode.com/svn/trunk/MSP-EXP430F5438-CC256x/example/

, and I tried to understand how it is doing it but it was a little
confusing. I would love to have a function that establishes a
connection with a hardcoded passcode since my slaves are not keybaords
and cannot type passcodes, and another function that receives
packages. Is there a template example that can be easily tested.

On May 7, 3:25 pm, Matthias Ringwald <matthias.ringw...@gmail.com>
wrote:
> Hi
>
> You could try to only use one embedded board. E.g. use the spp_counter example on the MSPEXP and setup a serial port from your computer. If you use Mac or Linux, you can also get a packet log easily and see where things get stuck.
>
> BTstack shouldn't block anywhere. Are you sure the program doesn't return from rfcomm_send_internal?
>
> Again a note for MSP430EXP users: make sure you've got the funny adapter on RF3 -http://processors.wiki.ti.com/index.php/PAN1315EMK_User_Guide#RF3_Con...

Matthias Ringwald

unread,
Jun 12, 2012, 6:36:09 PM6/12/12
to btsta...@googlegroups.com
Hi Zeid

please check out the examples in the MSPEXP430F5438 folder of BTstack. (and read all documentation on the wiki plus have a look at the headers in include/btstack/)

The spp-cat example in the general example folder uses a PIN passed in from the command line.

If you have a actual issue, feel free to ask here.

Best
Matthias

zeid Ayssa

unread,
Jun 15, 2012, 10:15:19 AM6/15/12
to btsta...@googlegroups.com
Hi Matthias, 
        What if I already know the address of the device I want to connect to and the password, how do I hard code that in the code. Plus am still a little confused on how to create and SPP and what functions are responsible for sending and receiving data. thanks
>>> To unsubscribe from this group, send email to btstack-dev+unsubscribe@googlegroups.com.
>>> For more options, visit this group athttp://groups.google.com/group/btstack-dev?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "btstack-dev" group.
> To post to this group, send email to btsta...@googlegroups.com.
> To unsubscribe from this group, send email to btstack-dev+unsubscribe@googlegroups.com.

Alucard

unread,
Jun 25, 2012, 3:51:18 PM6/25/12
to btsta...@googlegroups.com
Hello, 
    Thank you so much for taking the time to respond to my questions in detail, I really appreciate it. I just have some points that are not clear to me yet, so if my slave device has a hard coded password, all I do is search for the device , find the address and wait for the pin request from the slave?

case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
goodprintf( "Enter 1234");
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "1234");
break;

wait for this case. The other question is authentication, should I put "1" or "0" for my case and whats the difference. How do I hard code the channel number or how do I find it after getting the address so I can create the rf_comm channel. Also, after the channel is opened, what functions will allow me to receive and send data through that channel. Thanks again for your help

if (COMMAND_COMPLETE_EVENT(packet, hci_inquiry_cancel) ) {
// inquiry successfully canceled
goodprintf("Connecting");
rfcomm_create_channel_internal(NULL,&event_addr,rfcomm_channel_nr); break;
 }



Matthias Ringwald

unread,
Jun 25, 2012, 4:51:04 PM6/25/12
to btsta...@googlegroups.com
Hi

you use 1 for authentication if you require it, 0 if not. I'd try with 0 and if that doesn't work, use 1.

after the connection is open you can use rfcomm_send_internal for sending (see examples e.g spp_counter) and you'll receive incoming data in a packet callback (see examples e.g. spp_echo in the regular ones).

Getting the RFCOMM channel is harder. Basically, you have to open an L2CAP connection to the other side's SDP server and query it. Please search the archive to previous answers. I admit that functionality is lacking, but I'll get back to that.

best
matthias

--
You received this message because you are subscribed to the Google Groups "btstack-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/btstack-dev/-/HxPufdZxMsYJ.

To post to this group, send email to btsta...@googlegroups.com.
To unsubscribe from this group, send email to btstack-dev...@googlegroups.com.

zeid Ayssa

unread,
Jun 25, 2012, 5:04:55 PM6/25/12
to btsta...@googlegroups.com
Hi, 
   Thanks for the quick response, the RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE did not occur, and when I read the packet its 0x54 after the channel is opened and i checked that case and its 
#define BTSTACK_NOT_ACTIVATED   0x54
does that mean that my stack is no activated, if so then how come I scanned for devices and opened an RF_COMM ?

zeid Ayssa

unread,
Jun 25, 2012, 5:06:49 PM6/25/12
to btsta...@googlegroups.com
Add to that, the pin code case did not happen too. And that raises the question of how the L2CAP channel was opened before inputting the pin code. thanks

Matthias Ringwald

unread,
Jun 25, 2012, 6:25:39 PM6/25/12
to btsta...@googlegroups.com
hi

events 0x50-0x5f are marked as internal, too. here is it's definition
#define DAEMON_EVENT_HCI_PACKET_SENT 0x54
it means that the last packet was sent to the Bluetooth module

Could you check the status of the l2cap complete event? it could be that you get an error there, too.
in this case, there might be an error in rfcomm error handling which should return rfcomm_channel_complete with an error instead of none.

best
matthias

zeid Ayssa

unread,
Jun 26, 2012, 1:41:14 PM6/26/12
to btsta...@googlegroups.com
Hi, 
   I checked for the cases , below is the code I used and the output from the debugger
static void PacketHandler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size)
{
bd_addr_t event_addr;
   uint8_t   rfcomm_channel_nr=1;
   uint16_t  mtu;
   uint16_t handle;
uint16_t psm;
uint16_t local_cid;
uint16_t remote_cid;
   int i,j;

switch (packet_type) {
case RFCOMM_DATA_PACKET:
goodprintf("Received RFCOMM data on channel id %u, size %u\n", channel, size);
hexdump(packet, size);
break;
case L2CAP_EVENT_CHANNEL_OPENED :
bt_flip_addr(event_addr, &packet[3]);
psm = READ_BT_16(packet, 11);
local_cid = READ_BT_16(packet, 13);
handle = READ_BT_16(packet, 9);
remote_cid = READ_BT_16(packet, 14);
if (packet[2] == 0) {
goodprintf("Channel successfully opened: %s, handle 0x%02x, psm 0x%02x, local cid 0x%02x, remote cid 0x%02x\n",
bd_addr_to_str(event_addr), handle, psm, local_cid,  READ_BT_16(packet, 15));
l2cap_send_internal(local_cid,accel_buffer,sizeof (accel_buffer));
} else {
goodprintf("L2CAP connection to device %s failed. status code %u\n", bd_addr_to_str(event_addr), packet[2]);
//exit(1);
}
break;

case HCI_EVENT_PACKET:
switch (packet[0]) {


case BTSTACK_EVENT_STATE:
// bt stack activated, get started - set local name
if (packet[2] == HCI_STATE_WORKING) {
//hci_send_cmd(&hci_write_authentication_enable, 1);
                       hci_send_cmd(&hci_write_local_name, "BlueMSP-Demo");
                   
}
break;
case HCI_EVENT_INQUIRY_RESULT:

// ignore further results
//if (haveDevice) break;

// ignore none Devices
//if ((packet[12] & 0x40) != 0x40 || packet[13] != 0x25) break;

// flip addr
bt_flip_addr(event_addr, &packet[3]);

// show
goodprintf("Device:\n\r");

// addr
j=0;
for (i=0;i<6;i++){
lineBuffer[j++] = hexMap[ event_addr[i] >>    4 ];
lineBuffer[j++] = hexMap[ event_addr[i] &  0x0f ];
if (i<5) lineBuffer[j++] = ':';
}
lineBuffer[j++] = 0;
goodprintf(lineBuffer);
hci_send_cmd(&hci_inquiry_cancel);
break;

case HCI_EVENT_INQUIRY_COMPLETE:
goodprintf("No Device found :(");
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (COMMAND_COMPLETE_EVENT(packet, hci_write_local_name)){
goodprintf("Inquiry");
//state = inquiry;
hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 30, 0);
break;
 }
if (COMMAND_COMPLETE_EVENT(packet, hci_inquiry_cancel)){
hci_send_cmd(&hci_write_authentication_enable, 1);
break;
}
if (COMMAND_COMPLETE_EVENT(packet, hci_write_authentication_enable)){
                       hci_discoverable_control(1);
                       goodprintf("Connecting");                       
                       rfcomm_create_channel_internal(NULL,&event_addr,rfcomm_channel_nr);

                       break;
                   }
                   break;

case HCI_EVENT_LINK_KEY_REQUEST:
// deny link key request
goodprintf("Link key request\n\r");
                   bt_flip_addr(event_addr, &packet[2]);
hci_send_cmd(&hci_link_key_request_negative_reply, &event_addr);
break;

case HCI_EVENT_PIN_CODE_REQUEST:
// inform about pin code request
goodprintf( "PIN = 1234");
goodprintf("Pin code request - using '0000'\n\r");
                   bt_flip_addr(event_addr, &packet[2]);
hci_send_cmd(&hci_pin_code_request_reply, &event_addr, 4, "1234");
break;

               case RFCOMM_EVENT_INCOMING_CONNECTION:
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
bt_flip_addr(event_addr, &packet[2]);
rfcomm_channel_nr = packet[8];
rfcomm_channel_id = READ_BT_16(packet, 9);
goodprintf("RFCOMM channel %u requested for %s\n\r", rfcomm_channel_nr, bd_addr_to_str(event_addr));
                   rfcomm_accept_connection_internal(rfcomm_channel_id);

break;

case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE:
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
    if (packet[2]) {
    goodprintf("RFCOMM channel open failed, status %u\n\r", packet[2]);
    goodprintf("Connection failed :(");
} else {
rfcomm_channel_id = READ_BT_16(packet, 12);
mtu = READ_BT_16(packet, 14);
goodprintf("\n\rRFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n\r", rfcomm_channel_id, mtu);
}
    //rfcomm_send_internal(rfcomm_channel_id,accel_buffer,sizeof (accel_buffer));
break;

/*
               case DAEMON_EVENT_HCI_PACKET_SENT:
               case RFCOMM_EVENT_CREDITS:
                   if (!rfcomm_channel_id) break;
                   // try send
                  err = rfcomm_send_internal(rfcomm_channel_id, (uint8_t *)accel_buffer, sizeof(accel_buffer));
                   switch (err){
                       case 0:
                           //prepare_accel_packet();
                           break;
                       case BTSTACK_ACL_BUFFERS_FULL:
                           break;
                       default:
                        goodprintf("rfcomm_send_internal() -> err %d\n\r", err);
                       break;
                   }
                   break;
*/
               case RFCOMM_EVENT_CHANNEL_CLOSED:
                   rfcomm_channel_id = 0;
                   break;
               case HCI_EVENT_DISCONNECTION_COMPLETE:
// connection closed -> quit test app
goodprintf("Basebank connection closed\n");
break;

               default:
                   break;
}
           break;

       default:
           break;
}
}
================================================
     the output from the debugger is:

nfo: hci_power_control: 1, current mode 0
Info: hci_run: init script done

Info: Local Address, Status: 0x00: Addr: 00:18:34:2F:9B:46
ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E
InquiryDevice:

00:0E:6D:BA:87:AFConnectingInfo: rfcomm_create_channel_internal to 00:0E:6D:BA:87:AF, at channel #01, flow control 0, init credits 48
Info: rfcomm_max_frame_size_for_l2cap_mtu:  48 -> 43
Info: rfcomm_channel_create for service 0 1 --- begin
Info: Create_connection to 00:0E:6D:BA:87:AF
Info: Connection_complete (status=4) 00:0E:6D:BA:87:AF
Info: L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM
Info: L2CAP_EVENT_CHANNEL_OPENED: outgoing connection

         after that it freezes and nothing happens, when is says connection_complete (status=4) what does that mean. Also did the channel open or what? When is it supposed to check for the PIN code ? thanks

Matthias Ringwald

unread,
Jun 28, 2012, 3:51:27 PM6/28/12
to btsta...@googlegroups.com
Hi Zeid

Error 4 is again "Connection Timeout". If the address comes from an inquiry result that's actually pretty weird. It looks to me like your Bluetooth isn't working properly. If you use e.g. spp_counter, are you able to discover your device? Can you check which init script you are using? If you're using the wrong one the module might work partially (you should use the 2564 or the 2560A if you have the newer MetaWatch which advertises Bluetooth Low Energy).

Best
 Matthias





On 27.06.2012, at 23:24, zeid Ayssa <ayssa...@gmail.com> wrote:

Hi , 
    I was trying to use the same code from hid_demo.c ,i used this command 
l2cap_create_channel_internal(NULL, l2cap_packet_handler, Device, PSM_SDP, 150);
 this is my l2cap handler

static void l2cap_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){

uint8_t *ptr;
ptr=&packet_type;
print_hex_packet(ptr, sizeof(packet_type));
print_hex_packet(packet,4);
if (packet_type == HCI_EVENT_PACKET && packet[0] == L2CAP_EVENT_CHANNEL_OPENED){
        if (packet[2]) {
        //print_hex_packet(packet,size);
            printf("Connection failed\n\r");
            return;
   }
        print_hex_packet(packet,size);
printf("Connected\n\r");
}
}

It went inside the first if statement  , which means that  L2CAP_EVENT_CHANNEL_OPENED channel is opened, but packet[2] was never == 0 , why is that? Plus this is all happening without going through the PIN code request case. When I read the packets I found:
packet_type = 0x04 which is HCI_EVENT_PACKET  and packet[0] = L2CAP_EVENT_CHANNEL_OPENED but packet[2] was = 0x04 , what does that mean?. and when I tried to send something by using 
l2cap_send_internal(Local_cid,ptr, sizee);

 I get ERROR: l2cap_send_internal cid 1038, no credits!. Thanks

04,  70,13,04,AF,Connection failed
On Wed, Jun 27, 2012 at 7:28 AM, Matthias Ringwald <matthias...@gmail.com> wrote:
Hi Zeid

thanks for your log. BTstack uses the official Bluetooth status codes where possible. Status = 4 is "Connection Timeout", i.e. the Bluetooth module wasn't able to connect to the other side.

In theory, you should also get an RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE with status = 4 (-> fail). However, I just checked the code and I forgot the error checking on the L2CAP_EVENT_CHANNEL_OPENED in the RFCOMM handler. I'll add it to my list of ToDos.

In your case, you should check if the address of the remote device is correct. :)

Best
 Matthias

zeid Ayssa

unread,
Jun 28, 2012, 4:22:35 PM6/28/12
to btsta...@googlegroups.com
Hi Matthias, 
         Thanks again for your help, first, I would like to tell you that when I reset the watch to the original firmware it came with and then upload my code , it works , this is what I get in my debug
Info: Local Address, Status: 0x00: Addr: 00:18:34:2F:9B:46
ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E
InquiryDevice:
Info: 00:01:95:08:47:F4Info: Create_connection to 00:01:95:08:47:F4
Info: Connection_complete (status=0) 00:01:95:08:47:F4
Info: New connection: handle 1, 00:01:95:08:47:F4
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP signaling handler code 4, state 6
Info: 00:01:95:08:47:F4Info: l2cap_send_internal cid 64, cannot send
 Connected

I used this function 
l2cap_create_channel_internal(NULL, l2cap_packet_handler, Device, PSM_SDP, 150);
and my l2cap_handler was 
if (packet_type == HCI_EVENT_PACKET && packet[0] == L2CAP_EVENT_CHANNEL_OPENED){
        if (packet[2]) {
        //print_hex_packet(packet,size);
            printf("Connection failed\n\r");
            return;
   }
        print_hex_packet(packet,size);
printf("Connected\n\r");
}
if (packet_type == L2CAP_DATA_PACKET){
printf("L2CAP_DATA_PACKET");
            return;
        }

Now , I want to receive and send data to this device
what functions should I use and where to put them, plus do I need to include this in my bluetooth initialization
// try RS232
    rfcomm_init();
    rfcomm_register_packet_handler(PacketHandler);
    rfcomm_register_service_internal(NULL, 1, 100);

    // try SDP
    sdp_init();
    memset(sppServiceBuffer, 0, sizeof(sppServiceBuffer));
    service_record_item_t *serviceRecordItem = (service_record_item_t*)sppServiceBuffer;
    sdp_create_spp_service( (uint8_t*) &serviceRecordItem->service_record, 1, "SPP Interface");
    sdp_register_service_internal(NULL, serviceRecordItem);

because all I used was l2cap_init and l2cap register?
One more thing, where do i get the init script for 2564 ? and where should I place it ? thanks

zeid Ayssa

unread,
Jun 28, 2012, 4:23:44 PM6/28/12
to btsta...@googlegroups.com
Hi Matthias, 
         Thanks again for your help, first, I would like to tell you that when I reset the watch to the original firmware it came with and then upload my code , it works , this is what I get in my debug
Info: Local Address, Status: 0x00: Addr: 00:18:34:2F:9B:46
ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E
InquiryDevice:
Info: 00:01:95:08:47:F4Info: Create_connection to 00:01:95:08:47:F4
Info: Connection_complete (status=0) 00:01:95:08:47:F4
Info: New connection: handle 1, 00:01:95:08:47:F4
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP signaling handler code 4, state 6
Info: 00:01:95:08:47:F4Info: l2cap_send_internal cid 64, cannot send
 Connected

I used this function 
l2cap_create_channel_internal(NULL, l2cap_packet_handler, Device, PSM_SDP, 150);
and my l2cap_handler was 
if (packet_type == HCI_EVENT_PACKET && packet[0] == L2CAP_EVENT_CHANNEL_OPENED){
        if (packet[2]) {
         //print_hex_packet(packet,size);
            printf("Connection failed\n\r");
            return;
    }
        print_hex_packet(packet,size);
printf("Connected\n\r");
}
if (packet_type == L2CAP_DATA_PACKET){
printf("L2CAP_DATA_PACKET");
            return;
        }

Now , I want to receive and send data to this device
what functions should I use and where to put them, plus do I need to include this in my bluetooth initialization
// try RS232
    rfcomm_init();
    rfcomm_register_packet_handler(PacketHandler);
    rfcomm_register_service_internal(NULL, 1, 100);

    // try SDP
    sdp_init();
    memset(sppServiceBuffer, 0, sizeof(sppServiceBuffer));
    service_record_item_t *serviceRecordItem = (service_record_item_t*)sppServiceBuffer;
    sdp_create_spp_service( (uint8_t*) &serviceRecordItem->service_record, 1, "SPP Interface");
    sdp_register_service_internal(NULL, serviceRecordItem);

because all I used was l2cap_init and l2cap register?
One more thing, where do i get the init script for 2564 ? and where should I place it ? thanks

Matthias Ringwald

unread,
Jun 28, 2012, 5:07:13 PM6/28/12
to btsta...@googlegroups.com
Hi

if the l2cap connection works, the rfcomm should work, too.
in your previous logs, the ACL connection failed, on which l2cap and rfomm packets are transported.


best
matthias

zeid Ayssa

unread,
Jun 28, 2012, 6:17:52 PM6/28/12
to btsta...@googlegroups.com
Hi Mathias, 
       Is there a way to manually reset the bluetooth module? or does the bluetooth initialization takes care of that? because when I run my code it works for the first time, but then when I reset the CPU and run it again it wont connect to the channel , what do you think is the problem , thanks a lot for your help

zeid Ayssa

unread,
Jun 29, 2012, 2:29:09 AM6/29/12
to btsta...@googlegroups.com
Hi, 
    So far I was able to initiate a connection and open L2CAP channel. I am trying to connect to my PC hyperterminal and this is what I get in my debug:
Info: hci_run: init script done

Info: Local Address, Status: 0x00: Addr: 00:18:34:2F:9B:46
ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E
InquiryDevice:
Info: 00:50:F2:E4:86:43ConnectingInfo: Create_connection to 00:50:F2:E4:86:43
Info: HCI_EVENT_LINK_KEY_REQUEST
Info: responding to link key request
Info: Connection_complete (status=0) 00:50:F2:E4:86:43
Info: New connection: handle 1, 00:50:F2:E4:86:43
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 4, state 6
Info: L2CAP signaling handler code 5, state 6

Enter 1234HCI_EVENT_LINK_KEY_NOTIFICATION  70,13,00,43,86,E4F25000010001004000410030000004Connected

SDP service buffer size: 111
Info: rfcomm_create_channel_internal to 00:50:F2:E4:86:43, at channel #01, flow control 0, init credits 48
Info: rfcomm_max_frame_size_for_l2cap_mtu:  48 -> 43
Info: rfcomm_channel_create for service 0 1 --- begin
Info: Create_connection to 00:50:F2:E4:86:43
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 4, state 6
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM
Info: L2CAP_EVENT_CHANNEL_OPENED: outgoing connection
Info: Sending SABM #0 - (multi 0xInfo: Received UA #0 
Info: Multiplexer up and running
Info: Muliplexer opened, sending UIH PN next
Info: Sending UIH Parameter Negotiation Command for #2 (channel 0xInfo: Received DM message for #2
Info: -> Closing channel locally for #2
Info: Received DISC #0, (ougoing = 1)
Info: Sending UA #0
Info: Closing down multiplexer
Info: TODO: no connections established - delete link key prophylactically
Info: L2CAP signaling handler code 6, state 8
Info: L2CAP signaling handler code 4, state 6
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP signaling handler code 6, state 7

what does that mean? why did it close down, 

and once I try to open the port , i get 
Info: L2CAP signaling handler code 4, state 6
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP signaling handler code 6, state 7
then it says port could not open. Thanks again for your help, I really appreciate it.

Matthias Ringwald

unread,
Jun 29, 2012, 4:15:54 AM6/29/12
to btsta...@googlegroups.com

BTstack sends an HCI Reset command on startup.

However, I have to reset my Bluetooth module before each run too.

In the MSP430EXP5438 setup, removing power or doing a reset stops the 32 kHz for the PAN13xx module which causes a reboot anyway.

best
matthias

Matthias Ringwald

unread,
Jun 29, 2012, 4:17:28 AM6/29/12
to btsta...@googlegroups.com
Hi Zeid

while basically all SPP devices have an RFCOMM channel #1, computers usually have a few of them so the one you are looking for isn't necessarily #1. You would need to do an SDP query, or just try a few channels manually (1..32)..

btw. what was the problem before when all connections did fail?

cheers
matthias

zeid Ayssa

unread,
Jun 29, 2012, 11:38:06 AM6/29/12
to btsta...@googlegroups.com
Hi Mathias, 
       First, I would like to thank you for helping me. All I did was separate the initialization code, so I would wait for the l2cap_channel to open then I will initialize the rfcom and register the spp and sdp init(). Now the problem that I have is: 
I am trying to connect to this device:


when I establish a connection with it , I get this
Info: 00:0E:6D:BA:87:AFConnectingInfo: Create_connection to 00:0E:6D:BA:87:AF
Info: HCI_EVENT_LINK_KEY_REQUEST
Info: responding to link key request
Info: Connection_complete (status=0) 00:0E:6D:BA:87:AF
Info: New connection: handle 1, 00:0E:6D:BA:87:AF
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP signaling handler code 4, state 6
SDP service buffer size: 111
Info: rfcomm_create_channel_internal to 00:0E:6D:BA:87:AF, at channel #01, flow control 0, init credits 48
Info: rfcomm_max_frame_size_for_l2cap_mtu:  48 -> 43
Info: rfcomm_channel_create for service 0 1 --- begin
ERROR: h4_send_packet with tx_state = 6, type 1, data 1A 0C 01
 and then nothing happens, what is that error, and how can I send and receive data? thanks a lot

Matthias Ringwald

unread,
Jun 30, 2012, 6:32:45 AM6/30/12
to btsta...@googlegroups.com
hi

On 29.06.2012, at 17:38, zeid Ayssa wrote:

> Hi Mathias,
> First, I would like to thank you for helping me. All I did was separate the initialization code, so I would wait for the l2cap_channel to open then I will initialize the rfcom and register the spp and sdp init().
Interesting. In theory, you don't need to open an l2cap_channel before opening the rfcomm_channel. You do have to wait until BTstack is fully running.

> Info: rfcomm_channel_create for service 0 1 --- begin
> ERROR: h4_send_packet with tx_state = 6, type 1, data 1A 0C 01
> and then nothing happens, what is that error, and how can I send and receive data? thanks a lot

this error indicates that a higher layer requests to send a packet while the previous one hasn't been been acknowledged yet. This should not happen :)

All higher level code calls h4_can_send_packet_now before sending which only returns true if TX_STATE == IDLE and your error says that someone calls ehcill_send_packet with TX_STATE == DONE

One possible way to run into this could be if you're using multithreading and try sending from a different thread. That's my best guess.
Does this help?

Best
Matthias

zeid Ayssa

unread,
Jul 2, 2012, 1:50:55 PM7/2/12
to btsta...@googlegroups.com
Hi Mathias, 
          I think am not quit getting what is the error, I am using btstack with FreeRTOS and it has the highest priority of all the tasks. Now, I used this code to make sure that it is ready to send a package, 
if(packet_type == HCI_EVENT_PACKET && packet[0] ==L2CAP_EVENT_CREDITS){
// can send! (assuming single credits are handet out)

Local_cid = READ_BT_16(packet, 2);
if(l2cap_can_send_packet_now(Local_cid));
rfcomm_send_internal( Local_cid, packet, size);
return;
}

so my program is executing rfcomm send internal , which means that l2cap channel is opened and can send packet now, but its giving me another error plus the error from before, 

Info: rfcomm_max_frame_size_for_l2cap_mtu:  48 -> 43
Info: rfcomm_channel_create for service 0 1 --- begin
ERROR: rfcomm_send_internal cid 64 doesn't exist!
ERROR: h4_send_packet with tx_state = 6, type 1, data 1A 0C 01
     is there a function that I have to check before sending data? Plus I am more interested now in receiving data, how do I read incoming data? . When am talking to my sensor through my hyperterminal (PC) I have to set the Baudrate to 115200 , is there going to be a problem? should I change something to account for that? thanks

zeid Ayssa

unread,
Jul 2, 2012, 2:06:03 PM7/2/12
to btsta...@googlegroups.com
In addition, 
      I was wondering if you can explain briefly how the runloop embedded works
while (1) {

        // process data sources
        data_source_t *next;
        for (ds = (data_source_t *) data_sources; ds != NULL ; ds = next){
            next = (data_source_t *) ds->item.next; // cache pointer to next data_source to allow data source to remove itself
            ds->process(ds);
        }

how is this while loop getting data and sending them back to the packet handler , thanks


zeid Ayssa

unread,
Jul 2, 2012, 3:36:50 PM7/2/12
to btsta...@googlegroups.com
Hi, 
       After the L2CAP cahnnel is opened , I use this function to create an rfcomm channel
rfcomm_create_channel_internal(NULL,&Device,rfcomm_channel_nr);
the channel number is 1, in the packet handler I get the case RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE
and when I check to packet[2] I get 56, 

Info: rfcomm_create_channel_internal to 00:01:95:08:47:F4, at channel #01, flow control 0, init credits 48
Info: rfcomm_max_frame_size_for_l2cap_mtu:  48 -> 43
Info: rfcomm_channel_create for service 0 1 --- begin
RFCOMM_EVENT_SERVICE_REGISTERED channel: 1, status: 0x00
Info: rfcomm_create_channel_internal to 00:01:95:08:47:F4, at channel #01, flow control 0, init credits 48
Info: rfcomm_channel_create for service 0 1 --- begin
RFCOMM channel open failed, status 86
ERROR: h4_send_packet with tx_state = 6, type 1, data 1A 0C 01

What am I doing wrong? 

Matthias Ringwald

unread,
Jul 3, 2012, 4:48:56 AM7/3/12
to btsta...@googlegroups.com
hi zeid

the error looks like BTstack (run_loop_execute) is running on one thread and you're calling BTstack functions from another thread. Please make sure you use BTstack only from a single thread.

also, the l2cap_cid and the rfcomm_cid are totally different and unrelated. for rfcomm sending, you should call rfcomm_can_send (or so) when you receive RFCOMM_EVENT_CREDITS (or so) or DAEMON_EVENT_SENT (or so).

for communication over SPP you don't need to set the baudrate unless the other device has a physical serial port. No need on a PC.

best
matthias

Matthias Ringwald

unread,
Jul 3, 2012, 4:50:24 AM7/3/12
to btsta...@googlegroups.com
Hi

the run loop below is very primitive. It essentially polls each registered data source. One of those data sources is hci_transport which accepts packet from the Bluetooth module and forwards them to the higher layers until data reaches your application.

best
matthias

Matthias Ringwald

unread,
Jul 3, 2012, 4:53:43 AM7/3/12
to btsta...@googlegroups.com
hi again

as explained before, errors 0x00 - 0x3f are defined by the Bluetooth Specification and higher ones are defined in include/hci_cmds.h.

#define BTSTACK_MEMORY_ALLOC_FAILED 0x56

that's an easy one as you probably didn't reserve memory for your rfcomm channel. Please compare the config.h of the SPP examples with yours.

best
matthias

p.s. you almost made the connection...

zeid Ayssa

unread,
Jul 5, 2012, 10:45:58 AM7/5/12
to btsta...@googlegroups.com
Hi Mathias, 
       Could you please post a snippet of code for an RFCOMM client , just the part where it creates the channel, send and receive data. I am able to open L2CAP channel successfully and when I create an rfcomm channel, for the first time I got this:
Info: HCI_EVENT_LINK_KEY_REQUEST
Info: responding to link key request
Info: Connection_complete (status=0) 00:01:95:08:47:F4
Info: New connection: handle 1, 00:01:95:08:47:F4
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP signaling handler code 4, state 6
Info: L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM
Info: L2CAP_EVENT_CHANNEL_OPENED: outgoing connection
Info: Sending SABM #0 - (multi 0xERROR: h4_process: invalid packet type 0x00
Info: Received UA #0 
Info: Multiplexer up and running
Info: Muliplexer opened, sending UIH PN next
Info: Sending UIH Parameter Negotiation Command for #2 (channel 0xInfo: UIH Parameter Negotiation Response max frame 43, credits 0
Info: Sending SABM #2
Info: Received UA #2 - channel opened
Info: Sending MSC CMD for #2
Info: Providing credits for #2
Info: Received MSC CMD for #2, 
Info: Sending MSC RSP for #2
Info: Received MSC RSP for #2
Info: RFCOMM data UIH_PF, new credits: 44, now 44
Info: rfcomm_channel_opened!

Enter 1234HCI_EVENT_LINK_KEY_NOTIFICATION

RFCOMM channel open succeeded. New RFCOMM Channel ID 1, max frame size 43
Info: rfcomm_send_internal cid 1, no rfcomm credits granted!

but when I run the same code again , it does not work. I have been stuck on this problem for a long time now, I would really appreciate it if you can tell me what functions to use and in what order or just show me a snippet of code. Thanks for your help

zeid Ayssa

unread,
Jul 5, 2012, 10:58:44 AM7/5/12
to btsta...@googlegroups.com
In addition, 
        When I use rfcomm_create_channel , what should I use for the connection parameter, should I keep it NULL as the other examples? and if l2cap channel is opened , then what can I do with it, I tried sending data but it said error cid 64, cannot send. If you could please tell me when will you have free 30 min or and hour so we can chat if possible, I would really appreciate it. thanks

zeid Ayssa

unread,
Jul 5, 2012, 12:07:40 PM7/5/12
to btsta...@googlegroups.com
Hi, 
        What is this error and how to fix it

ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E

thanks,

Matthias Ringwald

unread,
Jul 5, 2012, 3:34:05 PM7/5/12
to btsta...@googlegroups.com
That should be an information and not an error. (don't worry about that)

Sent from my iPhone

Matthias Ringwald

unread,
Jul 5, 2012, 3:36:05 PM7/5/12
to btsta...@googlegroups.com
The connection argument is not used in embedded systems. It is used with BTdaemon to close all connections for one client or to know which client(connection) data should be delivered to. 

Sent from my iPhone

Matthias Ringwald

unread,
Jul 5, 2012, 3:43:33 PM7/5/12
to btsta...@googlegroups.com
Hi. If you can open an rfcomm connection once then you should be all set. I basically put all embedded code samples into the SVN. 

If it doesn't work the second time, the question is how you close it and if theres anything you do differently. 

I dont think I tried reconnecting as a test but multiple incoming connections work for sure, and I also didn't have problems opening outgoing channels on iOS (eg in the Celeste OBEX implementation)

Btw. you dont need to open an l2cap channel. At least not in my understanding of what I implemented. 


I would suggest to compare both the successful and the failing one in more detail. In fact I don't remember what error you get the second time. You got connection timeouts, but that would depend more on the remote side. 

Sent from my iPhone

zeid Ayssa

unread,
Jul 5, 2012, 4:19:06 PM7/5/12
to btsta...@googlegroups.com
Hi Mathias, 
     All I did was use this function:
rfcomm_create_channel_internal(NULL,&Device,1);
then it worked, after that I reset the watch and tried the code again but it did not work. I did not disconnect anything, I just stopped the processor and restarted it. How do I close the channel so I can connect to it again? thanks again for your help

Matthias Ringwald

unread,
Jul 5, 2012, 4:54:38 PM7/5/12
to btstack-dev
Hi Zeid

You're running BTstack on the MetaWatch, right? If you say "reset the watch", this means you press some RESET button, but don't power cycle the watch. Can you try to turn off the watch before retry?

It looks like the Bluetooth doesn't get fully reseted and the init scripts shouldn't run the second time after the reset. Is there a way on the MetaWatch to fully disable the power for the Bluetooth module?

On my developer boards, if I reset the board, the MCU stops and also stops providing the 32kHz clock to the Bluetooth module which causes it to restart.

Best 
 Matthias

zeid Ayssa

unread,
Jul 5, 2012, 5:52:29 PM7/5/12
to btsta...@googlegroups.com
Hi Mathias, 
      Since you have the watch, could you pls compile this code and see why the watch is not opening the channel
this already has btstack built into its freeRTOS. You can replace the code in task.c by the file attached. This file looks for devices and connects to the first device it finds. Please tell me why can't I establish a connection!!!. I have been on this for almost a month, and I really want the MetaWatch to be the master in a connection, because a lot of people are going to use it for cool projects using the btstack. I am about to give up, so I decided to send you the whole project. Please let me know if we can chat Live so I can send you the problems am having. Thanks again for your help
7_4_w.txt

Matthias Ringwald

unread,
Jul 5, 2012, 5:57:26 PM7/5/12
to btstack-dev
Hi Zeid

Jim, also on this list tried to post the following..

You might want to set the watch to RST rather than NMI, and then pull
the 'ninja' trick of shorting the two pins with the buckle.

Jim


<7_4_w.txt>

zeid Ayssa

unread,
Jul 6, 2012, 12:07:35 AM7/6/12
to btsta...@googlegroups.com
Hi Mathias, 
         I was able to get it running every time I reset the watch, I was trying to connect to a hyperterminal , but what I got is this:
Info: hci_run: init script done

Info: Local Address, Status: 0x00: Addr: 00:18:34:2F:9B:46
ERROR: hci_read_buffer_size: used size 52, count 4, packet types 331E
InquiryDevice:
Info: 00:50:F2:E4:86:43ConnectingInfo: rfcomm_create_channel_internal to 00:50:F2:E4:86:43, at channel #0B, flow control 0, init credits 48
Info: rfcomm_max_frame_size_for_l2cap_mtu:  48 -> 43
Info: rfcomm_channel_create for service 0 11 --- begin
Info: Create_connection to 00:50:F2:E4:86:43
Info: HCI_EVENT_LINK_KEY_REQUEST
Info: responding to link key request
Info: Connection_complete (status=0) 00:50:F2:E4:86:43
Info: New connection: handle 1, 00:50:F2:E4:86:43
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 3, state 5
Info: L2CAP signaling handler code 4, state 6
Info: L2CAP signaling handler code 5, state 6
Info: L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM
Info: L2CAP_EVENT_CHANNEL_OPENED: outgoing connection
Info: Sending SABM #0 - (multi 0xInfo: Received UA #0 
Info: Multiplexer up and running
Info: Muliplexer opened, sending UIH PN next
Info: Sending UIH Parameter Negotiation Command for #22 (channel 0xInfo: Received DM message for #22
Info: -> Closing channel locally for #22
Info: Received DISC #0, (ougoing = 1)
Info: Sending UA #0
Info: Closing down multiplexer
Info: TODO: no connections established - delete link key prophylactically
Info: L2CAP signaling handler code 6, state 8
Info: Connection closed: handle 1, 00:50:F2:E4:86:43

Basebank connection closed, exit.

why does it close after opening , thanks 

Zeid Ayssa

unread,
Jul 6, 2012, 1:23:01 AM7/6/12
to btsta...@googlegroups.com
Hi Mathias,
     Once I have an rfcomm channel opened , if I want to receive data, all I need is to wait for an RFcomm packet type as shown in the examples? thanks 

Matthias Ringwald

unread,
Jul 6, 2012, 4:44:54 AM7/6/12
to btsta...@googlegroups.com
hi

On Jul 6, 2012, at 6:07 AM, zeid Ayssa wrote:

> Hi Mathias,
> I was able to get it running every time I reset the watch, I was trying to connect to a hyperterminal , but what I got is this:

very good!

> Info: Sending UIH Parameter Negotiation Command for #22 (channel 0xInfo: Received DM message for #22
> Info: -> Closing channel locally for #22
> why does it close after opening , thanks

don't know, but the other side cancels the connection here. Are you sure it's the correct channel? Maybe the other side didn't realize yet the the previous connection is gone? Please try resetting the other side too (e.g. wait a minute..)

> Once I have an rfcomm channel opened , if I want to receive data, all I need is to wait for an RFcomm packet type as shown in the examples? thanks

yes, that's correct.

cheers
matthias

zeid Ayssa

unread,
Jul 6, 2012, 10:37:07 AM7/6/12
to btsta...@googlegroups.com
Hi Mathias, 
           I am able to get to this point then it stops:

Info: L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM
Info: L2CAP_EVENT_CHANNEL_OPENED: outgoing connection
Info: Sending SABM #0 - (multi 0xERROR: ERROR: NO RX REQUEST PENDING

how do I proceed? thanks 

matthias

Matthias Ringwald

unread,
Jul 6, 2012, 11:28:53 AM7/6/12
to btsta...@googlegroups.com
hi zeid

I would suggest to try to find the place in the BTstack code that prints that error and try to understand the reason for that (it's open source after all :). Right now, I don't know what it means either, only that I don't remember seeing that message.

something else: why are the log messages interleaved? how does the goodprint work? interleaved log messages commonly indicate that multiple threads use printf and there's no mutex to synchronize. BTstack is designed for a single thread, so if multiple threads interact with it, it may fail in any possible way.

Cheers
matthias

zeid Ayssa

unread,
Jul 6, 2012, 11:54:01 AM7/6/12
to btsta...@googlegroups.com
Hi Mathias, 
    I found it in this function:
static int ehcill_send_packet(uint8_t packet_type, uint8_t *packet, int size){
    
    // write in progress
    if (tx_state != TX_IDLE) {
        log_error("h4_send_packet with tx_state = %u, type %u, data %02x %02x %02x\n", tx_state, packet_type, packet[0], packet[1], packet[2]);
        return -1;
    }
    
#ifdef DUMP
    printf("TX: %02x ", packet_type);
    dump(packet, size);
#endif
    
    tx_packet_type = packet_type;
    tx_data = packet;
    tx_len  = size;
    
    if (!ehcill_sleep_mode_active()){
        tx_state = TX_W4_HEADER_SENT;
        hal_uart_dma_send_block(&packet_type, 1);
        return 0;
    }
    
    // UART needed again
    hal_uart_dma_set_sleep(0);

    // update state
    tx_state     = TX_W4_WAKEUP;
    ehcill_state = EHCILL_STATE_W4_ACK;
    
    // wake up
//    log_info("RX: SLEEP\n");
//    log_info("TX: EHCILL_WAKE_UP_IND\n");
    ehcill_command_to_send = EHCILL_WAKE_UP_IND;
    hal_uart_dma_send_block(&ehcill_command_to_send, 1);
    
    if (!ehcill_defer_rx_size){
        log_error("ERROR: NO RX REQUEST PENDING\n");
        return 0;
    }
    
    // receive request, clears RTS
    int rx_size = ehcill_defer_rx_size;
    ehcill_defer_rx_size = 0;
    hal_uart_dma_receive_block(ehcill_defer_rx_buffer, rx_size);
    return 0;
}

under  hci_transport_h4_ehcill_dma.c file, does that mean I need to change my SPP buffer size or what? thanks a lot 

Jim Thompson

unread,
Jul 6, 2012, 1:30:25 PM7/6/12
to btsta...@googlegroups.com

On Jul 6, 2012, at 10:28 AM, Matthias Ringwald <matthias...@gmail.com> wrote:

> something else: why are the log messages interleaved? how does the goodprint work? interleaved log messages commonly indicate that multiple threads use printf and there's no mutex to synchronize. BTstack is designed for a single thread, so if multiple threads interact with it, it may fail in any possible way.

The Metawatch platform is based on FreeRTOS. FreeRTOS provides methods for multiple threads (tasks), and semaphores. Thread priorities are supported.

It is likely that BTstack needs some work before running in such an environment.

Jim

Matthias Ringwald

unread,
Jul 9, 2012, 4:58:40 PM7/9/12
to btstack-dev
Hi Zeid

what did you change? did you look at the threads?

in general, BTstack doesn't provide any packet buffers, which is part of the minimal memory strategy. If you get data faster than it can be sent back, a send may fail. Please check the return value of rfcomm_send_internal to see if that happens.

best
matthias

On 08.07.2012, at 08:19, zeid Ayssa wrote:

> Hi Mathias,
> Thanks a lot, it worked. Now I can open an RFCOMM channel ,
> send and receive data. Now , how large is the buffer for the received
> data? I am trying to receive around 900 bytes, do I need to set up a
> buffer to retain the information? When I use this to receive data:
>
> case RFCOMM_DATA_PACKET:
> printf("Received RFCOMM data on channel id %u, size %u\n", channel, size);
> hexdump(packet, size);
> rfcomm_send_internal (channel, packet, size);
> break;
> if the data is large it will only echo some of it and ignores the
> rest, how do I wait till I receive all the data? thanks a lot for all
> your help, I really appreciate it
>
>
>
>
> On Fri, Jul 6, 2012 at 4:29 PM, Matthias Ringwald
> <matthias...@gmail.com> wrote:
>>
>> hi zeid
>>
>> you could disable support for eHCILL power saving by using
>> bt_control_cc256x_enable_ehcill(0);
>> instead of
>> bt_control_cc256x_enable_ehcill(1);
>>
>> however, as mentioned before, it looks like BTstack is running on different threads. I'd suggest to find the function to get the current thread (ID or thread context structure pointer) and add that to the log_ calls, by this you might learn about the used threads. I've also referred to the btstack/ports which contains a proper use of BTstack in an multi-threaded environement (uC/OS-II) - using message queues.
>>
>> best
>> matthias

zeid Ayssa

unread,
Jul 9, 2012, 5:55:01 PM7/9/12
to btsta...@googlegroups.com
Hi Matthias,
I changed FreeRTOS to only run one task which is the btstack, I
believe after doing that the problem was in
bt_control_cc256x_enable_ehcill(1);
because after you told me to change it it was running fine. For
receiving data, I thought that sending and receiving at the same time
might have some delay, so I got rid of the echoing part and assigned a
buffer to save the data. When I send large data , I only receive some
of it. Plus it says that the max frame is 43, what does that mean? I
have this to store data:
case RFCOMM_DATA_PACKET:
for(j=0;j<size;j++)
{
buffer[j+i]=packet[j];
}
i+=size;
break;

this will fill up the buffer with all received data, when I try to
send it back, does not let me, is it due to the size of my buffer-
which is 200 bytes- i use :
rfcomm_send_internal(rfcomm_channel_id, buffer, sizeof buffer);
I am trying to receive all data reliably first before I can continue
my project, thanks again



On Mon, Jul 9, 2012 at 4:58 PM, Matthias Ringwald

Matthias Ringwald

unread,
Jul 10, 2012, 4:01:56 AM7/10/12
to btsta...@googlegroups.com
Hi Zeid

On Jul 9, 2012, at 11:55 PM, zeid Ayssa wrote:

> Hi Matthias,
> I changed FreeRTOS to only run one task which is the btstack, I
> believe after doing that the problem was in
> bt_control_cc256x_enable_ehcill(1);
> because after you told me to change it it was running fine.

well, yes and no. I had ehcill enabled in all my tests and never had the error you've reported.

> For
> receiving data, I thought that sending and receiving at the same time
> might have some delay, so I got rid of the echoing part and assigned a
> buffer to save the data. When I send large data , I only receive some
> of it. Plus it says that the max frame is 43, what does that mean?

It means that you can only send max 43 bytes in one packet.
If you have more data to send, you need to send multiple packets.

43 bytes results from the default setting in config.h or 52 byte ACL packets or so.
you can increase that but that will also increase the RAM consumption.

cheers
matthias

zeid Ayssa

unread,
Jul 10, 2012, 7:38:18 PM7/10/12
to btsta...@googlegroups.com
Hi Matthias,
I am using btstack in a Task with FreeRTOS, what I want is
the received data to be sent to the FreeRTOS message queue for every
packet. The function am using is :

printf("Received RFCOMM data on channel id %u, size %u\n", channel, size);
uint8_t *buff;
buff=getBuff();
//Note: Buffer location [0] is reserved for the packet size
buff[0]= size;
for(i=0;i<size;i++)
{
buff[i+1]=packet[i];

}
if( xQueue!= 0 )
{
uint8_t* pxMessage;
pxMessage = buff;
xQueueSend( xQueue, ( void * ) &pxMessage, ( portTickType ) 0 );
}

when the received packet is 1 byte, everything works fine, notice that
I am not using any delay for the queue part, but when a large data is
coming I get h4_invalid packet type error. I am assuming that
freeRTOS is not taking that long to send a pointer to another task, so
why does the btstack freez eventhough the bluetooth task is the
highest priority in my program?. Also is there a way to delay incoming
packets? Thanks a lot
On Tue, Jul 10, 2012 at 4:01 AM, Matthias Ringwald

zeid Ayssa

unread,
Jul 20, 2012, 12:18:05 PM7/20/12
to btsta...@googlegroups.com
Hi Matthias,
for some reason the the inquiry function is not finding
devices anymore:

hci_send_cmd(&hci_inquiry, HCI_INQUIRY_LAP, 15, 0);

it was working fine the whole time, and suddenly it would barely find
one device if not nothing at all. What do you think is the problem?
thanks

On Tue, Jul 10, 2012 at 4:01 AM, Matthias Ringwald

Matthias Ringwald

unread,
Jul 20, 2012, 2:16:40 PM7/20/12
to btsta...@googlegroups.com
Hi Zeid

let's have a look into the crystal ball...

hm...

If you didn't change the software, I'd say your hardware got modified one way or the other. maybe the antenna got broken..

sorry, no better idea.

best
matthias

小兽

unread,
Jul 22, 2012, 9:42:14 PM7/22/12
to btsta...@googlegroups.com
HI zeid and  Matthias
   I have got the same problem,I want to take a test about the frequency offset and PA .The problem is that  I do not have the  HCI command to set the tx carrier Frequency to one of 2402~2480.
   anybody may show me some information about how to test this mode(CC2560_PAN1323etu), I can get the device of  network analyzer,frequency spectrograph,and some frontline bluetooth device.
   
   But when I use Bluetopia (LM3S9B96) with SPP demo program ,it works ok.   The same init code ,the same HCI inquiry.....  0.0   0.0

2012/7/21 Matthias Ringwald <matthias...@gmail.com>

叶颖

unread,
Jul 23, 2012, 2:41:50 AM7/23/12
to btsta...@googlegroups.com

Hi,zeid Ayssa
    I got the same problem with you some times ago.At last I solve it,because i'm using a wrong init script...where it is CC2560->PAN1315, CC2567->PAN1323. hope it helpful to you.tks

2012/7/21 Matthias Ringwald <matthias...@gmail.com>

Matthias Ringwald

unread,
Jul 23, 2012, 3:57:27 AM7/23/12
to 小兽, btsta...@googlegroups.com
hi

You can ask TI on their E2E forum. http://e2e.ti.com/support/default.aspx (not sure which topic to click).

matthias

Zeid Ayssa

unread,
Jul 23, 2012, 7:49:47 AM7/23/12
to btsta...@googlegroups.com

Hi,
    Thanks for your reply, can you pls tell me where can I get that init script ? 

小兽

unread,
Jul 24, 2012, 5:45:40 AM7/24/12
to btsta...@googlegroups.com
Hi Zeid
   you can get it from the  Bluetopia  ,It works fine .

2012/7/23 Zeid Ayssa <ayssa...@gmail.com>

Druta Christian-Filip

unread,
Jun 23, 2013, 6:13:02 PM6/23/13
to btsta...@googlegroups.com
Hello,
I am trying to integrate btStack in MSP430F5483A (Metawatch Frame WDS112 Digital).
My target is to make it a Master Bluetooth Device: Discover and connect to a sensor.
I managed to discover the devices around, I managed to initiate the connection: 
hci_send_cmd(&hci_create_connection, devices[deviceNo].address, /*EPacketsDM3*/PacketType /*0xCC18*/,
/*devices[deviceNo].pageScanRepetitionMode*/0x01,           Reserved/*0x00*/, devices[deviceNo].clockOffset, ERoleSwitchNotAllowed);
I get the event:HCI_EVENT_CONNECTION_COMPLETE

After this normally it will go into this function:l2cap_handle_connection_success_for_addr(address, handle);
And here is my problem, the code is blocking here.


I compared two methods: 
-MSP430 Metawatch connects to PC under Linux (hcidump installed )
-PC under Linux (hcidump installed ) connects to a sensor.

The difference is that the first solution does not open a L2CAP connection:over ACL.



I am blocking here:
what should I execute:
-hci_send_cmd(&l2cap_create_channel, devices[deviceNo].address, PSM_RFCOMM);
-bt_send_cmd(&hci_write_authentication_enable, 1); 
-hci_authentication_active_for_handle
-l2cap_create_channel_internal(connection, rfcomm_packet_handler, *addr, PSM_RFCOMM, l2cap_max_mtu());

Another problem that I face is that when I am comparing the effect of connection to a computer with HCIDUMP, the PC sends a role_switch command and this makes my work more difficult.
I have no debugger for Metawatch, debugUART module makes the controller to restart because of: "security violation"


Can you tell me what function to add please and after what should be my approach to open the RFCOMM channel and after that to register in the run_loop the connection.


Thanks in advance!
Connection Linux-CapteurCardio text.txt
Connection Metawatch - Linux text.txt

Matthias Ringwald

unread,
Jul 1, 2013, 5:37:36 AM7/1/13
to btsta...@googlegroups.com
Hi Druta

In this was my project, I'd try to get a way to either get access to a debug UART or collect Bluetooth packet logs on either end.

You say that function:l2cap_handle_connection_success_for_addr is blocking. BTstack doesn't block/waits anywhere. Do you mean that nothing happens after that?

If you want to establish an RFCOMM connection, you can just send a rfcomm_create_connection… command. BTstack will setup the connection, l2cap, and rfcomm multiplexer and channel for you.

best
 Matthias


To unsubscribe from this group and stop receiving emails from it, send an email to btstack-dev...@googlegroups.com.

To post to this group, send email to btsta...@googlegroups.com.
Visit this group at http://groups.google.com/group/btstack-dev.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
<Connection Linux-CapteurCardio text.txt><Connection Metawatch - Linux text.txt>

leif.e...@gmail.com

unread,
Dec 17, 2013, 11:08:54 AM12/17/13
to btsta...@googlegroups.com
Hello.  I am very interested in btstack, it looks like a very good implementation of Bluetooth.

I am attempting to test btstack on an MSP using the EXP430F5438A experimenter board with the PAN1323EMK.  I retrieved the startup script and moved the SPP Counter example project into code composer 5.  The device does not become discoverable when running the program.  Trying to find out what is going on; I uncommented and changed the printf on line 477 of hci.c to also show the size of packets.
 
When starting, the debug port shows this 30 times:

HCI:EVENT(size):0e, 6
hci.c: event_handler called with event packet of wrong size 1, expected 216 => dropping packet

Then this is shown:

HCI:EVENT(size):0e, 12
BD-ADDR: 00:17:e7:fe:cd:c8
hci.c: event_handler called with event packet of wrong size 1, expected 216 => dropping packet
hci.c: event_handler called with event packet of wrong size 1, expected 216 => dropping packet

While generating the debug output both LED one and two are on solid, then when the startup is complete, LED1 flashes very faintly perhaps at 5Hz.

Has anyone experienced this or perhaps knows what is happening?  I believe that that a packet is getting dropped for every command in the initialization script.

Thanks for any help you can provide.

Matthias RIngwald

unread,
Dec 17, 2013, 4:23:52 PM12/17/13
to btsta...@googlegroups.com
Hello Leif

welcome to the list. Do you have the lastest version from SVN? I only recently added the asserts for the packet size and didn’t get it right the first time. Despite these, there’s a similar issue on the tracker: https://code.google.com/p/btstack/issues/detail?id=357

I’ll try to run the example again on Thursday or Friday and see if it’s also broken for me

best
matthias


leif.e...@gmail.com

unread,
Dec 17, 2013, 6:27:15 PM12/17/13
to btsta...@googlegroups.com
Hello Matthias,

I was working with revision 2000.  I commented out the packet length assertion at the beginning of event_handler and now the module becomes discoverable.

Thanks for your help.

Matthias Ringwald

unread,
Dec 19, 2013, 5:29:26 PM12/19/13
to btsta...@googlegroups.com
HI Leif

I just run the SPP Counter example from SVN on the MSPEXP430F5438 without problems. Could you try a clean checkout or so? 

best
matthias

Matthias Ringwald

unread,
Dec 20, 2013, 2:29:56 PM12/20/13
to btsta...@googlegroups.com
Hi Leif, and others.

The same problem was just reported on the issue tracker and even diagnosed. I’ve fixed it in r2013. Could you try with that?

best
matthias

leif.e...@gmail.com

unread,
Jan 2, 2014, 5:32:12 PM1/2/14
to btsta...@googlegroups.com
Thanks Matthias,

The problem seams to be fixed.  The assert in hci.c at line 466 no longer needs to be commented out.

leif.e...@gmail.com

unread,
Jan 6, 2014, 4:42:02 PM1/6/14
to btsta...@googlegroups.com
I am starting to get into this stack and am a bit overwhelmed.  I wish to connect to another device using SPP which also requires a pin number using the MSPEXP430F5438.  Is there something like a how to guide to do this?  Where is a good place to start looking for an example?  I am experimenting with the sdp_rfcomm_query.c example but am not sure where to hook into to select a discovered device and attempt to pair with a pin number.

Thanks

Matthias Ringwald

unread,
Jan 6, 2014, 5:31:30 PM1/6/14
to btsta...@googlegroups.com
Hi Leif

Please start with reading the BTstack Manual http://bluekitchen-gmbh.com/docs/btstack-gettingstarted-1.1.pdf

With the sdp_rfcomm_query, you’ll get a list of remote devices. How to select one of them to connect to is up to you. Then you can use the RFCOMM API to establish a connection. This is e.g. in section 4.10 of the manual. Pairing of devices is explained in 4.7.

Please ask for more details if the Manual and/or the API doc in the .h files are not sufficient.

best
matthias

On 06.01.2014, at 22:42, leif.e...@gmail.com wrote:

> I am starting to get into this stack and am a bit overwhelmed. I wish to connect to another device using SPP which also requires a pin number using the MSPEXP430F5438. Is there something like a how to guide to do this? Where is a good place to start looking for an example? I am experimenting with the sdp_rfcomm_query.c example but am not sure where to hook into to select a discovered device and attempt to pair with a pin number.
>
> Thanks
>
>

leif.e...@gmail.com

unread,
Jan 9, 2014, 6:42:46 PM1/9/14
to btsta...@googlegroups.com
Hello Matthias,

Since there is no example on connecting to a remote SPP, I started with the hid_demo.  I removed the keyboard requirement from the HCI_EVENT_INQUIRY_RESULT and receive the device address and let the inquiry be canceled.  Then on the command complete event, I send a rfcomm_create_channel_internal.  What channel should I connect with?  Any way after that, I get a HCI_EVENT_PIN_CODE_REQUEST back.  From there whether I send the correct or incorrect pin number I get this:

L2CAP_EVENT_CHANNEL_OPENED status 0x5 addr xx:xx:xx:xx:xx:xx handle 0x0 psm 0x3 local_cid 0x0 remote_cid 0x0 local_mtu 196, remote_mtu 48
L2CAP_EVENT_CHANNEL_OPENED for PSM_RFCOMM, status 5

RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE status 0x5 xx:xx:xx:xx:xx:xx handle 0x0 channel #0 cid 0x01 mtu 190
RX: EHCILL_GO_TO_SLEEP_IND

But I never get a RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE packet or any data with RFCOMM_DATA_PACKET packet.  I know the device sends data as soon as a connection is made.

What should be done in a high level to search for a broadcasting device then connect to an SPP service on it?

I see there is some sdp_query_rfcomm_channel_and_name functions which I could call on the address found with the inquiry but I am unsure what to use for a uuid or service search pattern.

Do you know what I may be missing?  Thanks for any help you can provide.

leif.e...@gmail.com

unread,
Jan 9, 2014, 7:33:02 PM1/9/14
to btsta...@googlegroups.com
I think I have it connecting now.  I was sending the wrong amount of bytes for the pin number which is not 4 characters.  Also, I needed to connect to port 1 with the RFCOMM.  The connection drops after a bit from what I believe is the RFCOMM connection not reading data fast enough.  I believe I will have to look into manual control of the tokens and buffer the stream of data.

How would I use an sdp_query_rfcomm_?  Is the uuid somthing I need to find?

Do you know where I can lookup some of these details:

L2CAP_EVENT_CREDITS local_cid 0x40 credits 1
L2CAP_DISCONNECT local_cid 0x40 reason 0x13
L2CAP signaling handler code 6, state 8

L2CAP_EVENT_CHANNEL_CLOSED local_cid 0x40
L2CAP_EVENT_CHANNEL_CLOSED cid 0x40, mult 0
RX: EHCILL_GO_TO_SLEEP_IND

Or such things as you knowing to check byte 12 and 13 for a value to determine if it is a keyboard?

Thanks for all your help.

Matthias Ringwald

unread,
Jan 10, 2014, 9:52:52 AM1/10/14
to btsta...@googlegroups.com
Hi Leif

to get all SPP ports you can use the sdp_query_rfcomm_ functionality with UUID 0x1002 which should stand for “SPP” as in the sdp_query_rfcomm.c example.

An RFCOMM connection shouldn’t drop. You can still use RFCOMM credit based flow control - should be explained in the manual, too.

You cannot know if a device has a SPP by looking at it’s Class of Device. If the device sends Extended Inquriy Responses (Bluetooth 2.1+) you might get a hint there. Usually, you either can hard code the remote address or show a list with remote device names to a human to have him pick one. :)

best
matthias



Reply all
Reply to author
Forward
0 new messages