HelloWorld_IDS01A4 mbed application for Spirit1 P2P demo.
Dependencies: mbed
Fork of HelloWorld_IDS01A5_Program by
mbed 2.0 (a.k.a classic) HelloWorld example for Spirit1 to transfer data from one node to another.
To send the predefined data packet from the sender to the receiver, user needs to press User Button on the board. The LED on the receiver expansion board will toggle on reception of data successfully.
Data packets sent and received can be seen on USB serial terminal.
EVALUATION BOARDS RF FREQUENCY DESCRIPTION :
X-NUCLEO-IDS01A4 868 MHz 868 MHz RF expansion board based on SPIRIT1
main.cpp@3:29bbb772ee62, 2017-06-19 (annotated)
- Committer:
- rosarium
- Date:
- Mon Jun 19 08:52:28 2017 +0000
- Revision:
- 3:29bbb772ee62
- Parent:
- 2:a0677b17a570
- Child:
- 4:cae1fa054b86
main.cpp updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rosarium | 0:2ddc0583bcec | 1 | /** |
rosarium | 0:2ddc0583bcec | 2 | ****************************************************************************** |
rosarium | 0:2ddc0583bcec | 3 | * @file main.cpp |
rosarium | 0:2ddc0583bcec | 4 | * @author Rosarium PILA, STMicroelectronics |
rosarium | 0:2ddc0583bcec | 5 | * @version V1.0.0 |
rosarium | 3:29bbb772ee62 | 6 | * @date June 19th, 2017 |
rosarium | 1:cf2e2f85bf8d | 7 | * @brief mbed Hello World test application for the STMicroelectronics X-NUCLEO-IDB01A4/5 |
rosarium | 0:2ddc0583bcec | 8 | * Spirit1 Expansion Board |
rosarium | 0:2ddc0583bcec | 9 | ****************************************************************************** |
rosarium | 0:2ddc0583bcec | 10 | * @attention |
rosarium | 0:2ddc0583bcec | 11 | * |
rosarium | 0:2ddc0583bcec | 12 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
rosarium | 0:2ddc0583bcec | 13 | * |
rosarium | 0:2ddc0583bcec | 14 | * Redistribution and use in source and binary forms, with or without modification, |
rosarium | 0:2ddc0583bcec | 15 | * are permitted provided that the following conditions are met: |
rosarium | 0:2ddc0583bcec | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
rosarium | 0:2ddc0583bcec | 17 | * this list of conditions and the following disclaimer. |
rosarium | 0:2ddc0583bcec | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
rosarium | 0:2ddc0583bcec | 19 | * this list of conditions and the following disclaimer in the documentation |
rosarium | 0:2ddc0583bcec | 20 | * and/or other materials provided with the distribution. |
rosarium | 0:2ddc0583bcec | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
rosarium | 0:2ddc0583bcec | 22 | * may be used to endorse or promote products derived from this software |
rosarium | 0:2ddc0583bcec | 23 | * without specific prior written permission. |
rosarium | 0:2ddc0583bcec | 24 | * |
rosarium | 0:2ddc0583bcec | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
rosarium | 0:2ddc0583bcec | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
rosarium | 0:2ddc0583bcec | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
rosarium | 0:2ddc0583bcec | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
rosarium | 0:2ddc0583bcec | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
rosarium | 0:2ddc0583bcec | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
rosarium | 0:2ddc0583bcec | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
rosarium | 0:2ddc0583bcec | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
rosarium | 0:2ddc0583bcec | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
rosarium | 0:2ddc0583bcec | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
rosarium | 0:2ddc0583bcec | 35 | * |
rosarium | 0:2ddc0583bcec | 36 | ****************************************************************************** |
rosarium | 0:2ddc0583bcec | 37 | */ |
rosarium | 0:2ddc0583bcec | 38 | |
rosarium | 0:2ddc0583bcec | 39 | #include "mbed.h" |
rosarium | 0:2ddc0583bcec | 40 | #include "SimpleSpirit1.h" |
rosarium | 0:2ddc0583bcec | 41 | |
rosarium | 1:cf2e2f85bf8d | 42 | #define TEST_STR_LEN (32) |
rosarium | 0:2ddc0583bcec | 43 | static uint8_t send_buf[TEST_STR_LEN] ={'S','P','I','R','I','T','1',' ','H','E','L','L','O',' ','W','O','R','L','D',' ','P','2','P',' ','D','E','M','O'}; |
rosarium | 0:2ddc0583bcec | 44 | static uint8_t read_buf[TEST_STR_LEN] ={'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'}; |
rosarium | 1:cf2e2f85bf8d | 45 | |
rosarium | 1:cf2e2f85bf8d | 46 | static SimpleSpirit1 &myspirit = SimpleSpirit1::CreateInstance(D11, D12, D3, D9, D10, D2); //RPi: (SPI_CLK) = (D13:PA5:resistorR7 --> D3:PB3:resistorR4) |
rosarium | 0:2ddc0583bcec | 47 | |
rosarium | 1:cf2e2f85bf8d | 48 | volatile bool rx_done_flag = 0; |
rosarium | 1:cf2e2f85bf8d | 49 | volatile bool tx_done_flag = 0; |
rosarium | 0:2ddc0583bcec | 50 | |
rosarium | 0:2ddc0583bcec | 51 | static int curr_len = 0; |
rosarium | 0:2ddc0583bcec | 52 | unsigned char myValue = 0; |
rosarium | 0:2ddc0583bcec | 53 | |
rosarium | 1:cf2e2f85bf8d | 54 | InterruptIn event(USER_BUTTON); //RPi : //Added interrupt event to give userinterface to send pkt. |
rosarium | 0:2ddc0583bcec | 55 | |
rosarium | 1:cf2e2f85bf8d | 56 | /** |
rosarium | 1:cf2e2f85bf8d | 57 | * @brief callback_func |
rosarium | 1:cf2e2f85bf8d | 58 | * @param callback event |
rosarium | 1:cf2e2f85bf8d | 59 | * @retval None. |
rosarium | 1:cf2e2f85bf8d | 60 | */ |
rosarium | 0:2ddc0583bcec | 61 | static void callback_func(int event) |
rosarium | 0:2ddc0583bcec | 62 | { |
rosarium | 1:cf2e2f85bf8d | 63 | if(event == SimpleSpirit1::RX_DONE) |
rosarium | 1:cf2e2f85bf8d | 64 | { |
rosarium | 1:cf2e2f85bf8d | 65 | rx_done_flag = 1; |
rosarium | 1:cf2e2f85bf8d | 66 | } |
rosarium | 1:cf2e2f85bf8d | 67 | else if (event == SimpleSpirit1::TX_DONE) |
rosarium | 1:cf2e2f85bf8d | 68 | { |
rosarium | 1:cf2e2f85bf8d | 69 | tx_done_flag = 1; |
rosarium | 1:cf2e2f85bf8d | 70 | } |
rosarium | 0:2ddc0583bcec | 71 | } |
rosarium | 0:2ddc0583bcec | 72 | |
rosarium | 1:cf2e2f85bf8d | 73 | |
rosarium | 1:cf2e2f85bf8d | 74 | /** |
rosarium | 1:cf2e2f85bf8d | 75 | * @brief send_data |
rosarium | 1:cf2e2f85bf8d | 76 | * @param None |
rosarium | 1:cf2e2f85bf8d | 77 | * @retval None |
rosarium | 1:cf2e2f85bf8d | 78 | */ |
rosarium | 0:2ddc0583bcec | 79 | void send_data(void) |
rosarium | 1:cf2e2f85bf8d | 80 | { |
rosarium | 1:cf2e2f85bf8d | 81 | printf("\r\n***Sending a packet***\r\n"); |
rosarium | 0:2ddc0583bcec | 82 | |
rosarium | 0:2ddc0583bcec | 83 | while(myspirit.is_receiving()); // wait for ongoing RX ends |
rosarium | 1:cf2e2f85bf8d | 84 | |
rosarium | 0:2ddc0583bcec | 85 | curr_len = strlen((const char*)send_buf) + 1; |
rosarium | 0:2ddc0583bcec | 86 | myspirit.send(send_buf, curr_len); |
rosarium | 0:2ddc0583bcec | 87 | } |
rosarium | 1:cf2e2f85bf8d | 88 | /** |
rosarium | 1:cf2e2f85bf8d | 89 | * @brief main routine |
rosarium | 1:cf2e2f85bf8d | 90 | * @param None |
rosarium | 1:cf2e2f85bf8d | 91 | * @retval int |
rosarium | 1:cf2e2f85bf8d | 92 | */ |
rosarium | 0:2ddc0583bcec | 93 | int main() |
rosarium | 1:cf2e2f85bf8d | 94 | { |
rosarium | 2:a0677b17a570 | 95 | DigitalOut TestLED = D5; //RPi : LED of IDS01A4/5 |
rosarium | 2:a0677b17a570 | 96 | TestLED = 0; //RPi : LED off |
rosarium | 0:2ddc0583bcec | 97 | |
rosarium | 0:2ddc0583bcec | 98 | myspirit.attach_irq_callback(callback_func); |
rosarium | 0:2ddc0583bcec | 99 | |
rosarium | 0:2ddc0583bcec | 100 | myspirit.on(); |
rosarium | 0:2ddc0583bcec | 101 | |
rosarium | 0:2ddc0583bcec | 102 | printf("\n**************HelloWorld mbed demo for Spirit1 (X-NUCLEO-IDS01A4/5)**************\r\n"); |
rosarium | 0:2ddc0583bcec | 103 | printf("\nPress User Button on one of the two boards to send a packaet to the other and the LED D1 on the receiver X-NUCLEO-IDS01A4/5 should toggle \n\r\n"); |
rosarium | 0:2ddc0583bcec | 104 | |
rosarium | 1:cf2e2f85bf8d | 105 | event.rise(&send_data); //RPi: User button interrupt trigger to send data |
rosarium | 1:cf2e2f85bf8d | 106 | |
rosarium | 0:2ddc0583bcec | 107 | while(1) |
rosarium | 0:2ddc0583bcec | 108 | { |
rosarium | 1:cf2e2f85bf8d | 109 | __WFE(); // low power in idle condition., waiting for an event |
rosarium | 0:2ddc0583bcec | 110 | |
rosarium | 1:cf2e2f85bf8d | 111 | if(rx_done_flag) |
rosarium | 0:2ddc0583bcec | 112 | { |
rosarium | 1:cf2e2f85bf8d | 113 | rx_done_flag = 0; |
rosarium | 1:cf2e2f85bf8d | 114 | |
rosarium | 1:cf2e2f85bf8d | 115 | for(unsigned int flush_count = 0; flush_count < TEST_STR_LEN; flush_count++) read_buf[flush_count] = 0 ;//RPi:clear the read buffer |
rosarium | 0:2ddc0583bcec | 116 | |
rosarium | 0:2ddc0583bcec | 117 | int ret = myspirit.read(read_buf, sizeof(read_buf)); |
rosarium | 0:2ddc0583bcec | 118 | |
rosarium | 1:cf2e2f85bf8d | 119 | myValue = 1 - myValue; |
rosarium | 1:cf2e2f85bf8d | 120 | TestLED = myValue; //RPi: Toggle LED at the receiver |
rosarium | 0:2ddc0583bcec | 121 | |
rosarium | 0:2ddc0583bcec | 122 | if(ret == 0) { |
rosarium | 0:2ddc0583bcec | 123 | printf("\nNothing to read\n\r"); |
rosarium | 0:2ddc0583bcec | 124 | continue; |
rosarium | 0:2ddc0583bcec | 125 | } |
rosarium | 0:2ddc0583bcec | 126 | printf("\r\n***Received a packet***\r\n\rReceived string = '%s' (len=%d) \n\r", read_buf, ret); |
rosarium | 1:cf2e2f85bf8d | 127 | } |
rosarium | 1:cf2e2f85bf8d | 128 | |
rosarium | 1:cf2e2f85bf8d | 129 | else if (tx_done_flag) |
rosarium | 1:cf2e2f85bf8d | 130 | { |
rosarium | 1:cf2e2f85bf8d | 131 | tx_done_flag = 0; |
rosarium | 1:cf2e2f85bf8d | 132 | printf("\r\n***Packet sent***\r\nSent string ='%s' (len=%d)\n\r", send_buf, strlen((const char*)send_buf) + 1); |
rosarium | 1:cf2e2f85bf8d | 133 | } |
rosarium | 0:2ddc0583bcec | 134 | } |
rosarium | 0:2ddc0583bcec | 135 | |
rosarium | 0:2ddc0583bcec | 136 | myspirit.off(); |
rosarium | 0:2ddc0583bcec | 137 | |
rosarium | 0:2ddc0583bcec | 138 | return 0; |
rosarium | 0:2ddc0583bcec | 139 | } |
rosarium | 0:2ddc0583bcec | 140 | |
rosarium | 0:2ddc0583bcec | 141 | |
rosarium | 0:2ddc0583bcec | 142 |