Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
DC2217A.ino
Go to the documentation of this file.
1 /*!
2 DC2217A
3 LTC4316: Single/Dual I2C SMBUS ADDRESS REMAPPER
4 
5 @verbatim
6 
7 LTC4316 Remapper Menu
8  1. Scan Bus for Addresses
9  2. Control On Board DACs
10 
11 Control On Board DACs:
12  1. Turn on Through DAC
13  2. Turn on Remapped DAC
14  3. Turn off Through DAC
15  4. Turn off Remapped DAC
16 
17 NOTES
18  Setup:
19  Set the terminal baud rate to 115200 and select the newline terminator.
20  Requires a power supply.
21  Refer to demo manual DC2217A.
22 
23 USER INPUT DATA FORMAT:
24  decimal : 1024
25  hex : 0x400
26  octal : 02000 (leading 0 "zero")
27  binary : B10000000000
28  float : 1024.0
29 
30 @endverbatim
31 
32 http://www.linear.com/product/LTC4316
33 
34 http://www.linear.com/product/LTC4316#demoboards
35 
36 
37 Copyright 2018(c) Analog Devices, Inc.
38 
39 All rights reserved.
40 
41 Redistribution and use in source and binary forms, with or without
42 modification, are permitted provided that the following conditions are met:
43  - Redistributions of source code must retain the above copyright
44  notice, this list of conditions and the following disclaimer.
45  - Redistributions in binary form must reproduce the above copyright
46  notice, this list of conditions and the following disclaimer in
47  the documentation and/or other materials provided with the
48  distribution.
49  - Neither the name of Analog Devices, Inc. nor the names of its
50  contributors may be used to endorse or promote products derived
51  from this software without specific prior written permission.
52  - The use of this software may or may not infringe the patent rights
53  of one or more patent holders. This license does not release you
54  from the requirement that you obtain separate licenses from these
55  patent holders to use this software.
56  - Use of the software either in source or binary form, must be run
57  on or directly connected to an Analog Devices Inc. component.
58 
59 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
60 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
61 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
63 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
64 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
65 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
66 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
67 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
68 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69  */
70 
71 //! @ingroup Transceivers
72 //! @{
73 //! @defgroup LTC4316 LTC4316: Single/Dual I2C SMBUS ADDRESS REMAPPER
74 //! @}
75 
76 /*! @file
77  @ingroup LTC4316
78  Library for LTC4316: Single/Dual I2C SMBUS ADDRESS REMAPPER
79 */
80 
81 #include <Arduino.h>
82 #include "LT_I2C.h"
83 #include "UserInterface.h"
84 #include "QuikEval_EEPROM.h"
85 #include "Linduino.h"
86 #include <Wire.h>
87 #include <stdint.h>
88 
89 
90 
91 static int8_t demo_board_connected; //!< Set to 1 if the board is connected
92 
93 const char ack_error[] = "Error: No Acknowledge. Check I2C Address."; //!< Error message
94 
95 const int LTC4316_OFFSET = 0x78; //!< Demoboard offset. Change to correct value if EXT offset if chosen.
96 const int LTC2631_GLOBAL_ADDRESS = 0x73; //!< Global address of LTC2631 DAC
97 const int LTC2631_JP_ADDRESS_1 = 0x12; //!< Jumper Setting 1 on Demoboard
98 const int LTC2631_JP_ADDRESS_2 = 0x11; //!< Jumper Setting 2 on Demoboard
99 const int LTC2631_JP_ADDRESS_3 = 0x10; //!< Jumper Setting 3 on Demoboard
100 const int EEPROM_ADDRESS = 0x50; //!< EEPROM Address on Demoboard
101 
102 //! Initialize Linduino
103 void setup()
104 {
105  char demo_name[] = "DC2217A"; // Demo Board Name stored in QuikEval EEPROM
106  quikeval_I2C_init(); //! Configure the EEPROM I2C port for 100kHz
107  quikeval_I2C_connect(); //! Connects to main I2C port
108  Serial.begin(115200); //! Initialize the serial port to the PC
109  print_title(); //! Print Title
112  {
113  Serial.println(F("Demo board not detected, will attempt to proceed"));
114  demo_board_connected = true;
115  }
117  {
118  print_prompt();
119  }
120 }
121 
122 //! Repeats Linduino Loop
123 void loop()
124 {
125 
126  int8_t ack = 0; //! I2C acknowledge indicator
127  static uint8_t user_command; //! The user input command
128  if (demo_board_connected) //! Do nothing if the demo board is not connected
129  {
130  if (Serial.available()) //! Do nothing if serial is not available
131  {
132  user_command = read_int(); //! Read user input command
133  if (user_command != 'm')
134  Serial.println(user_command);
135  Serial.println();
136  ack = 0;
137  switch (user_command) //! Check user input.
138  {
139  case 1:
140  menu_1_scan_addresses(); //!< Perform I2C Address Scan
141  break;
142  case 2:
143  ack |= menu_2_DAC(); //!< Control on board DACs
144  break;
145  default:
146  Serial.println("Incorrect Option");
147  }
148 
149  if (ack != 0)
150  Serial.println(ack_error);
151  Serial.print(F("*************************"));
152  print_prompt();
153  }
154  }
155 }
156 
157 
158 
159 // Function Definitions
160 //! Print the title block
162 {
163  Serial.println(F("\n*****************************************************************"));
164  Serial.print(F("* DC2156 Demonstration Program *\n"));
165  Serial.print(F("* *\n"));
166  Serial.print(F("* This program demonstrates the functionality of the LTC4316 *\n"));
167  Serial.print(F("* which is a Single/Dual I2C SMBus Remappper. The program *\n"));
168  Serial.print(F("* scans the addresses present on the bus and controls the *\n"));
169  Serial.print(F("* onboard remapped DACs to light LEDs *\n"));
170  Serial.print(F("* *\n"));
171  Serial.print(F("*****************************************************************\n"));
172 }
173 
174 //! Print the main menu prompt
176 {
177  Serial.print(F("\n1- Scan Bus for Addresses\n"));
178  Serial.print(F("2- Control On Board DACs\n"));
179  Serial.print(F("\n"));
180  Serial.print(F("Enter a command: "));
181 }
182 
183 //! Scan I2C Bus for addresses
185 {
186 
187  int maxAddr = 127; //! Max Number for possible 7-bit address values
188  int addrCount = 0; //! Initialization of address count.
189 
190  for (int addr = 0x00; addr <= maxAddr; addr++) //! Scan possible address values till max address number
191  {
192  int8_t ret= 0 ; //! Initialize return bit variable
193  if (i2c_start()!=0) //! I2C START
194  {
195  Serial.print(F("Bus is Busy. Aborting...")); //! Stop and abort scanning if bus is busy.
196  break;
197  }
198 
199  ret |= i2c_write((addr<<1)|I2C_WRITE_BIT); //! Write the I2C 7 bit address with W bit
200  i2c_stop(); //! I2C STOP
201  if (ret==0) //! If acknolwege recieved on bus, print address
202  {
203  addrCount++; //! Increment address count
204  Serial.print(F("\n Address Found - #"));
205  Serial.print(addrCount); //! Print address count
206  Serial.print(F(": "));
207  Serial.print(addr, HEX); //! Print address
208 
209  switch (addr) //! Switch statement to identify factory set possible address values. Note: If external address has the same address as any of the jumper settings
210  //! it might register as one of the switch statements
211  {
212  case EEPROM_ADDRESS:
213  Serial.print(F(" - Onboard EEPROM Address."));
214  break;
215  case (LTC2631_GLOBAL_ADDRESS):
216  Serial.print(F(" - Through Global Address of LTC2631"));
217  break;
219  Serial.print(F(" - Remapped Global Address of LTC2631"));
220  break;
221  case (LTC2631_JP_ADDRESS_1):
222  Serial.print(F(" - Through Jumper Setting of Onboard LTC2631"));
223  break;
224  case (LTC2631_JP_ADDRESS_2):
225  Serial.print(F(" - Through Jumper Setting of Onboard LTC2631"));
226  break;
227  case (LTC2631_JP_ADDRESS_3):
228  Serial.print(F(" - Through Jumper Setting of Onboard LTC2631"));
229  break;
230  case (LTC2631_JP_ADDRESS_1 ^ LTC4316_OFFSET):
231  Serial.print(F(" - Remapped Address of Onboard LTC2631 Based On Jumper Setting 12h"));
232  break;
233  case (LTC2631_JP_ADDRESS_2 ^ LTC4316_OFFSET):
234  Serial.print(F(" - Remapped Address of Onboard LTC2631 Based On Jumper Setting 11h"));
235  break;
236  case (LTC2631_JP_ADDRESS_3 ^ LTC4316_OFFSET):
237  Serial.print(F(" - Remapped Address of Onboard LTC2631 Based On Jumper Setting 11h"));
238  break;
239  default:
240  Serial.print(F(" - Unknown Address Found. Possible external device connected and/or Non-Factory address selected."));
241  break;
242  }
243  Serial.print("\n\n");
244  }
245  }
246 
247  if (addrCount == 0)
248  Serial.println(F("Nothing Found on Bus"));
249 }
250 
251 //! DAC Control Menu
252 uint8_t menu_2_DAC()
253 {
254 //! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
255 
256  int ack = 0; //! I2C acknowledge indicator
257  static uint8_t user_command; //! The user input command
258  int maxAddr = 127; //! Max Number for possible 7-bit address values
259  int addrCount = 0; //! Initialization of address count.
260  uint8_t LTC2631_CMD_WRITE_UPDATE = 0x30; //! LTC2631 Write and Update Command Byte
261  uint16_t LTC2631_FULLSCALE_OUTPUT = 0xFFC0; //! LTC2631 10 bit fullscale input value
262  uint8_t through_address = 0; //! Through address value
263  uint8_t remapped_address = 0; //! Remapped address value
264 
265  for (int addr = 0x00; addr <= maxAddr; addr++)
266  {
267  int8_t ret= 0 ;
268 
269  if (i2c_start()!=0) //I2C START
270  {
271  Serial.print(F("Bus is Busy. Aborting...")); //Stop and abort scanning if bus is busy.
272  break;
273  }
274 
275  ret |= i2c_write((addr<<1)|I2C_WRITE_BIT); //Write the I2C 7 bit address with W bit
276  i2c_stop(); //I2C STOP
277  if (ret==0) // Returns 1 if failed
278  {
279  switch (addr) //Switch statement to assign addresses based on default demoboard configuration. External addresses are not supported and could cause conflict.
280  {
284  through_address = addr;
285  break;
289  remapped_address = addr;
290  break;
291  case EEPROM_ADDRESS:
294  break;
295  default:
296  Serial.print(F(" - Unknown Address Found. Possible external device connected and/or Non-Factory address selected."));
297  break;
298  }
299  Serial.print("\n\n");
300  }
301  }
302 
303  do
304  {
305  Serial.print(F("*************************\n\n"));
306  Serial.print(F("Turn on DACs\n"));
307  Serial.print(F("1-Turn on Through DAC\n"));
308  Serial.print(F("2-Turn on Remapped DAC\n"));
309  Serial.print(F("3-Turn off Through DAC\n"));
310  Serial.print(F("4-Turn off Through DAC\n"));
311  Serial.print(F("m-Main Menu\n\n"));
312  Serial.print(F("Enter a command: "));
313 
314  user_command = read_int(); //! Read user input command
315  if (user_command != 'm')
316  Serial.println(user_command);
317  if (user_command == 'm')
318  Serial.println("m");
319  Serial.println();
320  ack = 0;
321  switch (user_command) //! Switch statement for DAC menu
322  {
323  case 1:
324  ack |= i2c_write_word_data(through_address,LTC2631_CMD_WRITE_UPDATE, LTC2631_FULLSCALE_OUTPUT); //! I2C write command to turn Through DAC on
325  break;
326  case 2:
327  ack |= i2c_write_word_data(remapped_address,LTC2631_CMD_WRITE_UPDATE, LTC2631_FULLSCALE_OUTPUT); //! I2C write command to turn Remapped DAC on
328  break;
329  case 3:
330  ack |= i2c_write_word_data(through_address, LTC2631_CMD_WRITE_UPDATE, 0x0000); //! I2c write command to turn through DAC off
331  break;
332  case 4:
333  ack |= i2c_write_word_data(remapped_address, LTC2631_CMD_WRITE_UPDATE, 0x0000); //! I2C write command to turn remapped DAC off
334  default:
335  if (user_command != 'm')
336  Serial.println("Incorrect Option");
337  }
338  }
339  while (!(user_command == 'm' || (ack)));
340  if (ack != 0)
341  Serial.println(ack_error);
342  return ack;
343 }
#define I2C_WRITE_BIT
Definition: LT_I2C.h:64
long ret
const int LTC4316_OFFSET
Demoboard offset.
Definition: DC2217A.ino:95
unsigned char user_command
static void menu_1_scan_addresses()
Scan I2C Bus for addresses.
Definition: DC2217A.ino:184
static void print_title()
Print the title block.
Definition: DC2217A.ino:161
Header File for Linduino Libraries and Demo Code.
const int LTC2631_GLOBAL_ADDRESS
Global address of LTC2631 DAC.
Definition: DC2217A.ino:96
void i2c_stop()
Write stop bit to the hardware I2C port.
Definition: LT_I2C.cpp:462
int8_t i2c_start()
Write start bit to the hardware I2C port.
Definition: LT_I2C.cpp:425
static uint8_t menu_2_DAC()
DAC Control Menu.
Definition: DC2217A.ino:252
static int8_t demo_board_connected
Set to 1 if the board is connected.
Definition: DC2217A.ino:91
const int EEPROM_ADDRESS
EEPROM Address on Demoboard.
Definition: DC2217A.ino:100
int8_t i2c_write_word_data(uint8_t address, uint8_t command, uint16_t value)
Write a 16-bit word of data to register specified by "command".
Definition: LT_I2C.cpp:216
int8_t i2c_write(uint8_t data)
Send a data byte to hardware I2C port.
Definition: LT_I2C.cpp:470
static void setup()
Initialize Linduino.
Definition: DC2217A.ino:103
QuikEval EEPROM Library.
const int LTC2631_JP_ADDRESS_3
Jumper Setting 3 on Demoboard.
Definition: DC2217A.ino:99
const int LTC2631_JP_ADDRESS_2
Jumper Setting 2 on Demoboard.
Definition: DC2217A.ino:98
LT_I2C: Routines to communicate with ATmega328P&#39;s hardware I2C port.
char demo_name[]
Demo Board Name stored in QuikEval EEPROM.
Definition: DC1880A.ino:97
static void loop()
Repeats Linduino Loop.
Definition: DC2217A.ino:123
int32_t read_int()
const char ack_error[]
Error message.
Definition: DC2217A.ino:93
const int LTC2631_JP_ADDRESS_1
Jumper Setting 1 on Demoboard.
Definition: DC2217A.ino:97
void quikeval_I2C_init(void)
Initializes Linduino I2C port.
Definition: LT_I2C.cpp:394
void quikeval_I2C_connect(void)
Switch MUX to connect I2C pins to QuikEval connector.
Definition: LT_I2C.cpp:401
static void print_prompt()
Print the main menu prompt.
Definition: DC2217A.ino:175