bms_hardware
Embed:
(wiki syntax)
Show/hide line numbers
bms_hardware.cpp
00001 /*! 00002 ltc681x hardware library 00003 @verbatim 00004 This library contains all of the hardware dependant functions used by the bms 00005 code 00006 @endverbatim 00007 REVISION HISTORY 00008 $Revision: 7139 $ 00009 $Date: 2017-4 00010 00011 Copyright (c) 2017, Linear Technology Corp.(LTC) 00012 All rights reserved. 00013 00014 Redistribution and use in source and binary forms, with or without 00015 modification, are permitted provided that the following conditions are met: 00016 00017 1. Redistributions of source code must retain the above copyright notice, this 00018 list of conditions and the following disclaimer. 00019 2. Redistributions in binary form must reproduce the above copyright notice, 00020 this list of conditions and the following disclaimer in the documentation 00021 and/or other materials provided with the distribution. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00024 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00025 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00027 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00028 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00030 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00031 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00032 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 The views and conclusions contained in the software and documentation are those 00035 of the authors and should not be interpreted as representing official policies, 00036 either expressed or implied, of Linear Technology Corp. 00037 00038 The Linear Technology Linduino is not affiliated with the official Arduino team. 00039 However, the Linduino is only possible because of the Arduino team's commitment 00040 to the open-source community. Please, visit http://www.arduino.cc and 00041 http://store.arduino.cc , and consider a purchase that will help fund their 00042 ongoing work. 00043 00044 Copyright 2017 Linear Technology Corp. (LTC) 00045 */ 00046 #include "bms_hardware.h" 00047 00048 /* 00049 Writes an array of bytes out of the SPI port 00050 */ 00051 void spi_write_array(uint8_t len, // Option: Number of bytes to be written on the SPI port 00052 uint8_t data[] //Array of bytes to be written on the SPI port 00053 ) 00054 { 00055 for (uint8_t i = 0; i < len; i++) 00056 { 00057 spi.write((int8_t)data[i]); 00058 } 00059 } 00060 00061 /* 00062 Writes and read a set number of bytes using the SPI port. 00063 00064 */ 00065 00066 void spi_write_read(uint8_t tx_Data[],//array of data to be written on SPI port 00067 uint8_t tx_len, //length of the tx data arry 00068 uint8_t *rx_data,//Input: array that will store the data read by the SPI port 00069 uint8_t rx_len //Option: number of bytes to be read from the SPI port 00070 ) 00071 { 00072 for (uint8_t i = 0; i < tx_len; i++) 00073 { 00074 spi.write(tx_Data[i]); 00075 } 00076 00077 for (uint8_t i = 0; i < rx_len; i++) 00078 { 00079 00080 rx_data[i] = (uint8_t)spi.write(0xFF); 00081 } 00082 00083 } 00084 00085 00086 uint8_t spi_read_byte(uint8_t tx_dat) 00087 { 00088 uint8_t data; 00089 data = (uint8_t)spi.write(0xFF); 00090 return(data); 00091 }
Generated on Tue Jul 19 2022 05:01:14 by 1.7.2