Jump to content
43oh

Adafruit Bluefruit LE SPI friend with MSP432


Recommended Posts

Hello everyone,

 

I am a newbie here, just received my MSP432 launchpad few days ago and I'm willing to develop a wireless bluetooth communication between my MSP432+Bluefruit LE SPI and my computer.

 

I downloaded the librairies from Adafruit that are designed for Arduino and I think I succeeded to convert a honest part of the code for Energia.

Though, I still have an important problem that stops me to go forward. 

 

Indeed the Bluefruit LE SPI dongle communicate through some commands called ATCommand, and I don't succeed to transmit those commands through the dongle.

 

As an example this is the original Arduino code for a factory reset of the bluetooth device :

 /* Perform a factory reset to make sure everything is in a known state */

    Serial.println(F("Performing a factory reset: "));
    println("AT+FACTORYRESET");
    bool isOK = ble.waitForOK();

  // Bluefruit need 1 second to reboot
  delay(1000);

  // flush all left over
  ble.flush();

    if ( ! isOK ){
      error(F("Couldn't factory reset"));
    }

In Arduino they use the println to transmit the command but in Energia I just get the "AT+FACTORYRESET" back in my Serial monitor but don't believe the device receives it.

 

I tried to use SPI.transfer to send the message the following way but still get a failure result for the factory reset process :

bool Adafruit_BLE::factoryReset(void)
{
  char c;
    SPI.begin();
    // println("AT+FACTORYRESET");
    
    
    for (const char * p = "AT+FACTORYRESET" ; c = *p; p=p+2) {
      digitalWrite(18,LOW);
      SPI.transfer(0x10); // First Byte indicating that a COMMAND is sent according to Adafruit SDEP protocol
      SPI.transfer(c);   // First byte of data
      const char * d = p+1;
      char e = *d;      // Second byte of data
      SPI.transfer(e);
      digitalWrite(18,HIGH);
    }
    println("AT+FACTORYRESET");
     
  
  bool isOK = waitForOK();

  // Bluefruit need 1 second to reboot
  delay(1000);

  // flush all left over
  flush();

  return isOK;
} 

If anyone succeeded to connect this bluetooth dongle through SPI with MSP or has an idea of how to do it, pleeaase help me   :)

 

PS : It seems that this operation (like any other) is not achievable because the IRQ pin (This is the nRF51 -> Arduino 'interrupt' pin that lets the Arduino or MCU know when data is available on the nRF51, indicating that a new SPI transaction should be initiated by the Arduino/MCU) is never on HIGH. It is weird because normally after received any command message, it is supposed to turn on...

Link to post
Share on other sites

I had to add an "SPI.setDataMode(SPI_Mode0);" call to make the MSP432 SPI work using the Reaper's UIPEthernet library. Also, it defaults to LaunchPad Pin 18 for CS and the SPI library manages the CS. If you want a different CS you use SPI.begin(SS); where SS is the PIN number you are using. Most of the code I have seen manipulates the CS outside the library so specifying the CS in the SPI.begin may not matter although I think the SPI library will mess with Pin 18 if you don't which may cause other problems.

 

I am planning to continue testing tonight trying to clarify some of the MSP432 issues I am seeing.

 

B

Link to post
Share on other sites

I found the solution, the data wasn't transmitted correctly initially so there was nothing on the buffer and so the process was stuck in an available()==0 loop.

 

I finished to code this driver completely (I think ?), here is a link for you folks :

https://github.com/chillyjee/BluefruitSPI

 

Developed for MSP432 but surely compatible with any MSP43x platform  ;)

 

Leave any questions.

Link to post
Share on other sites
  • 4 weeks later...

chillyjee,

 

This is pretty damn cool! Nice work. I also have a Texas Instruments MSP432 P401 Launchpad, and I've been playing around with it to familiarize myself with the board. 

 

I would like to implement you project into my MSP board, and see what it can do (as I also have a Bluetooth LE UART Friend; not sure which Bluetooth LE you are using)

 

Can I ask quickly how you tested your code?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...