Prototype RF driver for STM Sub-1 GHz RF expansion board based on the SPSGRF-868 module for STM32 Nucleo.

Prototype RF Driver for STM Sub-1 GHz RF Expansion Boards based on the SPSGRF-868 and SPSGRF-915 Modules for STM32 Nucleo

Currently supported boards:

Note, in order to use expansion board X-NUCLEO-IDS01A4 in mbed you need to perform the following HW modifications on the board:

  • Unmount resistor R4
  • Mount resistor R7

Furthermore, on some Nucleo development boards (e.g. the NUCLEO_F429ZI), in order to be able to use Ethernet together with these Sub-1 GHz RF expansion boards, you need to compile this driver with macro SPIRIT1_SPI_MOSI=PB_5 defined, while the development board typically requires some HW modification as e.g. described here!

This driver can be used together with the 6LoWPAN stack (a.k.a. Nanostack).

Committer:
Wolfgang Betz
Date:
Thu Jan 18 15:07:23 2018 +0100
Revision:
77:a9a9807bf3ed
Parent:
34:edda6a7238ec
Merge pull request #3 from SeppoTakalo/skip

Skip compilation if FEATURE_NANOSTACK is not enabled

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 34:edda6a7238ec 1 /**
Wolfgang Betz 34:edda6a7238ec 2 ******************************************************************************
Wolfgang Betz 34:edda6a7238ec 3 * @file radio_spi.c
Wolfgang Betz 34:edda6a7238ec 4 * @author System Lab - NOIDA
Wolfgang Betz 34:edda6a7238ec 5 * @version V1.0.0
Wolfgang Betz 34:edda6a7238ec 6 * @date 15-May-2014
Wolfgang Betz 34:edda6a7238ec 7 * @brief This file provides code for the configuration of the SPI instances.
Wolfgang Betz 34:edda6a7238ec 8 ******************************************************************************
Wolfgang Betz 34:edda6a7238ec 9 * @attention
Wolfgang Betz 34:edda6a7238ec 10 *
Wolfgang Betz 34:edda6a7238ec 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Wolfgang Betz 34:edda6a7238ec 12 *
Wolfgang Betz 34:edda6a7238ec 13 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 34:edda6a7238ec 14 * are permitted provided that the following conditions are met:
Wolfgang Betz 34:edda6a7238ec 15 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 34:edda6a7238ec 16 * this list of conditions and the following disclaimer.
Wolfgang Betz 34:edda6a7238ec 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 34:edda6a7238ec 18 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 34:edda6a7238ec 19 * and/or other materials provided with the distribution.
Wolfgang Betz 34:edda6a7238ec 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 34:edda6a7238ec 21 * may be used to endorse or promote products derived from this software
Wolfgang Betz 34:edda6a7238ec 22 * without specific prior written permission.
Wolfgang Betz 34:edda6a7238ec 23 *
Wolfgang Betz 34:edda6a7238ec 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 34:edda6a7238ec 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 34:edda6a7238ec 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 34:edda6a7238ec 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 34:edda6a7238ec 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 34:edda6a7238ec 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 34:edda6a7238ec 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 34:edda6a7238ec 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 34:edda6a7238ec 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 34:edda6a7238ec 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 34:edda6a7238ec 34 *
Wolfgang Betz 34:edda6a7238ec 35 ******************************************************************************
Wolfgang Betz 34:edda6a7238ec 36 */
Wolfgang Betz 34:edda6a7238ec 37
Wolfgang Betz 34:edda6a7238ec 38
Wolfgang Betz 34:edda6a7238ec 39 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 34:edda6a7238ec 40 #include "radio_spi.h"
Wolfgang Betz 34:edda6a7238ec 41
Wolfgang Betz 34:edda6a7238ec 42 #include "SimpleSpirit1.h"
Wolfgang Betz 34:edda6a7238ec 43
Wolfgang Betz 34:edda6a7238ec 44
Wolfgang Betz 34:edda6a7238ec 45 /**
Wolfgang Betz 34:edda6a7238ec 46 * @addtogroup BSP
Wolfgang Betz 34:edda6a7238ec 47 * @{
Wolfgang Betz 34:edda6a7238ec 48 */
Wolfgang Betz 34:edda6a7238ec 49
Wolfgang Betz 34:edda6a7238ec 50
Wolfgang Betz 34:edda6a7238ec 51 /**
Wolfgang Betz 34:edda6a7238ec 52 * @addtogroup X-NUCLEO-IDS02Ax
Wolfgang Betz 34:edda6a7238ec 53 * @{
Wolfgang Betz 34:edda6a7238ec 54 */
Wolfgang Betz 34:edda6a7238ec 55
Wolfgang Betz 34:edda6a7238ec 56
Wolfgang Betz 34:edda6a7238ec 57 /**
Wolfgang Betz 34:edda6a7238ec 58 * @defgroup RADIO_SPI_Private_TypesDefinitions RADIO_SPI Private Types Definitions
Wolfgang Betz 34:edda6a7238ec 59 * @{
Wolfgang Betz 34:edda6a7238ec 60 */
Wolfgang Betz 34:edda6a7238ec 61
Wolfgang Betz 34:edda6a7238ec 62 /**
Wolfgang Betz 34:edda6a7238ec 63 * @}
Wolfgang Betz 34:edda6a7238ec 64 */
Wolfgang Betz 34:edda6a7238ec 65
Wolfgang Betz 34:edda6a7238ec 66
Wolfgang Betz 34:edda6a7238ec 67 /**
Wolfgang Betz 34:edda6a7238ec 68 * @defgroup RADIO_SPI_Private_Defines RADIO_SPI Private Defines
Wolfgang Betz 34:edda6a7238ec 69 * @{
Wolfgang Betz 34:edda6a7238ec 70 */
Wolfgang Betz 34:edda6a7238ec 71
Wolfgang Betz 34:edda6a7238ec 72 /**
Wolfgang Betz 34:edda6a7238ec 73 * @}
Wolfgang Betz 34:edda6a7238ec 74 */
Wolfgang Betz 34:edda6a7238ec 75
Wolfgang Betz 34:edda6a7238ec 76
Wolfgang Betz 34:edda6a7238ec 77 /**
Wolfgang Betz 34:edda6a7238ec 78 * @defgroup RADIO_SPI_Private_Macros RADIO_SPI Private Macros
Wolfgang Betz 34:edda6a7238ec 79 * @{
Wolfgang Betz 34:edda6a7238ec 80 */
Wolfgang Betz 34:edda6a7238ec 81
Wolfgang Betz 34:edda6a7238ec 82 /**
Wolfgang Betz 34:edda6a7238ec 83 * @}
Wolfgang Betz 34:edda6a7238ec 84 */
Wolfgang Betz 34:edda6a7238ec 85
Wolfgang Betz 34:edda6a7238ec 86
Wolfgang Betz 34:edda6a7238ec 87 /**
Wolfgang Betz 34:edda6a7238ec 88 * @defgroup RADIO_SPI_Private_Variables RADIO_SPI Private Variables
Wolfgang Betz 34:edda6a7238ec 89 * @{
Wolfgang Betz 34:edda6a7238ec 90 */
Wolfgang Betz 34:edda6a7238ec 91
Wolfgang Betz 34:edda6a7238ec 92 /**
Wolfgang Betz 34:edda6a7238ec 93 * @}
Wolfgang Betz 34:edda6a7238ec 94 */
Wolfgang Betz 34:edda6a7238ec 95
Wolfgang Betz 34:edda6a7238ec 96
Wolfgang Betz 34:edda6a7238ec 97 /**
Wolfgang Betz 34:edda6a7238ec 98 * @defgroup RADIO_SPI_Private_FunctionPrototypes RADIO_SPI Private Function Prototypes
Wolfgang Betz 34:edda6a7238ec 99 * @{
Wolfgang Betz 34:edda6a7238ec 100 */
Wolfgang Betz 34:edda6a7238ec 101
Wolfgang Betz 34:edda6a7238ec 102 /**
Wolfgang Betz 34:edda6a7238ec 103 * @}
Wolfgang Betz 34:edda6a7238ec 104 */
Wolfgang Betz 34:edda6a7238ec 105
Wolfgang Betz 34:edda6a7238ec 106 /**
Wolfgang Betz 34:edda6a7238ec 107 * @defgroup RADIO_SPI_Private_Functions RADIO_SPI Private Functions
Wolfgang Betz 34:edda6a7238ec 108 * @{
Wolfgang Betz 34:edda6a7238ec 109 */
Wolfgang Betz 34:edda6a7238ec 110
Wolfgang Betz 34:edda6a7238ec 111 /**
Wolfgang Betz 34:edda6a7238ec 112 * @}
Wolfgang Betz 34:edda6a7238ec 113 */
Wolfgang Betz 34:edda6a7238ec 114
Wolfgang Betz 34:edda6a7238ec 115 /**
Wolfgang Betz 34:edda6a7238ec 116 * @brief Write single or multiple RF Transceivers register
Wolfgang Betz 34:edda6a7238ec 117 * @param cRegAddress: base register's address to be write
Wolfgang Betz 34:edda6a7238ec 118 * @param cNbBytes: number of registers and bytes to be write
Wolfgang Betz 34:edda6a7238ec 119 * @param pcBuffer: pointer to the buffer of values have to be written into registers
Wolfgang Betz 34:edda6a7238ec 120 * @retval StatusBytes
Wolfgang Betz 34:edda6a7238ec 121 */
Wolfgang Betz 34:edda6a7238ec 122 StatusBytes SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 123 {
Wolfgang Betz 34:edda6a7238ec 124 return SimpleSpirit1::Instance().SdkEvalSpiWriteRegisters(cRegAddress, cNbBytes, pcBuffer);
Wolfgang Betz 34:edda6a7238ec 125 }
Wolfgang Betz 34:edda6a7238ec 126
Wolfgang Betz 34:edda6a7238ec 127 StatusBytes SimpleSpirit1::SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 128 {
Wolfgang Betz 34:edda6a7238ec 129 uint8_t aHeader[2] = {0};
Wolfgang Betz 34:edda6a7238ec 130 uint16_t tmpstatus = 0x0000;
Wolfgang Betz 34:edda6a7238ec 131 StatusBytes *pStatus=(StatusBytes *)&tmpstatus;
Wolfgang Betz 34:edda6a7238ec 132
Wolfgang Betz 34:edda6a7238ec 133 /* Built the aHeader bytes */
Wolfgang Betz 34:edda6a7238ec 134 aHeader[0] = WRITE_HEADER;
Wolfgang Betz 34:edda6a7238ec 135 aHeader[1] = cRegAddress;
Wolfgang Betz 34:edda6a7238ec 136
Wolfgang Betz 34:edda6a7238ec 137 /* Puts the SPI chip select low to start the transaction */
Wolfgang Betz 34:edda6a7238ec 138 chip_sync_select();
Wolfgang Betz 34:edda6a7238ec 139
Wolfgang Betz 34:edda6a7238ec 140 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 141 tmpstatus = _spi.write(aHeader[0]);
Wolfgang Betz 34:edda6a7238ec 142 tmpstatus = tmpstatus << 8;
Wolfgang Betz 34:edda6a7238ec 143
Wolfgang Betz 34:edda6a7238ec 144 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 145 tmpstatus |= _spi.write(aHeader[1]);
Wolfgang Betz 34:edda6a7238ec 146
Wolfgang Betz 34:edda6a7238ec 147 /* Writes the registers according to the number of bytes */
Wolfgang Betz 34:edda6a7238ec 148 for (int index = 0; index < cNbBytes; index++)
Wolfgang Betz 34:edda6a7238ec 149 {
Wolfgang Betz 34:edda6a7238ec 150 _spi.write(pcBuffer[index]);
Wolfgang Betz 34:edda6a7238ec 151 }
Wolfgang Betz 34:edda6a7238ec 152
Wolfgang Betz 34:edda6a7238ec 153 /* Puts the SPI chip select high to end the transaction */
Wolfgang Betz 34:edda6a7238ec 154 chip_sync_unselect();
Wolfgang Betz 34:edda6a7238ec 155
Wolfgang Betz 34:edda6a7238ec 156 return *pStatus;
Wolfgang Betz 34:edda6a7238ec 157 }
Wolfgang Betz 34:edda6a7238ec 158
Wolfgang Betz 34:edda6a7238ec 159
Wolfgang Betz 34:edda6a7238ec 160 /**
Wolfgang Betz 34:edda6a7238ec 161 * @brief Read single or multiple SPIRIT1 register
Wolfgang Betz 34:edda6a7238ec 162 * @param cRegAddress: base register's address to be read
Wolfgang Betz 34:edda6a7238ec 163 * @param cNbBytes: number of registers and bytes to be read
Wolfgang Betz 34:edda6a7238ec 164 * @param pcBuffer: pointer to the buffer of registers' values read
Wolfgang Betz 34:edda6a7238ec 165 * @retval StatusBytes
Wolfgang Betz 34:edda6a7238ec 166 */
Wolfgang Betz 34:edda6a7238ec 167 StatusBytes SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 168 {
Wolfgang Betz 34:edda6a7238ec 169 return SimpleSpirit1::Instance().SdkEvalSpiReadRegisters(cRegAddress, cNbBytes, pcBuffer);
Wolfgang Betz 34:edda6a7238ec 170 }
Wolfgang Betz 34:edda6a7238ec 171
Wolfgang Betz 34:edda6a7238ec 172 StatusBytes SimpleSpirit1::SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 173 {
Wolfgang Betz 34:edda6a7238ec 174 uint16_t tmpstatus = 0x00;
Wolfgang Betz 34:edda6a7238ec 175 StatusBytes *pStatus = (StatusBytes *)&tmpstatus;
Wolfgang Betz 34:edda6a7238ec 176
Wolfgang Betz 34:edda6a7238ec 177 uint8_t aHeader[2] = {0};
Wolfgang Betz 34:edda6a7238ec 178
Wolfgang Betz 34:edda6a7238ec 179 /* Built the aHeader bytes */
Wolfgang Betz 34:edda6a7238ec 180 aHeader[0] = READ_HEADER;
Wolfgang Betz 34:edda6a7238ec 181 aHeader[1] = cRegAddress;
Wolfgang Betz 34:edda6a7238ec 182
Wolfgang Betz 34:edda6a7238ec 183 /* Put the SPI chip select low to start the transaction */
Wolfgang Betz 34:edda6a7238ec 184 chip_sync_select();
Wolfgang Betz 34:edda6a7238ec 185
Wolfgang Betz 34:edda6a7238ec 186 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 187 tmpstatus = _spi.write(aHeader[0]);
Wolfgang Betz 34:edda6a7238ec 188 tmpstatus = tmpstatus << 8;
Wolfgang Betz 34:edda6a7238ec 189
Wolfgang Betz 34:edda6a7238ec 190 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 191 tmpstatus |= _spi.write(aHeader[1]);
Wolfgang Betz 34:edda6a7238ec 192
Wolfgang Betz 34:edda6a7238ec 193 for (int index = 0; index < cNbBytes; index++)
Wolfgang Betz 34:edda6a7238ec 194 {
Wolfgang Betz 34:edda6a7238ec 195 pcBuffer[index] = _spi.write(0xFF);
Wolfgang Betz 34:edda6a7238ec 196 }
Wolfgang Betz 34:edda6a7238ec 197
Wolfgang Betz 34:edda6a7238ec 198 /* Put the SPI chip select high to end the transaction */
Wolfgang Betz 34:edda6a7238ec 199 chip_sync_unselect();
Wolfgang Betz 34:edda6a7238ec 200
Wolfgang Betz 34:edda6a7238ec 201 return *pStatus;
Wolfgang Betz 34:edda6a7238ec 202 }
Wolfgang Betz 34:edda6a7238ec 203
Wolfgang Betz 34:edda6a7238ec 204
Wolfgang Betz 34:edda6a7238ec 205 /**
Wolfgang Betz 34:edda6a7238ec 206 * @brief Send a command
Wolfgang Betz 34:edda6a7238ec 207 * @param cCommandCode: command code to be sent
Wolfgang Betz 34:edda6a7238ec 208 * @retval StatusBytes
Wolfgang Betz 34:edda6a7238ec 209 */
Wolfgang Betz 34:edda6a7238ec 210 StatusBytes SdkEvalSpiCommandStrobes(uint8_t cCommandCode)
Wolfgang Betz 34:edda6a7238ec 211 {
Wolfgang Betz 34:edda6a7238ec 212 return SimpleSpirit1::Instance().SdkEvalSpiCommandStrobes(cCommandCode);
Wolfgang Betz 34:edda6a7238ec 213 }
Wolfgang Betz 34:edda6a7238ec 214
Wolfgang Betz 34:edda6a7238ec 215 StatusBytes SimpleSpirit1::SdkEvalSpiCommandStrobes(uint8_t cCommandCode)
Wolfgang Betz 34:edda6a7238ec 216 {
Wolfgang Betz 34:edda6a7238ec 217 uint8_t aHeader[2] = {0};
Wolfgang Betz 34:edda6a7238ec 218 uint16_t tmpstatus = 0x0000;
Wolfgang Betz 34:edda6a7238ec 219
Wolfgang Betz 34:edda6a7238ec 220 StatusBytes *pStatus = (StatusBytes *)&tmpstatus;
Wolfgang Betz 34:edda6a7238ec 221
Wolfgang Betz 34:edda6a7238ec 222 /* Built the aHeader bytes */
Wolfgang Betz 34:edda6a7238ec 223 aHeader[0] = COMMAND_HEADER;
Wolfgang Betz 34:edda6a7238ec 224 aHeader[1] = cCommandCode;
Wolfgang Betz 34:edda6a7238ec 225
Wolfgang Betz 34:edda6a7238ec 226 /* Puts the SPI chip select low to start the transaction */
Wolfgang Betz 34:edda6a7238ec 227 chip_sync_select();
Wolfgang Betz 34:edda6a7238ec 228
Wolfgang Betz 34:edda6a7238ec 229 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 230 tmpstatus = _spi.write(aHeader[0]);
Wolfgang Betz 34:edda6a7238ec 231 tmpstatus = tmpstatus<<8;
Wolfgang Betz 34:edda6a7238ec 232
Wolfgang Betz 34:edda6a7238ec 233 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 234 tmpstatus |= _spi.write(aHeader[1]);
Wolfgang Betz 34:edda6a7238ec 235
Wolfgang Betz 34:edda6a7238ec 236 /* Puts the SPI chip select high to end the transaction */
Wolfgang Betz 34:edda6a7238ec 237 chip_sync_unselect();
Wolfgang Betz 34:edda6a7238ec 238
Wolfgang Betz 34:edda6a7238ec 239 return *pStatus;
Wolfgang Betz 34:edda6a7238ec 240 }
Wolfgang Betz 34:edda6a7238ec 241
Wolfgang Betz 34:edda6a7238ec 242
Wolfgang Betz 34:edda6a7238ec 243 /**
Wolfgang Betz 34:edda6a7238ec 244 * @brief Write data into TX FIFO
Wolfgang Betz 34:edda6a7238ec 245 * @param cNbBytes: number of bytes to be written into TX FIFO
Wolfgang Betz 34:edda6a7238ec 246 * @param pcBuffer: pointer to data to write
Wolfgang Betz 34:edda6a7238ec 247 * @retval StatusBytes
Wolfgang Betz 34:edda6a7238ec 248 */
Wolfgang Betz 34:edda6a7238ec 249 StatusBytes SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 250 {
Wolfgang Betz 34:edda6a7238ec 251 return SimpleSpirit1::Instance().SdkEvalSpiWriteFifo(cNbBytes, pcBuffer);
Wolfgang Betz 34:edda6a7238ec 252 }
Wolfgang Betz 34:edda6a7238ec 253
Wolfgang Betz 34:edda6a7238ec 254 StatusBytes SimpleSpirit1::SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 255 {
Wolfgang Betz 34:edda6a7238ec 256 uint16_t tmpstatus = 0x0000;
Wolfgang Betz 34:edda6a7238ec 257 StatusBytes *pStatus = (StatusBytes *)&tmpstatus;
Wolfgang Betz 34:edda6a7238ec 258
Wolfgang Betz 34:edda6a7238ec 259 uint8_t aHeader[2] = {0};
Wolfgang Betz 34:edda6a7238ec 260
Wolfgang Betz 34:edda6a7238ec 261 /* Built the aHeader bytes */
Wolfgang Betz 34:edda6a7238ec 262 aHeader[0] = WRITE_HEADER;
Wolfgang Betz 34:edda6a7238ec 263 aHeader[1] = LINEAR_FIFO_ADDRESS;
Wolfgang Betz 34:edda6a7238ec 264
Wolfgang Betz 34:edda6a7238ec 265 /* Put the SPI chip select low to start the transaction */
Wolfgang Betz 34:edda6a7238ec 266 chip_sync_select();
Wolfgang Betz 34:edda6a7238ec 267
Wolfgang Betz 34:edda6a7238ec 268 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 269 tmpstatus = _spi.write(aHeader[0]);
Wolfgang Betz 34:edda6a7238ec 270 tmpstatus = tmpstatus<<8;
Wolfgang Betz 34:edda6a7238ec 271
Wolfgang Betz 34:edda6a7238ec 272 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 273 tmpstatus |= _spi.write(aHeader[1]);
Wolfgang Betz 34:edda6a7238ec 274
Wolfgang Betz 34:edda6a7238ec 275 /* Writes the registers according to the number of bytes */
Wolfgang Betz 34:edda6a7238ec 276 for (int index = 0; index < cNbBytes; index++)
Wolfgang Betz 34:edda6a7238ec 277 {
Wolfgang Betz 34:edda6a7238ec 278 _spi.write(pcBuffer[index]);
Wolfgang Betz 34:edda6a7238ec 279 }
Wolfgang Betz 34:edda6a7238ec 280
Wolfgang Betz 34:edda6a7238ec 281 /* Put the SPI chip select high to end the transaction */
Wolfgang Betz 34:edda6a7238ec 282 chip_sync_unselect();
Wolfgang Betz 34:edda6a7238ec 283
Wolfgang Betz 34:edda6a7238ec 284 return *pStatus;
Wolfgang Betz 34:edda6a7238ec 285 }
Wolfgang Betz 34:edda6a7238ec 286
Wolfgang Betz 34:edda6a7238ec 287 /**
Wolfgang Betz 34:edda6a7238ec 288 * @brief Read data from RX FIFO
Wolfgang Betz 34:edda6a7238ec 289 * @param cNbBytes: number of bytes to read from RX FIFO
Wolfgang Betz 34:edda6a7238ec 290 * @param pcBuffer: pointer to data read from RX FIFO
Wolfgang Betz 34:edda6a7238ec 291 * @retval StatusBytes
Wolfgang Betz 34:edda6a7238ec 292 */
Wolfgang Betz 34:edda6a7238ec 293 StatusBytes SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 294 {
Wolfgang Betz 34:edda6a7238ec 295 return SimpleSpirit1::Instance().SdkEvalSpiReadFifo(cNbBytes, pcBuffer);
Wolfgang Betz 34:edda6a7238ec 296 }
Wolfgang Betz 34:edda6a7238ec 297
Wolfgang Betz 34:edda6a7238ec 298 StatusBytes SimpleSpirit1::SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer)
Wolfgang Betz 34:edda6a7238ec 299 {
Wolfgang Betz 34:edda6a7238ec 300 uint16_t tmpstatus = 0x0000;
Wolfgang Betz 34:edda6a7238ec 301 StatusBytes *pStatus = (StatusBytes *)&tmpstatus;
Wolfgang Betz 34:edda6a7238ec 302
Wolfgang Betz 34:edda6a7238ec 303 uint8_t aHeader[2];
Wolfgang Betz 34:edda6a7238ec 304
Wolfgang Betz 34:edda6a7238ec 305 /* Built the aHeader bytes */
Wolfgang Betz 34:edda6a7238ec 306 aHeader[0]=READ_HEADER;
Wolfgang Betz 34:edda6a7238ec 307 aHeader[1]=LINEAR_FIFO_ADDRESS;
Wolfgang Betz 34:edda6a7238ec 308
Wolfgang Betz 34:edda6a7238ec 309 /* Put the SPI chip select low to start the transaction */
Wolfgang Betz 34:edda6a7238ec 310 chip_sync_select();
Wolfgang Betz 34:edda6a7238ec 311
Wolfgang Betz 34:edda6a7238ec 312 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 313 tmpstatus = _spi.write(aHeader[0]);
Wolfgang Betz 34:edda6a7238ec 314 tmpstatus = tmpstatus<<8;
Wolfgang Betz 34:edda6a7238ec 315
Wolfgang Betz 34:edda6a7238ec 316 /* Write the aHeader bytes and read the SPIRIT1 status bytes */
Wolfgang Betz 34:edda6a7238ec 317 tmpstatus |= _spi.write(aHeader[1]);
Wolfgang Betz 34:edda6a7238ec 318
Wolfgang Betz 34:edda6a7238ec 319 for (int index = 0; index < cNbBytes; index++)
Wolfgang Betz 34:edda6a7238ec 320 {
Wolfgang Betz 34:edda6a7238ec 321 pcBuffer[index] = _spi.write(0xFF);
Wolfgang Betz 34:edda6a7238ec 322 }
Wolfgang Betz 34:edda6a7238ec 323
Wolfgang Betz 34:edda6a7238ec 324 /* Put the SPI chip select high to end the transaction */
Wolfgang Betz 34:edda6a7238ec 325 chip_sync_unselect();
Wolfgang Betz 34:edda6a7238ec 326
Wolfgang Betz 34:edda6a7238ec 327 return *pStatus;
Wolfgang Betz 34:edda6a7238ec 328 }
Wolfgang Betz 34:edda6a7238ec 329
Wolfgang Betz 34:edda6a7238ec 330
Wolfgang Betz 34:edda6a7238ec 331 /**
Wolfgang Betz 34:edda6a7238ec 332 * @}
Wolfgang Betz 34:edda6a7238ec 333 */
Wolfgang Betz 34:edda6a7238ec 334
Wolfgang Betz 34:edda6a7238ec 335 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/