nigel.epsom
Member
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
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());
}