Program that uses the QuickStart Library to interface a SmartMesh IP mote: Connects to the default network and starts publishing a random walk value every 5 seconds.

Dependencies:   mbed millis

Fork of QSL_SimplePublish by Jon-Håkon Bøe Røli

QSL SimplePublish

SmartMesh IP QuickStart Library

Committer:
jhbr
Date:
Fri Nov 04 14:19:34 2016 +0000
Revision:
9:f723949a18b7
Parent:
0:d3f5fdf2e6da
Deactivated DEBUG prints and updated mbed library to v128

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhbr 0:d3f5fdf2e6da 1 /*
jhbr 0:d3f5fdf2e6da 2 Copyright (c) 2016, Dust Networks. All rights reserved.
jhbr 0:d3f5fdf2e6da 3
jhbr 0:d3f5fdf2e6da 4 Port of the uart module to the NUCLEO-L053R8.
jhbr 0:d3f5fdf2e6da 5
jhbr 0:d3f5fdf2e6da 6 \license See attached DN_LICENSE.txt.
jhbr 0:d3f5fdf2e6da 7 */
jhbr 0:d3f5fdf2e6da 8
jhbr 0:d3f5fdf2e6da 9 #include "dn_uart.h"
jhbr 0:d3f5fdf2e6da 10 #include "dn_ipmt.h"
jhbr 0:d3f5fdf2e6da 11 #include "dn_debug.h"
jhbr 0:d3f5fdf2e6da 12 #include "mbed.h"
jhbr 0:d3f5fdf2e6da 13
jhbr 0:d3f5fdf2e6da 14
jhbr 0:d3f5fdf2e6da 15 //=========================== defines =========================================
jhbr 0:d3f5fdf2e6da 16
jhbr 0:d3f5fdf2e6da 17 // Set correct pins for external UART on your board (USART1 for NUCLEO-L053R8)
jhbr 0:d3f5fdf2e6da 18 #define UART_MOTE_TX PA_9
jhbr 0:d3f5fdf2e6da 19 #define UART_MOTE_RX PA_10
jhbr 0:d3f5fdf2e6da 20
jhbr 0:d3f5fdf2e6da 21
jhbr 0:d3f5fdf2e6da 22 //=========================== variables =======================================
jhbr 0:d3f5fdf2e6da 23
jhbr 0:d3f5fdf2e6da 24 typedef struct {
jhbr 0:d3f5fdf2e6da 25 dn_uart_rxByte_cbt ipmt_uart_rxByte_cb;
jhbr 0:d3f5fdf2e6da 26 } dn_uart_vars_t;
jhbr 0:d3f5fdf2e6da 27
jhbr 0:d3f5fdf2e6da 28 static dn_uart_vars_t dn_uart_vars;
jhbr 0:d3f5fdf2e6da 29 static Serial serialMote(UART_MOTE_TX, UART_MOTE_RX);
jhbr 0:d3f5fdf2e6da 30
jhbr 0:d3f5fdf2e6da 31
jhbr 0:d3f5fdf2e6da 32 //=========================== prototypes ======================================
jhbr 0:d3f5fdf2e6da 33
jhbr 0:d3f5fdf2e6da 34 void moteRXinterrupt(void);
jhbr 0:d3f5fdf2e6da 35
jhbr 0:d3f5fdf2e6da 36 //=========================== public ==========================================
jhbr 0:d3f5fdf2e6da 37
jhbr 0:d3f5fdf2e6da 38 void dn_uart_init(dn_uart_rxByte_cbt rxByte_cb)
jhbr 0:d3f5fdf2e6da 39 {
jhbr 0:d3f5fdf2e6da 40 // Store RX callback function
jhbr 0:d3f5fdf2e6da 41 dn_uart_vars.ipmt_uart_rxByte_cb = rxByte_cb;
jhbr 0:d3f5fdf2e6da 42
jhbr 0:d3f5fdf2e6da 43 /* Default configuration for Serial:
jhbr 0:d3f5fdf2e6da 44 - 8 bit character size
jhbr 0:d3f5fdf2e6da 45 - No Parity
jhbr 0:d3f5fdf2e6da 46 - 1 bit stop bit
jhbr 0:d3f5fdf2e6da 47 - No flow control
jhbr 0:d3f5fdf2e6da 48 - 9600 baudrate
jhbr 0:d3f5fdf2e6da 49 Hence, we only need to change the baudrate */
jhbr 0:d3f5fdf2e6da 50 serialMote.baud(115200);
jhbr 0:d3f5fdf2e6da 51
jhbr 0:d3f5fdf2e6da 52 // Attach RX interrupt handler
jhbr 0:d3f5fdf2e6da 53 serialMote.attach(&moteRXinterrupt, Serial::RxIrq);
jhbr 0:d3f5fdf2e6da 54
jhbr 0:d3f5fdf2e6da 55 debug("SMIP Serial Initialized");
jhbr 0:d3f5fdf2e6da 56 }
jhbr 0:d3f5fdf2e6da 57
jhbr 0:d3f5fdf2e6da 58 void dn_uart_txByte(uint8_t byte)
jhbr 0:d3f5fdf2e6da 59 {
jhbr 0:d3f5fdf2e6da 60 serialMote.putc(byte);
jhbr 0:d3f5fdf2e6da 61 }
jhbr 0:d3f5fdf2e6da 62
jhbr 0:d3f5fdf2e6da 63 void dn_uart_txFlush()
jhbr 0:d3f5fdf2e6da 64 {
jhbr 0:d3f5fdf2e6da 65 // Nothing to do since we push byte-by-byte
jhbr 0:d3f5fdf2e6da 66 }
jhbr 0:d3f5fdf2e6da 67
jhbr 0:d3f5fdf2e6da 68 //=========================== private =========================================
jhbr 0:d3f5fdf2e6da 69
jhbr 0:d3f5fdf2e6da 70 //=========================== helpers =========================================
jhbr 0:d3f5fdf2e6da 71
jhbr 0:d3f5fdf2e6da 72 //=========================== interrupt handlers ==============================
jhbr 0:d3f5fdf2e6da 73
jhbr 0:d3f5fdf2e6da 74 void moteRXinterrupt(void)
jhbr 0:d3f5fdf2e6da 75 {
jhbr 0:d3f5fdf2e6da 76 while (serialMote.readable())
jhbr 0:d3f5fdf2e6da 77 {
jhbr 0:d3f5fdf2e6da 78 dn_uart_vars.ipmt_uart_rxByte_cb(serialMote.getc());
jhbr 0:d3f5fdf2e6da 79 }
jhbr 0:d3f5fdf2e6da 80 }
jhbr 0:d3f5fdf2e6da 81