This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 - Bluetopia - how to send a string automatically?

Other Parts Discussed in Thread: MSP430F5438A

Hi,
i am experimenting with the MSP430F5438A + PAN1326 + Android Phone + Bluetopia + SPPDemo

everything works fine so far with the debug-console and i already implemented some adoptions to the code:
i managed autopairing, store/read a link-key to flash memory and so on...

now i tried to run some commands automatically one after each other, but i cannot solve the problem:
i entered a new command "test" at the debug-console to open a new method:

void Test(){
ClientMode();
ReadKeyFromFlashToSystem();
OpenRemoteServer();
Write();
CloseRemoteServer();}

i hope it is clear what this program should do:
change to client mode, read the stored linkkeys, open the port to the server, write a string and finally close the server!

when i run those methods step by step at the debug-console everything works fine!!! no problems!
but when the comands shall be called automatically by my method it throws an error...

i think i already found out the problem with debugging:
it seems to me, that no event-callbacks occur between the commands!?
so it tries to write the string before the etPort_Open_Confirmation - Event is called.

i also tried to put delays between the commands, but this doesnt help!?
i also tried to put a while(connected!=true), but this loops forever, because the Event never comes...

so the question is, where shall i place the code, or how shall i call those methods that there is time in between for the events?!? interrupts? the scheduler?

thanks for your help!

  • Hi, i could still need some help for this problem.
    what happens between the two debug-commands Open and Write? (except the open_confirmation_event)
    when i enter those commands at the Debug-console everything works fine.
    when i use the method, where those two methods are called automatically, it will not work.
    the write-command doesn't throw an error - it seems to send the character, but it will not arrive at the other side!?
    i also tried to use delays after opening the port - exactly the same behavior.

    thanks.

  • Could you provide more details? At what point do ou get the error? what error message do you get? Which APIs are you calling in your function? Most likely, there is an event callback associated to one of the commands and that's why you are getting the errors. You can look for the event callbacks associated to each commands in the API document.

    Miguel

  • there is no error... it simply doesn't do what it should do :o)

    as i posted before, when i enter the commands at the debug-console one after each other, everything works fine: read the linkkey, open the port to the remote device, write a string and finally close the port.

    when i use my new method to do this steps automatically, everything seems to work too, but the string doesnt arive at the remote device! open and close port are done with no errors at all! the write command also confirms with "Wrote 1." at the debug console as it should look like. but i dont understand, why the string doesnt arrive at the other side!?

    now i tried to check the open_confirmation_event and tried to write the string after this event occured, but this doesnt improve the result.

    so the question is, is there another event i have to wait for before writing?
    maybe i overlooked an event?
    debugging is not so easy for me, because of the many Uart-Interrupts :o)

    i try to post some code here later.

  • Daniel,

    Is there an actual connection between the server and the Client? Because if you try to do a write before that it will obviously fail. Do you get an etPort_Open_Confirmation event and Status as 0 for the PortOpenStatus?

    Regards,

    Stonestreet One.

  • Hi SS1,

    yes i get the open_confirmation-event.  here i copy the content of the debug-console. i start my method to send a string with the command "testrd". it automatically goes to client, read the stored link-key, open a port, wait for the confirmation-event, write a string, close port. as you can see at the debug-console, there is no error at all, and it says "wrote 1." what meens, no errors during writing ...

    ******************************************************************
    * Command Options: Server, Client, Help *
    ******************************************************************

    Choose Mode>testrd

    ******************************************************************
    * Command Options: Inquiry, DisplayInquiryList, Pair, *
    * EndPairing, PINCodeResponse, PassKeyResponse, *
    * UserConfirmationResponse, *
    * SetDiscoverabilityMode, SetConnectabilityMode,*
    * SetPairabilityMode, *
    * ChangeSimplePairingParameters, *
    * GetLocalAddress, GetLocalName, SetLocalName, *
    * GetClassOfDevice, SetClassOfDevice, *
    * GetRemoteName, SniffMode, ExitSniffMode, *
    * Open, Close, Read, Write, *
    * GetConfigParams, SetConfigParams, *
    * GetQueueParams, SetQueueParams, *
    * Loopback, DisplayRawModeData, *
    * AutomaticReadMode, SetBaudRate, Send *
    * Help, Quit *
    ******************************************************************

    SPP_Open_Remote_Port success.

    Client>
    atLinkKeyRequest: 0xBCF5AC730013

    GAP_Authentication_Response success.

    Client>
    SPP Open Confirmation, ID: 0x0004, Status 0x0000.
    Wrote: 1.
    Client Port closed.

    Client>

  • here is the code for my method testrd() - pretty simple statemachine, to proceed step by step.

    static int TestRD()
    {
    statemachine = 0;
    AutoSendCommand(0);

    return 0;
    }

    static void AutoSendCommand(int step)
    {

    switch (step) {
    case 0:
    if(statemachine==0){
    ClientModeRD();
    statemachine++;
    AutoSendCommand(1);}
    else
    statemachine=0;
    break;
    case 1:
    if(statemachine==1){
    ReadKeyFromFlashToSystem();
    statemachine++;
    AutoSendCommand(2);}
    else
    statemachine=0;
    break;
    case 2:
    if(statemachine==2){
    OpenRemoteServerRD();
    statemachine++;}
    else
    statemachine=0;
    break;
    case 3:
    if(statemachine==3){
    CreateSendString();
    statemachine++;
    AutoSendCommand(4);}
    else
    statemachine=0;
    break;
    case 4:
    if(statemachine==4){
    //BTPS_Delay(4000);
    //__delay_cycles(1000000);
    Write(NULL);
    // WriteRD();
    //BTPS_Delay(4000);
    //__delay_cycles(1000000);
    statemachine++;
    AutoSendCommand(5);}
    else
    statemachine=0;
    break;
    case 5:
    if(statemachine==5)
    CloseRemoteServerRD(); 
    statemachine=0;
    break;
    default:
    break;
    }
    }

    and here the confirmation-event, where the autosend(3) is called, after the port opening was successful:

    case etPort_Open_Confirmation:
    /* A Client Port was opened. The Status indicates the */
    /* Status of the Open. */
    Display(("\r\n"));
    Display(("SPP Open Confirmation, ID: 0x%04X, Status 0x%04X.\r\n", SPP_Event_Data->Event_Data.SPP_Open_Port_Confirmation_Data->SerialPortID,
    SPP_Event_Data->Event_Data.SPP_Open_Port_Confirmation_Data->PortOpenStatus));

    /* Check the Status to make sure that an error did not */
    /* occur. */
    if(SPP_Event_Data->Event_Data.SPP_Open_Port_Confirmation_Data->PortOpenStatus)
    {
    /* An error occurred while opening the Serial Port so */
    /* invalidate the Serial Port ID. */
    SerialPortID = 0;
    Connection_Handle = 0;

    /* Flag that we are no longer connected. */
    Connected = FALSE;
    }
    else
    {
    /* Flag that we are now connected. */
    Connected = TRUE;

    /* Query the connection Handle. */
    ret_val = GAP_Query_Connection_Handle(BluetoothStackID, LinkKeyInfo[0].BD_ADDR, &Connection_Handle); // RD: statt SelectedBD_ADDR kommt hier direkt die einzige gespeicherte rein!

    if(ret_val)
    {
    /* Failed to Query the Connection Handle. */
    DisplayFunctionError("GAP_Query_Connection_Handle()",ret_val);

    ret_val = 0;
    Connection_Handle = 0;
    }
    AutoSendCommand(3); 
    }
    break;

    PS: sorry, i dont know how to insert the code with the correct indents?!

  • Daniel,

    Is it possible to send us your C file or attach it here?

    Thanks,

    Stonestreet One.

  • 6724.SPPDemo.zip

    i attached my whole project for you.

    short description:
    i started with the SPP-Demo and implemented only a few changes:
    - changed the clock to internal DCO (8Mhz)
    - changed the debug-baudrate to 115k (9600 didn't work - don't know why!?)
    - implemented autopairing (0000)
    - implemented automatic key-storage to the flash
    - and finaly, i tried to implement the automatic sending of a string, which causes the problems i posted in this thread. the reason for this step is, the final project shall send a string as reaction to a button-press to the android device.

    i hope you could help me solving the problem!

    thanks!

  • Daniel,

    Does the project only work with CCS? Is there also an additional driverlib folder? What does it do?

    Regards,

    Stonestreet One.

  • Hi SS1,

    i just use CCS5 and cannot say if it works with an other environment!?

    the driverlib is from one of the MSP430-Samples and it is barely used. it is just implemented because i copied some code from an MSP430-Sample for reading and writing the Flash where the linkkey is stored...
    so it should not do anything with the bluetooth related code!?

    Daniel

  • today i spent a lot of time finding the problem ... no success

    when i send the sting manually via the debug-console i do following:
    client-mode, open port, write, close port - works perfekt!

    when i try to run the method to do this automatically:
    client-mode, open port, write, close port - everything is running without any error, but the write doesnt send the string to the other side!

    so i tried to debug the write-part in detail - no success
    everytime i run the write-Method from the debug-console it works (typing WRITE+enter)
    when i use the Method Write(NULL) in the code it finishes without any error, but it doesnt send the string to the other side! I also tried to use a new parameter with zero parameters instead of NULL - same result.
    but the write which is started from the console does also simply start the write-Method!? where is the difference?
    i am getting insane :o)

  • Daniel,

    I'm not able to create a connection with your code with one MSP430 as Server and the other as Client. Can you please tell me the Android application you are using and steps to reproduce the issue. I assume that since you are reading keys from flash that you pair once before running the testrd steps?

    Regards,

    Stonestreet One.

  • Hi,
    yes, thats correct, i did the pairing once, and since this moment the key is available from the flash. so i didnt care about this to have it perfekt at the moment - but it works, i just tested it again right now.

    Steps:
    - run the code
    - initiate the pairing from the phone and the MSP will automatically accept the pairing with code 0000
    - link-key is stored to the flash
    - reset the controller (workaround, will be fixed later)
    - enter "testrd" to the console (this will read the linkkey from the flash and do the other steps for auto-sending...)
    - all steps done without error ...
    - if you want to try the manual write now:
    - enter "openrd" to the console (similar to "open 1 5")
    - enter "write" to the console -> tada!!! here the write will be performed!

    The android-app is running as server, but it should also work with other servers!?
    i could also send you the android-app by mail, if you could give me an address. (if you do not want to post your address here, please send me a mail to anut_peach@gmx.at and i will respond..)

    thanks!

  • HAAAAAAAAAAA!!!!

    i didn't find the correct solution, but i found a workaround that works!  :o)

    The system needs to do anything between the open-confirmation-event and the write!?

    not working attempt:
    - waiting for the open_confirmation_event
    - then try to write the string...

    workaround that works:
    - waiting for the open_confirmation_event
    - start a timer - waiting and for the interrupt.
    - after some time the timer-interrupt comes and the system seems to have finished all necessary steps for the connection ....
    - i start the write - and now it works!!!!!!!

    so it seems, that the system has to finish anything after the confirmation_event before writing the string is possible!

    it would be great, if you could help me to find this "anything", and make a better solution that works, because my solution with the timer is just a quick&dirty workaround!

    thanks!

  • Daniel,

    Can you take a look at the SPP_Purge_Buffer interface with the SPP_PURGE_MASK_TRANSMIT_FLUSH_BIT bit mask? That would help you with this.

    Thanks,

    Stonestreet One. 

  • Hi,

    could you give me some additional information to this SPP_Purge_Buffer?!

    i searched in all .c-files for this SPP_PURGE_MASK_TRANSMIT_FLUSH_BIT, but no result ...

    where can in find it? what shall i do with it when found?

    PS: isnt there any sample out there for doing this? (connect-send-disconnect)

    thanks for your help...

  • Daniel,

    You can find it in SPPAPI.h. There is a more detailed description in that file.

    Thanks,

    Stonestreet One.