2 Replies Latest reply on Sep 29, 2017 11:27 AM by user_478787221

    UART receive unresponsive while scanning and transmitting back response info.

    user_478787221

      I am using the pioneer kit connected to the PC which is to emulate an MCU which will eventually be hooked to a BLE module.   The PC sends commands to the module for it to enter various states (i.e., scanning, advertising, broadcasting, etc.).  I am using cool term as a terminal emulator.

       

      When entering scanning mode, and actively triggering off  CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT, which sends data back to the PC (MCU) with an onslaught of data, transmittal of any further commands by the PC is ignored .   So I cannot exit scanning mode.  If I reduce the transmission activity by gutting contents under CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT. I can proceed to change to other modes with my transmitted commands.  So this appears to be a bandwidth problem.   Communication occurring at 115200 baud.   I have flow control enabled, but have not yet attempted an Rx Interrupt Method.  (Rx Fifo Level).   The program in different states (modes) simply looks to see if there is any data available in the Rx buffer and processes it accordingly.  This is part of the main loop HandleBleProcessing();

       

      Any way I can give higher precedence to received data than to transmitted data, so that I can still transmit data to the module from the PC (MCU) and it be acted upon accordingly.

        • 1. Re: UART receive unresponsive while scanning and transmitting back response info.
          user_478787221

          The cause of my UART Rx shutting down is not what I thought.  This small excerpt from the code (derived from Central AND Peripheral project) is what is causing the unresponsiveness, and quite frankly, I don't see this portion of the code doing what it is claiming to be doing. It is not checking against a list of already stored values.  It simply seems to be checking if this is not a CYBLE_GAPC_SCAN_RSP type and it is also checking to make certain the number of devices is not exceeded.

           

          //== Copy the address of the devices to peerAddr[] array if the received advertising packet is not a duplicate one==//

                         

                          if((DevicesNearBy <= CYBLE_MAX_ADV_DEVICES) && (advReport->eventType!=CYBLE_GAPC_SCAN_RSP))

                          {

                              for(i = 0u; i < CYBLE_GAP_BD_ADDR_SIZE; i++)

                              {

                                  peerAddr[DevicesNearBy].bdAddr[i] = advReport->peerBdAddr[i];

                              }                   

                             

                              // Increase the number of peer devices when

                              // received aadvertising packet from different peer devices.

                              ++DevicesNearBy;

                             

                          }

          • 2. Re: UART receive unresponsive while scanning and transmitting back response info.
            user_478787221

            I've replaced the non-functioning portion of code with the following:   It should save up to 8 advertisers and prevent duplication.  May later put in a timer which is triggered off the DeviceNearBy = 8, so that after a short period (eg, 2 minutes), the list will refresh itself.

            My UART Rx is no longer shutting down, so I can exit the scanning state when I need to.

             

            char member[12];

            char addrByte[1];

            bool EqualFlag;

            uint8 i,test;

             

             

             

            case CYBLE_EVT_GAPC_SCAN_PROGRESS_RESULT:

                       

                        //copy the advertising packet recieved to advReport//

                        advReport=(CYBLE_GAPC_ADV_REPORT_T *)eventParam;

                       

                        //NOTE:   the peerBdAddr is in two forms:  in its raw form, it is in an array of 6 integer values.

                        //From the user persective, is a 12 character hexadecimal value.   Store the value in its raw form,

                        //make comparisons in the raw form, but display the hexadecimal form.

             

                     

                        //Convert raw peer Address to hexadecimal form

                        memset(member,0,MEMBER_IDX);

                        sprintf(addrByte,"%2.2x",advReport->peerBdAddr[5u]);

                        memcpy(member,addrByte,2);

                        for(i=5;i>0;i--){

                            sprintf(addrByte,"%2.2x",advReport->peerBdAddr[i-1]);

                            strcat(member,addrByte);

                        };   

                        

                           

                            //==Copy the address of the devices to peerAddr[] array if the received advertising packet is not a duplicate one==//

                       

                        if((DevicesNearBy <= CYBLE_MAX_ADV_DEVICES) && (advReport->eventType!=CYBLE_GAPC_SCAN_RSP)){

                           

                            if(!DevicesNearBy){

                                for(i=6;i>0;i--)

                                    peerAddr[0].bdAddr[i-1] = advReport->peerBdAddr[i-1];   

                               

                                #ifdef PRINT_MESSAGE_LOG

                                PrintPeerAddress(advReport, member, DevicesNearBy);

                                #endif

                               

                                DevicesNearBy++;

                               

                            }

                            else {     //DevicesNearby Nonzero

                                EqualFlag = 0;

                                for(i=0; i<DevicesNearBy;i++){

                                    if(!memcmp(peerAddr[i].bdAddr,advReport->peerBdAddr,sizeof(peerAddr[i].bdAddr)))    //meaning the two strings are equal

                                        EqualFlag = 1;

                                }//end for(i)

                                if(!EqualFlag){   //meaning we could NOT find a match

                                   

                                    for(i=6;i>0;i--)

                                        peerAddr[DevicesNearBy].bdAddr[i-1] = advReport->peerBdAddr[i-1];

                         

                                    #ifdef PRINT_MESSAGE_LOG

                                    PrintPeerAddress(advReport, member, DevicesNearBy);

                                    #endif

                                    DevicesNearBy++;

                                    test = 1;

                                }//end if(!EqualFlag)       

                               

                            }//end if_else(DevicesNearBy)  

                       

                        }//end if((DevicesNearBy <= CYBLE_MAX_ADV_DEVICES) && (advReport->eventType!=CYBLE_GAPC_SCAN_RSP))

                       

                      

                        break;

             

             

            void PrintPeerAddress(CYBLE_GAPC_ADV_REPORT_T * AdvReport, char Addr[20], uint8 DeviceNumber){

             

             

                    char index[1];

               

                    UART_UartPutString("\r\n\r\nDevice Number: ");

                    sprintf(index,"%d",DeviceNumber);

                    UART_UartPutString(index);

                    UART_UartPutString("\r\n");

                   

                    //==EVENT TYPE=====//

                           

                    UART_UartPutString("eventType:");

                           

                    if( AdvReport->eventType==CYBLE_GAPC_CONN_UNDIRECTED_ADV){

                        UART_UartPutString("Connectable undirected advertising\r\n");

                    }

                    else if(AdvReport->eventType==CYBLE_GAPC_CONN_DIRECTED_ADV){

                        UART_UartPutString("Connectable directed advertising\r\n");

                    }

                    else if(AdvReport->eventType==CYBLE_GAPC_SCAN_UNDIRECTED_ADV){

                        UART_UartPutString("Scannable undirected advertising\r\n");

                    }

                    else if(AdvReport->eventType==CYBLE_GAPC_NON_CONN_UNDIRECTED_ADV){

                        UART_UartPutString("Non connectable undirected advertising\r\n");

                    }

                    else if(AdvReport->eventType==CYBLE_GAPC_SCAN_RSP){

                        UART_UartPutString("SCAN_RSP\r\n");

                    }

                           

                    //UART_UartPutString("\r\n");

                           

                    //==PEER address type===//

                    UART_UartPutString("peerAddrType: ");

                           

                    if(AdvReport->peerAddrType==CYBLE_GAP_ADDR_TYPE_PUBLIC){

                        UART_UartPutString("PUBLIC\r\n");

                    }

                    else if(AdvReport->peerAddrType==CYBLE_GAP_ADDR_TYPE_RANDOM){

                        UART_UartPutString("RANDOM \r\n");

                    }

                           

                           

                    UART_UartPutString("peerBdAddr: ");

                    UART_UartPutString(Addr);

                    //UART_UartPutString("\r\n\r\n");

               

            }//end PrintPeerAddress(  )