Skip to content
\n

This main code works on an Arduino Pro Mini, but I was porting it to an STM32:

\n
#include <lmic.h>\n#include <hal/hal.h>\n#include <SPI.h>\n\n//\n// For normal use, we require that you edit the sketch to replace FILLMEIN\n// with values assigned by the TTN console. However, for regression tests,\n// we want to be able to compile these scripts. The regression tests define\n// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-\n// working but innocuous value.\n//\n#ifdef COMPILE_REGRESSION_TEST\n# define FILLMEIN 0\n#else\n# warning \"You must replace the values marked FILLMEIN with real values from the TTN control panel!\"\n# define FILLMEIN //(#dont edit this, edit the lines that use FILLMEIN)\n#endif\n\n// This EUI must be in little-endian format, so least-significant-byte\n// first. When copying an EUI from ttnctl output, this means to reverse\n// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,\n// 0x70.\nstatic const u1_t PROGMEM APPEUI[8]={ 0x1B, 0x7A, 0xF3, 0x55, 0xB8, 0x78, 0xAC, 0x54 };\nvoid os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}\n\nstatic const u1_t PROGMEM DEVEUI[8]={ 0x99, 0x02, 0x09, 0x06, 0x04, 0x02, 0x02, 0xCC };\nvoid os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}\n\nstatic const u1_t PROGMEM APPKEY[16]={ 0x87, 0xAA, 0xAA, 0x76, 0x13, 0xD4, 0xDC, 0x1A, 0x2B, 0x74, 0xCF, 0x5A, 0x16, 0xEE, 0x11, 0x52 };\nvoid os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}\n\nstatic uint8_t mydata[] = \"{\\\"temperature\\\": 22}\";\nstatic osjob_t sendjob;\n\n// Schedule TX every this many seconds (might become longer due to duty\n// cycle limitations).\nconst unsigned TX_INTERVAL = 10;\n\n// Pin mapping\nconst lmic_pinmap lmic_pins = {\n    .nss = PA5,       // Chip select pin (NSS for SPI1)\n    .rxtx = LMIC_UNUSED_PIN,  // Not used\n    .rst = PB5,       // Reset pin\n    .dio = {PB8, PB6, PB7},  // DIO0, DIO1, DIO2 pins\n    // optional: set polarity of rxtx pin.\n    .rxtx_rx_active = 0,\n    // optional: set RSSI cal for listen-before-talk\n    // this value is in dB, and is added to RSSI\n    // measured prior to decision.\n    // Must include noise guardband! Ignored in US,\n    // EU, IN, other markets where LBT is not required.\n    .rssi_cal = 0,\n    // optional: override LMIC_SPI_FREQ if non-zero\n    .spi_freq = 0,\n};\n\nvoid printHex2(unsigned v) {\n    v &= 0xff;\n    if (v < 16)\n        Serial.print('0');\n    Serial.print(v, HEX);\n}\n\nvoid onEvent (ev_t ev) {\n    Serial.print(os_getTime());\n    Serial.print(\": \");\n    switch(ev) {\n        case EV_SCAN_TIMEOUT:\n            Serial.println(F(\"EV_SCAN_TIMEOUT\"));\n            break;\n        case EV_BEACON_FOUND:\n            Serial.println(F(\"EV_BEACON_FOUND\"));\n            break;\n        case EV_BEACON_MISSED:\n            Serial.println(F(\"EV_BEACON_MISSED\"));\n            break;\n        case EV_BEACON_TRACKED:\n            Serial.println(F(\"EV_BEACON_TRACKED\"));\n            break;\n        case EV_JOINING:\n            Serial.println(F(\"EV_JOINING\"));\n            break;\n        case EV_JOINED:\n            Serial.println(F(\"EV_JOINED\"));\n            {\n              u4_t netid = 0;\n              devaddr_t devaddr = 0;\n              u1_t nwkKey[16];\n              u1_t artKey[16];\n              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);\n              Serial.print(\"netid: \");\n              Serial.println(netid, DEC);\n              Serial.print(\"devaddr: \");\n              Serial.println(devaddr, HEX);\n              Serial.print(\"AppSKey: \");\n              for (size_t i=0; i<sizeof(artKey); ++i) {\n                if (i != 0)\n                  Serial.print(\"-\");\n                printHex2(artKey[i]);\n              }\n              Serial.println(\"\");\n              Serial.print(\"NwkSKey: \");\n              for (size_t i=0; i<sizeof(nwkKey); ++i) {\n                      if (i != 0)\n                              Serial.print(\"-\");\n                      printHex2(nwkKey[i]);\n              }\n              Serial.println();\n            }\n            // Disable link check validation (automatically enabled\n            // during join, but because slow data rates change max TX\n\t    // size, we don't use it in this example.\n            LMIC_setLinkCheckMode(0);\n\n           \n          \n            break;\n        /*\n        || This event is defined but not used in the code. No\n        || point in wasting codespace on it.\n        ||\n        || case EV_RFU1:\n        ||     Serial.println(F(\"EV_RFU1\"));\n        ||     break;\n        */\n        case EV_JOIN_FAILED:\n            Serial.println(F(\"EV_JOIN_FAILED\"));\n            break;\n        case EV_REJOIN_FAILED:\n            Serial.println(F(\"EV_REJOIN_FAILED\"));\n            break;\n        case EV_TXCOMPLETE:\n            Serial.println(F(\"EV_TXCOMPLETE (includes waiting for RX windows)\"));\n            if (LMIC.txrxFlags & TXRX_ACK)\n              Serial.println(F(\"Received ack\"));\n            if (LMIC.dataLen) {\n              Serial.print(F(\"Received \"));\n              Serial.print(LMIC.dataLen);\n              Serial.println(F(\" bytes of payload\"));\n            }\n            // Schedule next transmission\n            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);\n            break;\n        case EV_LOST_TSYNC:\n            Serial.println(F(\"EV_LOST_TSYNC\"));\n            break;\n        case EV_RESET:\n            Serial.println(F(\"EV_RESET\"));\n            break;\n        case EV_RXCOMPLETE:\n            // data received in ping slot\n            Serial.println(F(\"EV_RXCOMPLETE\"));\n            break;\n        case EV_LINK_DEAD:\n            Serial.println(F(\"EV_LINK_DEAD\"));\n            break;\n        case EV_LINK_ALIVE:\n            Serial.println(F(\"EV_LINK_ALIVE\"));\n            break;\n        /*\n        || This event is defined but not used in the code. No\n        || point in wasting codespace on it.\n        ||\n        || case EV_SCAN_FOUND:\n        ||    Serial.println(F(\"EV_SCAN_FOUND\"));\n        ||    break;\n        */\n        case EV_TXSTART:\n            Serial.println(F(\"EV_TXSTART\"));\n            break;\n        case EV_TXCANCELED:\n            Serial.println(F(\"EV_TXCANCELED\"));\n            break;\n        case EV_RXSTART:\n            /* do not print anything -- it wrecks timing */\n            break;\n        case EV_JOIN_TXCOMPLETE:\n            Serial.println(F(\"EV_JOIN_TXCOMPLETE: no JoinAccept\"));\n            break;\n\n        default:\n            Serial.print(F(\"Unknown event: \"));\n            Serial.println((unsigned) ev);\n            break;\n    }\n}\n\nvoid do_send(osjob_t* j){\n    // Check if there is not a current TX/RX job running\n    if (LMIC.opmode & OP_TXRXPEND) {\n        Serial.println(F(\"OP_TXRXPEND, not sending\"));\n    } else {\n        // Prepare upstream data transmission at the next possible time.\n        LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);\n        Serial.println(F(\"Packet queued\"));\n    }\n    // Next TX is scheduled after TX_COMPLETE event.\n}\n\nvoid setup() {\n    Serial.begin(9600);\n    Serial.println(F(\"Starting\"));\n\n    #ifdef VCC_ENABLE\n    // For Pinoccio Scout boards\n    pinMode(VCC_ENABLE, OUTPUT);\n    digitalWrite(VCC_ENABLE, HIGH);\n    delay(1000);\n    #endif\n\n    // LMIC init\n    os_init();\n    // Reset the MAC state. Session and pending data transfers will be discarded.\n    LMIC_reset();\n    //SetclockError added to fix joining timing issue \n    LMIC_setClockError(MAX_CLOCK_ERROR * 1 / 100); \n\n    // Start job (sending automatically starts OTAA too)\n    do_send(&sendjob);\n   // Data rate can be defined here.if not defined a rate is assigned\n    //LMIC_setDrTxpow (DR_SF9, 14);\n}\n\nvoid loop() {\n    os_runloop_once();\n}
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hi,

\n

default SPI pins used for the SPI instance of the Nucleo WL55JC1 are:
\n

\n \n
\n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n
#define PA7 11
#define PA6 12
#define PA5 13
\n
\n
\n

\n

If you want uses different pins you can change them:

\n","upvoteCount":1,"url":"https://github.com/orgs/stm32duino/discussions/2675#discussioncomment-12447311"}}}

Porting LMIC Library to STM32 (Nucleo-WL55JC1) - SPI Pin Issue #2675

Closed Answered by fpistm
SeppeBudenaers asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,

default SPI pins used for the SPI instance of the Nucleo WL55JC1 are:

If you want uses different pins you can change them:

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@SeppeBudenaers
Comment options

Answer selected by SeppeBudenaers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants