Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpiPeripheral.ReadRegister always returns 0 #50

Open
KiwiBryn opened this issue Dec 26, 2019 · 1 comment
Open

SpiPeripheral.ReadRegister always returns 0 #50

KiwiBryn opened this issue Dec 26, 2019 · 1 comment

Comments

@KiwiBryn
Copy link

@KiwiBryn KiwiBryn commented Dec 26, 2019

Porting my LoRa radio stack to Meadow. The Semetech SX127X devices use SPI and I always get a return value of 0 when I call ReadRegister. (register 0x42 is the silicon version, expecting 0x12).

If I use SpiBus.ExchangeData or SpiPeripheral.WriteRead I can read the register successfully.

try
{
byte registerValue;

// Doesn't work Dec 2019 always returns 0
registerValue = sx127xDevice.ReadRegister(RegVersion);

// Using low level spi bus level approach works
var txBuffer = new byte[] { RegVersion, 0x0 };
var rxBuffer = new byte[] { 0x0, 0x0 };
Console.WriteLine("spiBus.ExchangeData...1");
spiBus.ExchangeData(spiPeriphChipSelect, ChipSelectMode.ActiveLow, txBuffer, rxBuffer);
Console.WriteLine("spiBus.ExchangeData...2");
registerValue = rxBuffer[1];

// Using this device level approach works,
byte[] txBuffer = new byte[] { RegVersion };
Console.WriteLine("spiBus.WriteRead...1");
byte[] rxBuffer = sx127xDevice.WriteRead(txBuffer, 2);
Console.WriteLine("spiBus.WriteRead...2");
registerValue = rxBuffer[1];

Console.WriteLine("Register 0x{0:x2} - Value 0X{1:x2} - Bits {2}", RegVersion, registerValue, Convert.ToString(registerValue, 2).PadLeft(8, '0'));
}
catch (Exception ex)
{
Console.WriteLine("ReadDeviceID " + ex.Message);
}

MeadowApp.zip

Thanks
@KiwiBryn

@adrianstevens

This comment has been minimized.

Copy link

@adrianstevens adrianstevens commented Jan 4, 2020

Thx again @KiwiBryn, I think I've hit the issue recently as well, I just haven't investigated fully yet.

@ctacke any thoughts? (and I'll take a closer look over the weekend)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.