ElectronicCats / BastWAN

BastWAN is all the best in the world format Feather and LoRa with a RAK4260 and LoRaWAN
Other
31 stars 10 forks source link

LoRaWAN and pinouts #7

Closed Jakub-Nagy closed 3 years ago

Jakub-Nagy commented 3 years ago

Hello there!

I'm also trying to resolve this issue on the TTN forum but here I'm just looking at the BastWAN core aspect.

I recently bought this SAM R34 evaluation board from Tindie with hopes to get to know the processor before doing a custom HW implementation.

After experimentation with ASF and Mbed OS, I was happy I found this Arduino core for the RAK4260 (so also for SAM R34). I managed to burn the UF2 bootloader and upload and test simple Arduino sketches. I managed to get a direct LoRa link working using the Arduino LoRa library. This worked well.

I ran into problems when trying to use LoRaWAN though. I tried using a modified TinyLoRa version, the Beelan-LoRaWAN library with the example from this repo and also the Arduino LMIC library.

When using the TinyLoRa test sketch, the serial output (with memory register debug printouts) looks exactly the same as it does with a working Arduino + SX1276 circuit. But I'm definitely in range of the gateway and I have correct keys. I tried both OTAA and ABP.

When using the Beelan example found on this repo, the printout also acted as if the transmission was happening normally. When I turned on memory register debug printouts though, I found out that the communication with then chip happened only during initialization and there was no communication when transmitting. Again, I didn't receive anything on the TTN console neither with OTAA or ABP.

When I uploaded the LMIC test sketch (with correct pinouts and everything), the processor just crashed and wouldn't communicate. I needed to reburn the bootloader.

I also need to ask about the pinouts. I found out that direct LoRa transmissions only work if the RFM_SWITCH is set to high. Apparently the status of RFM_RFSW_ON and RFM_TCX_ON doesn't affect this at all. I can not find the RX/TX pin in the pin map though. What is the system in this pin mapping? I couldn't find any correlation between the BastWAN pin map and the RAK4260 pinout or even the SAM R34 pinout. Not one pin number seems to match. Does anyone know how the pin mapping is made?

If anyone can advise me about any of this I would really appreciate that. I would like to use this core but it's very hard at the moment. Thanks!

sabas1080 commented 3 years ago

Hi @Jakub-Nagy

BastWAN and Penguino Feather SAMR34 are not the same in pinout and schematic, that causes the arduino variant maybe not able to work.

our support is focused on Beelan library, please use this branch this may fix your problem i am almost sure and test if work, RFM_RFSW_ON and RFM_TCX_ON are configured in our arduino core and the Beelan library

Jakub-Nagy commented 3 years ago

BastWAN and Penguino Feather SAMR34 are not the same in pinout and schematic, that causes the arduino variant maybe not able to work.

Tried this but unfortunately didn't help me. Luckily I was able to find this BastWAN pinout and compare it with this Penguino pinout. When I compared them, that the RFM_SWITCH was the same in both of them, but the RFM_RFSW_ON was different (it was pin 17 on the Penguino). Thanks to this I was able to make LoRaWAN uplink work at least with TinyLoRa. This means that the hardware works.

Though in the future I would rather use Beelan since it also supports downlinks and has some other features. When using the send-class-A-ABP.ino example (with the same pinout as with the functioning TinyLoRa sketch), I get this output:

22:29:24.793 -> Sending: Counter-0 22:29:24.793 -> SPI Write ADDR: 1 DATA: 81 22:29:24.793 -> SPI Write ADDR: 1E DATA: C4 22:29:24.793 -> SPI Write ADDR: 1D DATA: 72 22:29:24.793 -> SPI Write ADDR: 26 DATA: 4 22:29:24.793 -> SPI Write ADDR: 6 DATA: D8 22:29:24.793 -> SPI Write ADDR: 7 DATA: EC 22:29:24.793 -> SPI Write ADDR: 8 DATA: F1 22:29:24.793 -> SPI Write ADDR: 40 DATA: 40 22:29:24.793 -> SPI Write ADDR: 33 DATA: 27 22:29:24.793 -> SPI Write ADDR: 3B DATA: 1D 22:29:24.793 -> SPI Write ADDR: 22 DATA: 16 22:29:24.793 -> SPI Read ADDR: E DATA: 80 22:29:24.793 -> SPI Write ADDR: D DATA: 80 22:29:24.828 -> SPI Write ADDR: 0 DATA: 40 22:29:24.828 -> SPI Write ADDR: 0 DATA: F1 22:29:24.828 -> SPI Write ADDR: 0 DATA: 3F 22:29:24.828 -> SPI Write ADDR: 0 DATA: 1 22:29:24.828 -> SPI Write ADDR: 0 DATA: 26 22:29:24.828 -> SPI Write ADDR: 0 DATA: 0 22:29:24.828 -> SPI Write ADDR: 0 DATA: 0 22:29:24.828 -> SPI Write ADDR: 0 DATA: 0 22:29:24.828 -> SPI Write ADDR: 0 DATA: 1 22:29:24.828 -> SPI Write ADDR: 0 DATA: D0 22:29:24.828 -> SPI Write ADDR: 0 DATA: 9F 22:29:24.828 -> SPI Write ADDR: 0 DATA: FE 22:29:24.828 -> SPI Write ADDR: 0 DATA: 78 22:29:24.828 -> SPI Write ADDR: 0 DATA: D4 22:29:24.828 -> SPI Write ADDR: 0 DATA: 9B 22:29:24.828 -> SPI Write ADDR: 0 DATA: 3F 22:29:24.828 -> SPI Write ADDR: 0 DATA: 53 22:29:24.828 -> SPI Write ADDR: 0 DATA: 48 22:29:24.828 -> SPI Write ADDR: 0 DATA: 86 22:29:24.828 -> SPI Write ADDR: 0 DATA: 61 22:29:24.828 -> SPI Write ADDR: 0 DATA: 83 22:29:24.828 -> SPI Write ADDR: 0 DATA: 87 22:29:24.828 -> SPI Write ADDR: 1 DATA: 83 22:29:26.146 -> SPI Write ADDR: 12 DATA: 8 22:29:27.144 -> SPI Write ADDR: 40 DATA: 0 22:29:27.144 -> SPI Write ADDR: 33 DATA: 67 22:29:27.144 -> SPI Write ADDR: 3B DATA: 19 22:29:27.144 -> SPI Write ADDR: 6 DATA: D8 22:29:27.144 -> SPI Write ADDR: 7 DATA: EC 22:29:27.144 -> SPI Write ADDR: 8 DATA: F1 22:29:27.144 -> SPI Write ADDR: 1 DATA: 86 22:29:28.356 -> SPI Write ADDR: 12 DATA: E0 22:29:28.356 -> SPI Write ADDR: 40 DATA: 0 22:29:28.356 -> SPI Write ADDR: 33 DATA: 67 22:29:28.356 -> SPI Write ADDR: 3B DATA: 19 22:29:28.356 -> SPI Write ADDR: 6 DATA: D9 22:29:28.356 -> SPI Write ADDR: 7 DATA: 61 22:29:28.356 -> SPI Write ADDR: 8 DATA: BE 22:29:28.356 -> SPI Write ADDR: 1 DATA: 86 22:29:29.573 -> SPI Write ADDR: 12 DATA: E0

The printouts act as if it was transmitting normally but I don't receive anything.

I was also looking into the Config.h file inside the Beelan library. I found the following: `// #define AS_923

define EU_868

//#define US_915 1 //#define AU_915 1`

Why don't the first two regions have a 1 while the second ones do? I would understand if 1 means enabled and without 1 it's disabled. But some with 1 are commented out by default. Why is this different?

Even if I don't get LoRaWAN working with Beelan, I can at least make it work with TinyLoRa. I have a checklist with different features I need to test on this processor before it can be implemented in new hardware. The last items remaining are: ADC, Writing into flash during runtime and software sleep/standby. But I doubt there will be issues with the first two.

I was trying out the examples from the ArduinoLowPower library. They won't even compile. I get many different compilation errors like these:

C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:8:8: error: 'struct Gclk' has no member named 'CLKCTRL' GCLK->CLKCTRL.bit.CLKEN = 0; //disable GCLK module ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:9:15: error: 'struct Gclk' has no member named 'STATUS' while (GCLK->STATUS.bit.SYNCBUSY); ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:11:8: error: 'struct Gclk' has no member named 'CLKCTRL' GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK6 | GCLK_CLKCTRL_ID( GCM_EIC )) ; //EIC clock switched on GCLK6 ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:11:34: error: 'GCLK_CLKCTRL_CLKEN' was not declared in this scope GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK6 | GCLK_CLKCTRL_ID( GCM_EIC )) ; //EIC clock switched on GCLK6 ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:11:55: error: 'GCLK_CLKCTRL_GEN_GCLK6' was not declared in this scope GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK6 | GCLK_CLKCTRL_ID( GCM_EIC )) ; //EIC clock switched on GCLK6 ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:11:105: error: 'GCLK_CLKCTRL_ID' was not declared in this scope GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK6 | GCLK_CLKCTRL_ID( GCM_EIC )) ; //EIC clock switched on GCLK6 ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:12:15: error: 'struct Gclk' has no member named 'STATUS' while (GCLK->STATUS.bit.SYNCBUSY); ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:14:16: error: request for member 'reg' in '1073747968u->Gclk::GENCTRL', which is of non-class type 'volatile GCLK_GENCTRL_Type [9]' GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(6)); //source for GCLK6 is OSCULP32K ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:14:90: error: 'GCLK_GENCTRL_ID' was not declared in this scope GCLK->GENCTRL.reg = (GCLK_GENCTRL_GENEN | GCLK_GENCTRL_SRC_OSCULP32K | GCLK_GENCTRL_ID(6)); //source for GCLK6 is OSCULP32K ^ C:\Users\nagyk\Documents\Arduino\libraries\ArduinoLowPower-master\src\samd\ArduinoLowPower.cpp:15:15: error: 'struct Gclk' has no member named 'STATUS' while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY);

...There is much more of these but are very similar. Do you know what might be the source of this?

But I also read in the issue "Sleep modes with the Arduino IDE #2" that currently even with the sleep mode enabled the minimum current is 2mA. In the application I'm developing it's crucial to have 500uA and below. Is there any roadmap for the implementation of the other sleep modes? Is it planned at all? Thank you very much.

sabas1080 commented 3 years ago

Tried this but unfortunately didn't help me. Luckily I was able to find this BastWAN pinout and compare it with this Penguino pinout. When I compared them, that the RFM_SWITCH was the same in both of them, but the RFM_RFSW_ON was different (it was pin 17 on the Penguino). Thanks to this I was able to make LoRaWAN uplink work at least with TinyLoRa. This means that the hardware works.

excellent that your board now works.

We define pinout for LoRA Radio with macros in Arduino IDE and Beelan library use that macros in the code, we must correct that, but for test use this version

I was also looking into the Config.h file inside the Beelan library. I found the following: // #define AS_923 #define EU_868 //#define US_915 1 //#define AU_915 1

Why don't the first two regions have a 1 while the second ones do? I would understand if 1 means enabled and without 1 it's disabled. But some with 1 are commented out by default. Why is this different?

I will send pullrequest for fix this

I was trying out the examples from the ArduinoLowPower library. They won't even compile. I get many different compilation errors like these:

For SAMR34 and our ArduinoCore use our version of the library

RTCZero https://github.com/ElectronicCats/RTCZero ArduinoLowPower https://github.com/ElectronicCats/ArduinoLowPower

But I also read in the issue "Sleep modes with the Arduino IDE #2" that currently even with the sleep mode enabled the minimum current is 2mA. In the application I'm developing it's crucial to have 500uA and below. Is there any roadmap for the implementation of the other sleep modes? Is it planned at all? Thank you very much.

Yes, we have ported the arduino version and it is the maximum we have obtained, if you want to contribute to improving performance, welcome and we can discuss in #2

Jakub-Nagy commented 3 years ago

use this version

I did use this version the first time. Doesn't matter now.

I will send pullrequest for fix this

Great. Maybe I just wasn't enabling my region properly.

I'm going to close this issue and reply to the sleep stuff in #2.