Bluetooth shield not working when code compiled in Atmel Studio

In my project I’m using the following Bluetooth shield with Arduino Leonardo.

When the code is compiled and uploaded through the Arduino IDE everything works as expected.
However, when I use the same code in Atmel Studio 6, the bluetooth shield is not switched to inquiry mode (red/blue led not blinking) and I’m not able to connect to it.

I configured Atmel Studio according to this tutorial and tested it with a couple of simple projects. The setup() and loop() functions were called as expected and everything was working.

I was using the SoftwareSerial library for communication with the bluetooth shield. I wasn’t able to find the cause of this issue, I was just suspecting that there might be some missing (or incorrect) preprocessor defines in project settings, which might cause e.g. incorrect timing in library functions. Checked everything, but I still have no idea why it’s not working.

Here is the code:

/* Upload this sketch into Crowduino and press reset*/
#include <avr/io.h>
#include "Arduino.h" 
#include <SoftwareSerial.h>   //Software Serial Port

#define RxD 6
#define TxD 7
SoftwareSerial blueToothSerial(RxD,TxD);
void setup() 
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
void loop() 
  char recvChar;
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar =;
    if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
      recvChar  =;
void setupBlueToothConnection()
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=CrowBTSlave\r\n"); //set the bluetooth name as "CrowBTSlave"
  blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.

Any help appreciated. Thanks.