nopnop2002 / Arduino-LoRa-Ra01S

An Arduino Library for LoRa Communication using SX1262/1268
MIT License
33 stars 11 forks source link

add delay suggestion in WriteCommand() #9

Closed garudaonekh closed 1 year ago

garudaonekh commented 1 year ago

Hi,

With Atmega16, If debugPrint is false, I need to add a delay(10), otherwise sending will be successful but the other side will not receive it.

void SX126x::WriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy) {
  // ensure BUSY is low (state meachine ready)
  WaitForIdle();

  // start transfer
  digitalWrite(SX126x_SPI_SELECT, LOW);
  SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

  // send command byte
  if(debugPrint) {
    Serial.print("WriteCommand:  CMD=0x");
    Serial.print(cmd, HEX);
    Serial.print(" ");
    Serial.print(" DataOut: ");
  }
**delay(10)**
  SPI.transfer(cmd);
nopnop2002 commented 1 year ago

do you know why?

garudaonekh commented 1 year ago

I guess it needs some gap between SPI command. That's why when you set debugPrint to true, it needs to spend sometimes to serial.print so it works fine. I look at RadioLib code, there're mostly delay(1) between command.

nopnop2002 commented 1 year ago

Atmega328 works without Delay. It seems to be an issue only for Atmega16.

garudaonekh commented 1 year ago

Have you confirmed with the receiver side? On my Atmega16(debugPrint=false), it's sent successfully but receiver doesn't receive the data.

nopnop2002 commented 1 year ago

Atmega328 can send and receive correctly without delay. If you have an ATMEGA328, try it.

And so far, no such report has been received from anyone.

WriteCommand function is the function that is also used for sending.

garudaonekh commented 1 year ago

I use Atmega16 at one side and ESP8266 on the other end. Ok, I will update further if I have more info on this issue.