Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: HC-05 and SPI interfere?

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    5

    HC-05 and SPI interfere?

    Hi
    I am trying to send AT codes to an HC05 unit from a Teensy4.0 using Serial2. A program that emulates the problem is below. The project calls for RAM and EEPROM to be addressed using SPI, the select lines being on D3,4&5. These all work normally and as would be expected and are not included in the emulation program. I have a 3.3V PSU with the enable line on D31. The HC-05 enable line is on D32.
    The problem is that there is no response from the HC-05 unit unless I include the SPI.end() instruction. Without this the program appears to hang. WIth the SPI.end instruction I can program the HC-05 unit as normal via the IDE monitor, no problem. I have no logic analyser so I am tipping about in the dark here. Can somebody tell me what I am doing wrong?
    Many thanks
    Nigel
    Code:
    #include <SPI.h>                // for communication on SPI bus (external ram & eeprom)
    #define blue Serial2            // RX2,TX2 on Teensy4
    byte EN = 32;                   // enable line on HC05 module
    byte EN7 = 31;                  // enable on 3.3volt power supply
    byte BLUSEN = 30;               // connected signal from Bluetooth module
    
    void setup()
    {
      pinMode(EN7, OUTPUT);       // to drive the enable pin on PSU
      pinMode(EN, OUTPUT);        // this pin will pull the HC-05 pin 34 (EN/key pin) HIGH to switch module to AT mode
      SPI.begin();                // initiate the SPI system
      SPI.end();                  // stop SPI - AT system fails if SPI left functioning
      digitalWrite(EN7, LOW);     // force psu enable low no power to HC5
      delay (1000);               // time to allow PSU to spin down
      digitalWrite(EN, HIGH);     // put power on EN before power on Vcc forces default speed
      digitalWrite(EN7, HIGH);    // enable power supply
      Serial.begin(115200);
      blue.begin(38400);          // set to default speed = 38400AT
      Serial.println("Enter AT commands:");
    }
    
    void loop()
    {
      // Keep reading from HC-05 and send to Arduino Serial Monitor
      if (blue.available())
        Serial.write(blue.read());
    
      // Keep reading from Arduino Serial Monitor and send to HC-05
      if (Serial.available())
        blue.write(Serial.read());
    }

  2. #2
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    533
    You stated "The problem is that there is no response from the HC-05". Well, the first thing I would do is to measure whether pins EN and EN7 are actually set HIGH by the digitalWrite's when not having the SPI.end() command in. Then at least you know whether the HC-05 module gets power [or not] and/or whether it's enabled [or not].

    Regards,
    Paul

  3. #3
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    533
    Since you are soldering on the backside of the Teensy 4.0: you did not accidently short pin 32 [HC-05 enable] to one of the SPI pins 10, 11 or 12?

    Regards,
    Paul

  4. #4
    Junior Member
    Join Date
    Nov 2020
    Posts
    5
    Quote Originally Posted by PaulS View Post
    Since you are soldering on the backside of the Teensy 4.0: you did not accidently short pin 32 [HC-05 enable] to one of the SPI pins 10, 11 or 12?

    Regards,
    Paul
    Thank's Paul for you insight. The pins on the back were not shorted to the SPI pins and EN and EN7 were indeed doing exactly as expected. But I had deviated on the bread board layout from my circuit diagram and driven the RAMs from the switched power supply instead of from the Teensy 3.3V output. When the SPI was running there was a back coupling from the MOSI line through the (now unpowered) RAM and to the HC-05 power supply of about 1.85V - obviously enough to prevent the proper operation of the device. Fixing that short cut fixed the problem - short cuts lead to long voyages!
    Thanks again for your quick and incisive answer.
    Nigel

  5. #5
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    533
    Allright. Glad you got it to work.

    Regards,
    Paul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •