bms_hardware
bms_hardware.cpp@0:5f17f13ad875, 2017-11-12 (annotated)
- Committer:
- roger5641
- Date:
- Sun Nov 12 01:21:53 2017 +0000
- Revision:
- 0:5f17f13ad875
ver1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
roger5641 | 0:5f17f13ad875 | 1 | /*! |
roger5641 | 0:5f17f13ad875 | 2 | ltc681x hardware library |
roger5641 | 0:5f17f13ad875 | 3 | @verbatim |
roger5641 | 0:5f17f13ad875 | 4 | This library contains all of the hardware dependant functions used by the bms |
roger5641 | 0:5f17f13ad875 | 5 | code |
roger5641 | 0:5f17f13ad875 | 6 | @endverbatim |
roger5641 | 0:5f17f13ad875 | 7 | REVISION HISTORY |
roger5641 | 0:5f17f13ad875 | 8 | $Revision: 7139 $ |
roger5641 | 0:5f17f13ad875 | 9 | $Date: 2017-4 |
roger5641 | 0:5f17f13ad875 | 10 | |
roger5641 | 0:5f17f13ad875 | 11 | Copyright (c) 2017, Linear Technology Corp.(LTC) |
roger5641 | 0:5f17f13ad875 | 12 | All rights reserved. |
roger5641 | 0:5f17f13ad875 | 13 | |
roger5641 | 0:5f17f13ad875 | 14 | Redistribution and use in source and binary forms, with or without |
roger5641 | 0:5f17f13ad875 | 15 | modification, are permitted provided that the following conditions are met: |
roger5641 | 0:5f17f13ad875 | 16 | |
roger5641 | 0:5f17f13ad875 | 17 | 1. Redistributions of source code must retain the above copyright notice, this |
roger5641 | 0:5f17f13ad875 | 18 | list of conditions and the following disclaimer. |
roger5641 | 0:5f17f13ad875 | 19 | 2. Redistributions in binary form must reproduce the above copyright notice, |
roger5641 | 0:5f17f13ad875 | 20 | this list of conditions and the following disclaimer in the documentation |
roger5641 | 0:5f17f13ad875 | 21 | and/or other materials provided with the distribution. |
roger5641 | 0:5f17f13ad875 | 22 | |
roger5641 | 0:5f17f13ad875 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
roger5641 | 0:5f17f13ad875 | 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
roger5641 | 0:5f17f13ad875 | 25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
roger5641 | 0:5f17f13ad875 | 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
roger5641 | 0:5f17f13ad875 | 27 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
roger5641 | 0:5f17f13ad875 | 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
roger5641 | 0:5f17f13ad875 | 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
roger5641 | 0:5f17f13ad875 | 30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
roger5641 | 0:5f17f13ad875 | 31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
roger5641 | 0:5f17f13ad875 | 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
roger5641 | 0:5f17f13ad875 | 33 | |
roger5641 | 0:5f17f13ad875 | 34 | The views and conclusions contained in the software and documentation are those |
roger5641 | 0:5f17f13ad875 | 35 | of the authors and should not be interpreted as representing official policies, |
roger5641 | 0:5f17f13ad875 | 36 | either expressed or implied, of Linear Technology Corp. |
roger5641 | 0:5f17f13ad875 | 37 | |
roger5641 | 0:5f17f13ad875 | 38 | The Linear Technology Linduino is not affiliated with the official Arduino team. |
roger5641 | 0:5f17f13ad875 | 39 | However, the Linduino is only possible because of the Arduino team's commitment |
roger5641 | 0:5f17f13ad875 | 40 | to the open-source community. Please, visit http://www.arduino.cc and |
roger5641 | 0:5f17f13ad875 | 41 | http://store.arduino.cc , and consider a purchase that will help fund their |
roger5641 | 0:5f17f13ad875 | 42 | ongoing work. |
roger5641 | 0:5f17f13ad875 | 43 | |
roger5641 | 0:5f17f13ad875 | 44 | Copyright 2017 Linear Technology Corp. (LTC) |
roger5641 | 0:5f17f13ad875 | 45 | */ |
roger5641 | 0:5f17f13ad875 | 46 | #include "bms_hardware.h" |
roger5641 | 0:5f17f13ad875 | 47 | |
roger5641 | 0:5f17f13ad875 | 48 | /* |
roger5641 | 0:5f17f13ad875 | 49 | Writes an array of bytes out of the SPI port |
roger5641 | 0:5f17f13ad875 | 50 | */ |
roger5641 | 0:5f17f13ad875 | 51 | void spi_write_array(uint8_t len, // Option: Number of bytes to be written on the SPI port |
roger5641 | 0:5f17f13ad875 | 52 | uint8_t data[] //Array of bytes to be written on the SPI port |
roger5641 | 0:5f17f13ad875 | 53 | ) |
roger5641 | 0:5f17f13ad875 | 54 | { |
roger5641 | 0:5f17f13ad875 | 55 | for (uint8_t i = 0; i < len; i++) |
roger5641 | 0:5f17f13ad875 | 56 | { |
roger5641 | 0:5f17f13ad875 | 57 | spi.write((int8_t)data[i]); |
roger5641 | 0:5f17f13ad875 | 58 | } |
roger5641 | 0:5f17f13ad875 | 59 | } |
roger5641 | 0:5f17f13ad875 | 60 | |
roger5641 | 0:5f17f13ad875 | 61 | /* |
roger5641 | 0:5f17f13ad875 | 62 | Writes and read a set number of bytes using the SPI port. |
roger5641 | 0:5f17f13ad875 | 63 | |
roger5641 | 0:5f17f13ad875 | 64 | */ |
roger5641 | 0:5f17f13ad875 | 65 | |
roger5641 | 0:5f17f13ad875 | 66 | void spi_write_read(uint8_t tx_Data[],//array of data to be written on SPI port |
roger5641 | 0:5f17f13ad875 | 67 | uint8_t tx_len, //length of the tx data arry |
roger5641 | 0:5f17f13ad875 | 68 | uint8_t *rx_data,//Input: array that will store the data read by the SPI port |
roger5641 | 0:5f17f13ad875 | 69 | uint8_t rx_len //Option: number of bytes to be read from the SPI port |
roger5641 | 0:5f17f13ad875 | 70 | ) |
roger5641 | 0:5f17f13ad875 | 71 | { |
roger5641 | 0:5f17f13ad875 | 72 | for (uint8_t i = 0; i < tx_len; i++) |
roger5641 | 0:5f17f13ad875 | 73 | { |
roger5641 | 0:5f17f13ad875 | 74 | spi.write(tx_Data[i]); |
roger5641 | 0:5f17f13ad875 | 75 | } |
roger5641 | 0:5f17f13ad875 | 76 | |
roger5641 | 0:5f17f13ad875 | 77 | for (uint8_t i = 0; i < rx_len; i++) |
roger5641 | 0:5f17f13ad875 | 78 | { |
roger5641 | 0:5f17f13ad875 | 79 | |
roger5641 | 0:5f17f13ad875 | 80 | rx_data[i] = (uint8_t)spi.write(0xFF); |
roger5641 | 0:5f17f13ad875 | 81 | } |
roger5641 | 0:5f17f13ad875 | 82 | |
roger5641 | 0:5f17f13ad875 | 83 | } |
roger5641 | 0:5f17f13ad875 | 84 | |
roger5641 | 0:5f17f13ad875 | 85 | |
roger5641 | 0:5f17f13ad875 | 86 | uint8_t spi_read_byte(uint8_t tx_dat) |
roger5641 | 0:5f17f13ad875 | 87 | { |
roger5641 | 0:5f17f13ad875 | 88 | uint8_t data; |
roger5641 | 0:5f17f13ad875 | 89 | data = (uint8_t)spi.write(0xFF); |
roger5641 | 0:5f17f13ad875 | 90 | return(data); |
roger5641 | 0:5f17f13ad875 | 91 | } |