Nano River Technologies April 2009

Similar documents
Nano River Technologies October 2010

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K

THE HONG KONG POLYTECHNIC UNIVERSITY Faculty of Engineering. Computer Programming Closed-book Written Test 3 Date: 28 March 2009 Time: 2:30 3:30 pm

Application Brief. Using the Total Phase CAN/I2C Activity Board Pro as an I2C- to- CAN Translator Application Brief by Rick Bogart

ASNTu2s PCB with Tiger Board USB to 7-Channel 3-Wire Interface Bridge Application Notes

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

SwitchLinc 2-Wire Dimmer (RF Only) (2474DWH - Dev 0x01 / Sub 0x24)

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

USB-910H API DLL and Include File Reference Manual

UART TO SPI SPECIFICATION

Armide Documentation. Release Kyle Mayes

Lab 1: First Steps in C++ - Eclipse

Micro Module Shutter. Micro Module Shutter

I2C and SPI Foundation

C Refresher, Advance C, Coding Standard, Misra C Compliance & Real-time Programming

UM1064 User manual. Software guide for Unico Lite. Introduction

Intermediate Programming, Spring 2017*

LatticeMico32 SPI Flash Controller

Program Organization and Comments

USER MANUAL EXPERIENCE INCREDIBLE PERFORMANCE V2.3

Venstar Thermostat Adapter

INSTEON Hidden Door Sensor

QBridge. I2C, SPI, CAN Control Software User s Manual. Date: Rev 1.3

Bootloader project Project with a Bootloader Component and communication Component.

Introduction to Programming Using Java (98-388)

Application Note: AN00152 xscope - Bi-Directional Endpoint

Using Embedded Tools for I2C, SPI, and USB Debugging for the Renesas RX63N RDK

Reprinted by permission of T&L Publications Inc. Copyright 2001 USB MICROCONTROLLERS FOR THE MASSES

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Read section 8 of this document for detailed instructions on how to use this interface spec with LibUSB For OSX

F²MC-8FX FAMILY 8-BIT MICROCONTROLLER MB95200H SERIES SPI SW REALIZATION USING GPIO APPLICATION NOTE

ice40 UltraPlus Image Sensor Elliptical Crypto Engine (ECC) Demo - Radiant Software User Guide

Serial Communication. Simplex Half-Duplex Duplex

MPX-24794S Serial USB Card

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

AN022: The Bootloader Protocol

FLASH Programming in Production of VS1000 Applications

C++ For Science and Engineering Lecture 12

Model Viva Questions for Programming in C lab

Altera DE2 I2C Driver. Daniel Fiske Michael Lam Daniel Tiam

JENET C LIBRARY API ver. 3.00

CS2141 Software Development using C/C++ C++ Basics

Developer Notes for KeypadLinc Line

Bootloader Design Techniques for Microcontrollers

/* defines are mostly used to declare constants */ #define MAX_ITER 10 // max number of iterations

General Purpose GUI Overview

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Detecting Errors in the Dual Port TPU RAM (DPTRAM) Module

Dragon12 LCD Displays Hantronix_CLD.PDF data sheet (Dragon12 CD-ROM) Dragon12 LCD Display. The Dragon12 board has a 16 character x 2 line display

17. I 2 C communication channel

ZIO Java API. Tutorial. 1.2, Feb 2012

Freescale Semiconductor, I

PusleIR Multitouch Screen Software SDK Specification. Revision 4.0

USB-I2C USB to I2C Communications Module Technical Specification

Keithley KPCI-3160 Series

Migrating to Venom2. Part 1: Language Changes

Parallel Data Transfer. Suppose you need to transfer data from one HCS12 to another. How can you do this?

ECE 598 Advanced Operating Systems Lecture 6

CANopen Win API. Version TK Engineering Oy

CC2650 Java SBL Imp CC2650.

ArduCAM-M-2MP Camera Shield

VS10XX REAL-TIME MIDI INPUT

I2C a learn.sparkfun.com tutorial

8051 Microcontroller

Communications API. TEAM A : Communications and Integration Group. April 15, 1995

Software Development With Emacs: The Edit-Compile-Debug Cycle

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

Microcontrollers and Interfacing

Application Note: AN00151 xscope - Custom Host Endpoint

SC5360B Manual SC5360B. 9.3 GHz Dual Channel Phase Coherent RF Downconverter. Core Module with USB and SPI

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers

CS16 Exam #1 7/17/ Minutes 100 Points total

Tutorial 5 Completing the Inventory Application Introducing Programming

EL-USB-RT API Guide V1.0

SPI Framework Module Guide

Keyboards. The PS/2 Protocol

Fredrick M. Cady. Assembly and С Programming forthefreescalehcs12 Microcontroller. шт.

Tokens, Expressions and Control Structures

Using the Z8051 MCU s USI Peripheral as an SPI Interface

ECE2049-E18 Lecture 6 Notes 1. ECE2049: Embedded Computing in Engineering Design E Term Lecture #6: Exam Review

Generalised User Interface for Embedded Applications using an LCD screen and keypad.

App Note Application Note: Addressing Multiple FPAAs Using a SPI Interface

Laboratory 5 Communication Interfaces

Summary of basic C++-commands

Design UART Loopback with Interrupts

ECE2049: Embedded Computing in Engineering Design A Term Fall Lecture #9: Exam Review w/ Solutions

Serial communications with SPI

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

BioTac C Library Manual for Cheetah

Maths 1264 Quiz 1 answers Thursday 22/1/15

SpiNNaker Application Programming Interface (API)

User Manual. SUSI Library

STD_CU43USBSW_V1.0E. CUnet (MKY43) USB Unit. CU-43USB Software Manual

2. Numbers In, Numbers Out

Short Notes of CS201

AN2737 Application note Basic in-application programming example using the STM8 I 2 C and SPI peripherals Introduction

Project 15 - Reading a keypad with the Raspberry Pi

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

RVDS 4.0 Introductory Tutorial

Getting started with E909.06

Transcription:

Miniboard Nano River Technologies April 2009 Rev: 1.4 (Apr 2009) Nano River Technolgies Page 1 of 67

Table of Contents 1. OVERVIEW... 4 2. WINDOWS GPIO TOOL... 5 2.1. FUNCTIONALITY... 5 2.2. PROJECT STRUCTURE... 6 2.3. DESIGN DESCRIPTION... 8 3. IIC COMMAND TOOL... 11 3.1. FUNCTIONALITY... 12 3.2. PROJECT STRUCTURE... 13 3.3. DESIGN DESCRIPTION... 15 4. WINDOWS IIC TOOL... 20 4.1. FUNCTIONALITY... 21 4.2. PROJECT STRUCTURE... 22 4.3. DESIGN DESCRIPTION... 24 5. WINDOWS EEPROM PROGRAMMER... 30 5.1. FUNCTIONALITY... 31 5.2. PROJECT STRUCTURE... 32 5.3. DESIGN DESCRIPTION... 34 6. IIC COMMAND TOOL (LINUX AND MACOS VERSIONS)... 48 6.1. FUNCTIONALITY... 49 6.2. PROJECT STRUCTURE... 50 6.3. DESIGN DESCRIPTION... 51 7. CONFIGURATION EXAMPLE (LINUX AND MACOS VERSIONS)... 52 7.1. FUNCTIONALITY... 53 7.2. PROJECT STRUCTURE... 54 7.3. DESIGN DESCRIPTION... 56 8. IIC CHECKER TOOL (MACOS XCODE COCOA)... 61 8.1. FUNCTIONALITY... 61 8.2. PROJECT STRUCTURE... 62 8.3. DESIGN DESCRIPTION... 66 Rev: 1.4 (Apr 2009) Nano River Technolgies Page 2 of 67

ABBREVIATIONS API EEPROM G++ GCC GPIO I2C IDE IIC IO NRT SPI USB Application Programming Interface Electrically Erasable Programmable Read Only Memory C++ compiler for Linux (part of GCC) GNU Compiler Collection General Purpose IO Inter-Integrated Circuit Integrated Design Environment Inter-Integrated Circuit (same as I2C) Input / Output Nano River Technologies Serial Peripheral Interface Universal Serial Bus Rev: 1.4 (Apr 2009) Nano River Technolgies Page 3 of 67

1. Overview This document provides information about the four application examples which come with the MiniBoard from Nano River Technologies. The application examples aim to show how to build your own C/C++ and Visual C++ applications and interface to the MiniBoard API. The four example applications described in the document are: Windows GPIO Tool IIC Command Tool Windows IIC Tool Windows EEPROM Programmer Two further examples have been included for Linux and MacOS applications. These run using GCC. IIC Command Tool (Linux and MacOS Versions) Configuration Example (Linux and MacOS Versions) One example is provided to show how to use MiniBoard from Xcode Cocoa, which is the current GUI IDE for MacOS. IIC Checker Tool (MacOS Xcode Cocoa) Rev: 1.4 (Apr 2009) Nano River Technolgies Page 4 of 67

2. Windows GPIO Tool This example application is a very simple Visual C++ GUI application showing how to interface to the general purpose IO (GPIO) pins. Slider Control Read Value 2.1. Functionality To use the application the user needs to select one of three slider control settings. One slider is provided for each bit. Each bit can be driven high as an output, driven low as an output or used as an input. Irrespective of whether the pin is configured as input or output the GPIO pin is then sampled and displayed as the read value. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 5 of 67

2.2. Project Structure In order to create such a Windows application in Visual C++, first start up a new project and select Window Form Application as the project type. This will create a standard Windows application. The project file structure will then look as follows. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 6 of 67

To this, one must add the MiniBoard class header file (miniboard_class.h) and MiniBoard class C++ file as follows. Windows Form Description MiniBoard Class Header File Application Top Level C++ File MiniBoard Class C++ File Remember to change the Common Language Runtime support to /clr. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 7 of 67

2.3. Design Description The main file which needs to be developed in a Windows GUI application is the Windows form application file (Form1.h). This can be built up graphically by dragging in elements of the.net development toolbox and/or by editing the Form1.h text file. The final Form1.h file can be found in the downloaded files for the GPIO Windows application available on the web-site. The file starts by linking to the MiniBoard class library header file: Nano River Technologies File: GPIOWindowsApplication (Form.h) Desciption: This is a simpe Windows application as a demonstration to show how to build up a simple Windows application and link to the GPIO functions in the Nano River Techologies MiniBoard. Revision: Version 1.0 #pragma once #include "../../common/miniboard_class.h" The file declares some global variables used in the application: Own Global variables here NANO_RESULT res; Returned result for calls to Nano River Tech functions MBc MB; The MiniBoard class library Int32 slider; Slider value Int32 bit; GPIO Bit number BOOL value; Read value of the GPIO bit bool connected; True if the MiniBoard is connected Rev: 1.4 (Apr 2009) Nano River Technolgies Page 8 of 67

Windows objects are defined: Define all the Windows objects here private: System::Windows::Forms::TrackBar^ trackbar_0; private: System::Windows::Forms::TrackBar^ trackbar_1; private: System::Windows::Forms::TrackBar^ trackbar_30; A function is defined during the form load. In this the connection to the MiniBoard is established by calling OpenDevice()in the MiniBoard class. Functions Nano_GPIOSetDirection and Nano_GPIOWrite are called to initialise all GPIOs as inputs. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { A task called when the form is loaded. Here we open the USB link and initialise the MiniBoard. All GPIOs are initialised to all input. connected = ::MBc::OpenDevice(); if (!connected) this->label_50->visible = true; if (connected) { res = ::MBc::Nano_GPIOSetDirection(MB.mb_hDevice,0x00000000,0xFFFFFFFF); res = ::MBc::Nano_GPIOWrite(MB.mb_hDevice,0x00000000,0xFFFFFFFF); All inputs Values 0x0 Finally, a timer service routine is defined. Each time the timer ticks the control slider is checked to see if the GPIO needs to be updated as an output or if it needs to change to an input. In addition the GPIO is read and displayed. The process is repeated for all GPIOs. private: System::Void timer1_tick(system::object^ sender, System::EventArgs^ e) { Task to update all GPIOs each clock tick Bit 00 bit = 0; slider = this->trackbar_0->value; if (slider==0) res = ::MBc::Nano_GPIOSetSingleBitDirection(MB.mb_hDevice,bit,0); Input else if (slider==1) { res = ::MBc::Nano_GPIOSingleBitWrite(MB.mb_hDevice,bit,0); 0 res = ::MBc::Nano_GPIOSetSingleBitDirection(MB.mb_hDevice,bit,1); Output else if (slider==2) { res = ::MBc::Nano_GPIOSingleBitWrite(MB.mb_hDevice,bit,1); 1 res = ::MBc::Nano_GPIOSetSingleBitDirection(MB.mb_hDevice,bit,1); Output res = ::MBc::Nano_GPIOSingleBitRead(MB.mb_hDevice,bit,&value); this->textbox_0->text = Convert::ToString(value); Rev: 1.4 (Apr 2009) Nano River Technolgies Page 9 of 67

Some important links and includes are necessary in stdafx.h. This is best seen by viewing the file in the download from the web-site. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 10 of 67

3. IIC Command Tool This example application is a C/C++ console application showing how to call functions associated with the IIC such as IIC read, IIC write, IIC scan and various configuration commands. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 11 of 67

3.1. Functionality The application works by prompting the user for a new command. There are three main types of commands that are accepted. IIC Scan Command %cmd> s Here the program will scan all IIC addresses and report which devices are connected to the bus. IIC Write Command %cmd> w devid <Device ID> -sa <Start Address> -l <Length> -d <Data Sequence> Here the user specifies the device ID, internal start address, transfer length and the data sequence. An IIC write transaction is then initiated. IIC Read Command %cmd> r devid <Device ID> -sa <Start Address> -l <Length> Here the user specifies the device ID, internal start address and transfer length. An IIC read transaction is then initiated and returns the read data. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 12 of 67

3.2. Project Structure In order to create such a console application in Visual C++, first start up a new project and select Win32 Console Application as the project type. This will create a standard console application. The project file structure will then look as follows. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 13 of 67

To this, one must add the MiniBoard class header file (miniboard_class.h), the MiniBoard class C++ file (miniboard_class.cpp) and the libusb library (libusb.lib) as follows. MiniBoard Class Header File Main Program (Top) MiniBoard Class C++ File LibUSB library Rev: 1.4 (Apr 2009) Nano River Technolgies Page 14 of 67

3.3. Design Description The application is implemented using a single file (IICCommandToolApplication.cpp). The complete file and project can be downloaded from the web-site. The file starts by linking to the MiniBoard class library header file and the standard project header file: Nano River Technologies File: IICCommandToolApplication (IICCommandToolApplication.cpp) Desciption: This is a console application as a demonstration showing how to build up a simple application linking to the IIC functions for the Nano River Techologies MiniBoard. Revision: Version 1.0 #include "stdafx.h" #include "../../common/miniboard_class.h" using namespace std; The file declares some global variables used in the application: Global Variables BOOL d; Return result for opening the connection to MiniBoard NANO_RESULT e; Return result for all IIC commands for MiniBoard MBc MB; The MiniBoard class library BYTE InBuffer[256]; A buffer for receiving data from the IIC device BYTE OutBuffer[256]; A buffer for sending data to the IIC device DEV_LIST lst; Returned list of connected IIC devices char s[250]; Variable used to take the users input as a sting enum commandtype { NONE, READ, WRITE, SCAN, HELP ; The type of command commandtype command; The actual command long int deviceid = 0; The IIC Device ID long int startaddress = 0; The IIC start address long int length = 0; The IIC transfer length long int data[256]; An array storing the data to send int count = 0; Index into the data array int i; A variable used in scanning all possible IIC Device IDs bool datafound; True when the user has included data in the command Rev: 1.4 (Apr 2009) Nano River Technolgies Page 15 of 67

A help procedure is included to give the user instructions as to the correct syntax for commands: void help() Prints out a help banner to show the possible commands and formats etc. { printf ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf ("+ Enter a command in the following format:\n"); printf ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf ("+ IIC Device Scan... \n"); printf ("+ $cmd> s\n"); printf ("+ IIC Read... \n"); printf ("+ $cmd> r -devid <Device ID> -sa <Start Addr> -l <Length>\n"); printf ("+ Eg. $cmd> r -devid 50 -sa 00 -l 02\n"); printf ("+ IIC Write... \n"); printf ("+ $cmd> w -devid <Device ID> -sa <Start Addr> -l <Length> -d <Data Seq>\n"); printf ("+ Eg. $cmd> w -devid 50 -sa 00 -l 0A -d 12 34 55 3A 4F FF 00 55 EF 11\n"); printf ("+ Help... \n"); printf ("+ $cmd> h\n"); printf ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); The main program starts by printing out a startup banner and calling the user instructions: int _tmain(int argc, _TCHAR* argv[]) { The Tool header printf ("+++++++++++++++++++++++++++++++++++++++\n"); printf ("+++++++++++++++++++++++++++++++++++++++\n"); printf ("++ ++\n"); printf ("++ IIC Command Line Tool ++\n"); printf ("++ ++\n"); printf ("++ by Nano River Technologies ++\n"); printf ("++ support@nanorivertech.com ++\n"); printf ("++ ++\n"); printf ("+++++++++++++++++++++++++++++++++++++++\n"); printf ("+++++++++++++++++++++++++++++++++++++++\n\n\n"); help(); Rev: 1.4 (Apr 2009) Nano River Technolgies Page 16 of 67

The I2C interface is then initialised by calling the OpenDevice() in the MiniBoard class. Functions are then called to setup the I2C line rate. Initialise the Nano River Tech Board connected=mb.opendevice(); Open the MiniBoard if (!connected) { printf ("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf ("++ DEMONSTRATION MODE ONLY!\n"); printf ("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); if (connected) { e=mb.nano_iicsetfrequency(mb.mb_hdevice,nano_iic_freq_fast); Set the IIC frequency A main loop is included to prompt for user input: Main loop to take users commands while (1) { Prompt and get user input printf("\n"); printf ("$cmd> "); command = NONE; datafound = false; count = 0; gets(s); The remainder of the main loop and program then calls I2C functions based on the user s request. These are primarily I2C scan, I2C read and I2C write functions. The input needs to be parsed. The request along with the returned data is summarised and presented to the user on the screen. Now process the command char * pch; This is a variable used to store the next peice of the command Each peice is separated by spaces. char * last = ""; This is the last peice pch = strtok (s," "); Get the first peice of the command while (pch!= NULL) { if (strcmp( pch, "r" )==0) If a read is found command = READ; if (strcmp( pch, "w" )==0) If a write is found command = WRITE; if (strcmp( pch, "s" )==0) If an IIC scan is requested command = SCAN; if (strcmp( pch, "h" )==0) If a help is requested command = HELP; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 17 of 67

if (strcmp( last, "-devid" )==0) { Check for DEVID flag as the last peice deviceid = strtol(pch,null,16); Store the DEVID datafound=false; if (strcmp( last, "-sa" )==0) { Check for start address flag as the last peice startaddress = strtol(pch,null,16); Store the start address datafound=false; if (strcmp( last, "-l" )==0) { Check for the length flag as the last peice length = strtol(pch,null,16); Store the length datafound=false; if (datafound) { Check if we are accepting data data[count] = strtol(pch,null,16); Store the data count++; Increment data index if (strcmp( pch, "-d" )==0) Flag that we are taking data datafound = true; last = pch; pch = strtok (NULL, " "); Get next peice of the string Zero un-spcified data for (i=count; i<length; i++) data[i] = 0; Act on the required IIC command switch ( command ) { No command case NONE : printf("\n"); printf("incorrect command type!\n\n"); help(); break; Help command case HELP : help(); break; Read command case READ : printf("\n"); printf(" Read...\n"); if (connected) e=mb.nano_iicread(mb.mb_hdevice,byte(deviceid),2,word(startaddress), WORD(length),InBuffer); The Nano River Tech IIC Read command if (e==nano_success) { printf(" Device ID : %02X\n",deviceID); printf(" Start Address : %04X\n",startAddress); printf(" Length : %04X\n",length); printf(" Data :"); for (i=0; i<length; i++) { printf(" %02X",InBuffer[i]); if (((i+1)%16)==0) printf("\n "); printf("\n"); printf(" Successfull Read!\n"); Display the data Rev: 1.4 (Apr 2009) Nano River Technolgies Page 18 of 67

else { printf("\n"); printf(" Error on Read!\n"); break; Write command case WRITE: printf("\n"); printf(" Write...\n"); printf(" Device ID : %02X\n",deviceID); printf(" Start Address : %04X\n",startAddress); printf(" Length : %04X\n",length); printf(" Data :"); for (i=0; i<length; i++) { OutBuffer[i] = BYTE(data[i]); printf(" %02X",data[i]); if (((i+1)%16)==0) printf("\n "); if (connected) Prepare the data e=mb.nano_iicwrite(mb.mb_hdevice,byte(deviceid),2,word(startaddress), WORD(length),OutBuffer); The Nano River Tech IIC Write command printf("\n"); if (e==nano_success) printf(" Successfull Write!\n"); else printf(" Error on Write!\n"); break; Scan command case SCAN : printf("\n"); printf(" Scan...\n\n"); if (connected) e=mb.nano_iicscanconnecteddevices(mb.mb_hdevice,&lst); The Nano River Tech IIC Scan command printf(" IIC Devices Connected... "); for (i=0;i<128;i++) { if (lst.list[i]) {printf("%02x ",i); printf("\n"); break; return 0; Some important links and includes are necessary in stdafx.h. This is best seen by viewing the file in the download from the web-site. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 19 of 67

4. Windows IIC Tool This example application is a windows GUI application in Visual C++ used to illustrate how to access I2C functions. Scan Button Read Button Write Button Information Window Rev: 1.4 (Apr 2009) Nano River Technolgies Page 20 of 67

4.1. Functionality In this application the user can request one of three types of IIC accesses. IIC Scan In this case the user need only press the Scan Button. The list of connected devices is then returned in the information window. IIC Read For a read, the user needs to enter the device ID, start address for the transfer and the transfer length. When the user presses the Read Button an IIC read transfer is initiated. A summary of the transfer is sent to the information window, including the returned data from the device. IIC Write For a write, the user needs to enter the device ID, start address for the transfer, transfer length and the data sequence to be transferred. When the user presses the Write Button the IIC write transfer is made and a summary of the transfer is sent to the information window. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 21 of 67

4.2. Project Structure In order to create such a Windows application in Visual C++, first start up a new project and select Window Form Application as the project type. This will create a standard Windows application. The project file structure will then look as follows. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 22 of 67

To this, one must add the MiniBoard class header file (miniboard_class.h) and MiniBoard class C++ file as follows. Windows Form Description MiniBoard Class Header File Application Top Level C++ File MiniBoard Class C++ File Remember to change the Common Language Runtime support to /clr. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 23 of 67

4.3. Design Description The main file which needs to be developed in a Windows GUI application is the Windows form application file (Form1.h). This can be built up graphically by dragging in elements of the.net development toolbox and/or by editing the Form1.h text file. The final Form1.h file can be found in the downloaded files for the IIC Windows application available on the web-site. The file starts by linking to the MiniBoard class library header file: Nano River Technologies File: IICWindowsApplication (Form.h) Desciption: This is a simpe Windows application as a demonstration to show how to build up a simple Windows application and link to the IIC functions in the Nano River Techologies MiniBoard. Revision: Version 1.0 #pragma once #include "../../common/miniboard_class.h" The file declares some global variables used in the application: Own Global variables here NANO_RESULT res; Returned result for calls to Nano River Tech functions DEV_LIST lst; Returned list of connected IIC devices Int32 i; General purpose loop variable BYTE SlaveAddress; The IIC slave address WORD StartAddress; The start address for the particular device WORD BufferLength; Length of the IIC transfer BYTE InBuffer[256]; A buffer for receiving data from the IIC device BYTE OutBuffer[256]; A buffer for sending data to the IIC device MBc MB; The MiniBoard class library bool connected; True if the MiniBoard is connected Rev: 1.4 (Apr 2009) Nano River Technolgies Page 24 of 67

Windows objects are defined: Define all the Windows objects here private: System::Windows::Forms::Label^ label_1; private: System::Windows::Forms::Label^ label_2; private: System::Windows::Forms::Label^ label_3; private: System::Windows::Forms::Button^ button_1; private: System::Windows::Forms::Button^ button_2; private: System::Windows::Forms::Button^ button_3; private: System::Windows::Forms::TextBox^ textbox_1; private: System::Windows::Forms::TextBox^ textbox_2; private: System::Windows::Forms::TextBox^ textbox_3; private: System::Windows::Forms::TextBox^ textbox_4; private: System::Windows::Forms::RichTextBox^ richtextbox_1; We then define some managed variables: Managed variables String ^s1; A local string variable used for RichTechBox output String ^s2; 2nd local string variable used for RichTechBox output String ^s3; 3rd local string variable used for RichTechBox output String ^Data; A string used for parsing the data input textbox A function is defined during the form load. In this the connection to the MiniBoard is established by calling OpenDevice() in the MiniBoard class. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { A task called when the form is loaded. Here we just open the USB link and initialise the MiniBoard. connected = ::MBc::OpenDevice(); if (!connected) this->label_0->visible = true; for (i=0;i<128;i++) lst.list[i] = false; lst.list[0x50] = true; For the demo we show 0x50 as connected Rev: 1.4 (Apr 2009) Nano River Technolgies Page 25 of 67

A function is defined for when the user presses the Scan Button. When this occurs, the scan function is called from the MiniBoard class. The function returns a list containing the I2C addresses of connected devices. The function displays the result in the information window. private: System::Void button_1_click(system::object^ sender, System::EventArgs^ e) { This is the task called when we press the button for scanning. Here we just call the IIC scan task and display the result. s1= "Scanning...\n"; s2= " Device\(s\) found:"; s3= " No Device Connected"; bool found; found = false; if (connected) res = ::MBc::Nano_IICScanConnectedDevices(MB.mb_hDevice,&lst); Call the IIC scan task here for (i=0;i<128;i++) { if (lst.list[i]) { found=true; s2 = System::String::Concat( s2," 0x"); s2 = System::String::Concat( s2,i.tostring("x2")); if (found) { s1 = System::String::Concat( s1,s2); else { s1 = System::String::Concat( s1,s3); this->richtextbox_1->text = s1; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 26 of 67

A function is defined for when the user presses the Read Button. When this occurs, the device ID, start address and transfer length are taken from the content of the corresponding textboxes. A call is made to the I2C read function from the MiniBoard class. The function returns a buffer of data. A summary of the transfer is presented to the user including the read data in the information window. private: System::Void button_2_click(system::object^ sender, System::EventArgs^ e) { This is a function called when we press the IIC read button. The function calls the IIC read task for the MiniBoard and displays the result. Parameters are taken from the other TextBoxes. if (connected) { res = ::MBc::Nano_IICSetFrequency(MB.mb_hDevice,NANO_IIC_FREQ_FAST); Setup the clock speed SlaveAddress = Int32::Parse(this->textBox_1-> Text,System::Globalization::NumberStyles::HexNumber); Get slave address from TextBox StartAddress = Int32::Parse(this->textBox_3-> Text,System::Globalization::NumberStyles::HexNumber); Get start address from TextBox BufferLength = Int32::Parse(this->textBox_5-> Text,System::Globalization::NumberStyles::HexNumber); Get buffer length from TextBox bool error; error = false; s1= "Reading"; s2= " "; s3= " Error on read"; s1 = System::String::Concat( s1," (Device ID 0x"); s1 = System::String::Concat( s1,slaveaddress.tostring("x2")); s1 = System::String::Concat( s1,") (Start Addr 0x"); s1 = System::String::Concat( s1,startaddress.tostring("x4")); s1 = System::String::Concat( s1,")...\n\n"); if (connected) res = ::MBc::Nano_IICRead(MB.mb_hDevice,SlaveAddress,2,StartAddress, BufferLength,InBuffer); Call the IIC read task here if (res!=nano_success) error = true; for (i=0;i<bufferlength;i++) { Print the resultant buffer s2 = System::String::Concat( s2," 0x"); s2 = System::String::Concat( s2,inbuffer[i].tostring("x2")); if (((i+1)%16)==0) s2 = System::String::Concat( s2,"\n "); if (error) { s1 = System::String::Concat( s1,s3); else { s1 = System::String::Concat( s1,s2); this->richtextbox_1->text = s1; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 27 of 67

A function is defined for when the user presses the Write Button. When this occurs, the device ID, start address, transfer length and data sequence are taken from the content of the corresponding textboxes. A call is made to the I2C write function from the MiniBoard class. When the transfer is complete a summary of the transfer is presented to the user in the information window. If the transfer length exceeds the data sequence entered then 0x00 is written. private: System::Void button_3_click(system::object^ sender, System::EventArgs^ e) { This is a function called when we press the IIC write button. The function calls the IIC write task for the MiniBoard and displays the result. Parameters are taken from the other TextBoxes. if (connected) { res = ::MBc::Nano_IICSetFrequency(MB.mb_hDevice,NANO_IIC_FREQ_FAST); Setup the clock speed SlaveAddress = Int32::Parse(this->textBox_2-> Text,System::Globalization::NumberStyles::HexNumber); Get slave address from TextBox StartAddress = Int32::Parse(this->textBox_4-> Text,System::Globalization::NumberStyles::HexNumber); Get start address from TextBox BufferLength = Int32::Parse(this->textBox_6-> Text,System::Globalization::NumberStyles::HexNumber); Get buffer length from TextBox Data = this->textbox_7->text; array<string^>^ splitdata = Data->Split(' '); Do string splitting to get the individual data entries. Expect a space between bool error; error = false; s1= "Writing"; s2= " "; s3= " Error on write"; s1 = System::String::Concat( s1," (Device ID 0x"); s1 = System::String::Concat( s1,slaveaddress.tostring("x2")); s1 = System::String::Concat( s1,") (Start Addr 0x"); s1 = System::String::Concat( s1,startaddress.tostring("x4")); s1 = System::String::Concat( s1,")...\n\n"); for (i=0; i<256; i++) { OutBuffer[i]=0; Default data is 0 unless specified for (i=0; i<splitdata->length; i++) if (i<bufferlength) Fill output buffer with data OutBuffer[i]=Convert::ToInt32(splitData[i],16); for (i=0;i<bufferlength;i++) { Print Buffer s2 = System::String::Concat( s2," 0x"); s2 = System::String::Concat( s2,outbuffer[i].tostring("x2")); if (((i+1)%16)==0) s2 = System::String::Concat( s2,"\n "); if (connected) res = ::MBc::Nano_IICWrite(MB.mb_hDevice,SlaveAddress,2,StartAddress, BufferLength,OutBuffer); Call the IIC write task here if (res!=nano_success) error = true; if (error) { s1 = System::String::Concat( s1,s3); else { s1 = System::String::Concat( s1,s2); this->richtextbox_1->text = s1; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 28 of 67

Some important links and includes are necessary in stdafx.h. This is best seen by viewing the file in the download from the web-site. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 29 of 67

5. Windows EEPROM Programmer This example application example is a simple programmer for either I2C or SPI EEPROMs. The application is intended as a slightly more complex example of how to interface to both I2C and SPI interfaces in a real-life example. I2C/SPI select I2C Configuration SPI Configuration File IO Image editing Image Window Information Window Rev: 1.4 (Apr 2009) Nano River Technolgies Page 30 of 67

5.1. Functionality To use this application the user needs to select between I2C and SPI style EEPROMs. This is achieved by using the I2C/SPI pull-down menu. For I2C EEPROMs, the user must then continue to configure the chip size, page size, device ID, clock speed and write time by the various pull-down menus and text boxes in the I2C configuration. Similarly for SPI EEPROMs, the user needs to configure the chip size, page size, clock rate, clock polarity, clock phase and write time from the SPI configuration. The current image in the programmer memory is displayed in the image window. One can scroll through this image to see all locations. To read from file one should specify the file name and press the Read File button. To save an image to file one should specify the file name and press the Write File button. To edit a single location of the programmer image then specify the address and new data then press the Update button in the image editing. For random image import or to have 0xFF in all locations then press the Random Fill or FF Fill buttons. When the image is ready for programming one should press the Program button. The programming should immediately be checked by pressing the Verify button. An image can be read into the programmer s memory from chip using the Read button. Success or otherwise of any of the operations is displayed in the information window. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 31 of 67

5.2. Project Structure In order to create such a Windows application in Visual C++, first start up a new project and select Window Form Application as the project type. This will create a standard Windows application. The project file structure will then look as follows. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 32 of 67

To this, one must add the MiniBoard class header file (miniboard_class.h) and MiniBoard class C++ file as follows. Windows Form Description MiniBoard Class Header File Application Top Level C++ File MiniBoard Class C++ File Remember to change the Common Language Runtime support to /clr. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 33 of 67

5.3. Design Description The main file which needs to be developed in a Windows GUI application is the Windows form application file (Form1.h). This can be built up graphically by dragging in elements of the.net development toolbox and/or by editing the Form1.h text file. The final Form1.h file can be found in the downloaded files for the EEPROM Programmer application available on the web-site. The file starts by linking to the MiniBoard class library header file: Nano River Technologies File: EEPROMProgrammerApplication (Form.h) Desciption: This is a simple EEPROM programmer working for IIC or SPI style EEPROMs. The programmer is made as an example of how to build a Windows style application using IIC and SPI commands and the Nano River Technologies MiniBoard. Revision: Version 1.0 #pragma once #include "../../common/miniboard_class.h" The file declares some global variables used in the application: Own Global variables here const Int32 MEMORYMAX = 65536; Maximum size of the memory array Int32 no_screens; Number of screens of data to be displayed Int32 chip_size; The actual chip size Int32 page_size; The actial chip page size Int32 page_no; Page number Int32 iic_write_time; Chip write time (for IIC devices) Int32 spi_write_time; Chip write time (for SPI devices) NANO_RESULT res; Returned result for calls to Nano River Tech functions Int32 i,j; Loop variables BYTE SlaveAddress; IIC slave address (Device ID) WORD StartAddress; IIC transaction start address WORD BufferLength; IIC buffer length BYTE iic_frequency; IIC serial bit rate BYTE InBuffer[256]; IIC input buffer (data from IIC device) BYTE OutBuffer[256]; IIC output buffer (data for IIC device) Rev: 1.4 (Apr 2009) Nano River Technolgies Page 34 of 67

BYTE spi_frequency; SPI serial clock rate BYTE spi_polarity; SPI polarity setting BYTE spi_phase; SPI phase setting BYTE in_buffer[256]; SPI input buffer (data from SPI device) BYTE out_buffer[256]; SPI output buffer (data for SPI device) BYTE memory[memorymax]; Storage to hold data to be programmed BYTE verify_memory[memorymax]; Storage to hold data that was read MBc MB; The MiniBoard class library bool connected; True if the MiniBoard is connected Windows objects are defined: private: System::Windows::Forms::Label^ label_000; private: System::Windows::Forms::Label^ label_001; private: System::Windows::Forms::Label^ label_002; private: System::Windows::Forms::ComboBox^ combobox_000; private: System::Windows::Forms::ComboBox^ combobox_001; private: System::Windows::Forms::ComboBox^ combobox_002; private: System::Windows::Forms::TextBox^ textbox_000; private: System::Windows::Forms::TextBox^ textbox_001; private: System::Windows::Forms::TextBox^ textbox_002; private: System::Windows::Forms::Button^ button_000; private: System::Windows::Forms::Button^ button_001; private: System::Windows::Forms::Button^ button_002; private: System::Windows::Forms::RichTextBox^ richtextbox_000; private: System::Windows::Forms::RichTextBox^ richtextbox_001; private: System::Windows::Forms::RichTextBox^ richtextbox_002; private: System::Windows::Forms::VScrollBar^ vscrollbar_000; Some managed variables are then declared: Managed variables String ^s1; A local string variable used for RichTechBox output String ^s2; 2nd local string variable used for RichTechBox output String ^s3; 3rd local string variable used for RichTechBox output String ^Data; A string used for parsing the data input textbox Rev: 1.4 (Apr 2009) Nano River Technolgies Page 35 of 67

A function is defined to display the current programmer contents. This is displayed in the image window. The EEPROM image is broken into screens and displayed one screen at a time. The scroll bar changes to the next screen of image. private: System::Void ScreenUpdate() { A function to display the current screen of EEPROM data. Manages to show only the current screen based on the virtical slider. Int32 i,j; j = this->vscrollbar_000->value; s2=""; s2 = System::String::Concat( s2,j.tostring("x6")); this->richtextbox_001->text = s2; s2 = ""; for (i=0; i<256; i++) { if ((i%16)==0) { s2= System::String::Concat( s2," "); s2 = System::String::Concat( s2,(256*j+i).tostring("x7")); s2= System::String::Concat( s2," "); s2 = System::String::Concat( s2," "); s2 = System::String::Concat( s2,memory[256*j+i].tostring("x2")); if (((i+1)%16)==0) { s2= System::String::Concat( s2,"\n"); this->vscrollbar_000->maximum = no_screens+8; this->richtextbox_001->text = s2; A function is defined during the form load. In this connection to the MiniBoard is established by calling the OpenDevice() in the MiniBoard class. The function also initialises the programmer contents and also the global variables. Finally a call is made to display the first screen of the image. private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { A task called when the form is loaded. Here we open the USB link and initialise the MiniBoard. Also initialise all the global varaibles. connected = ::MBc::OpenDevice(); Open the device if (!connected) this->label_300->visible = true; for (i=0; i<memorymax; i++) memory[i] = rand()&0xff; Randomise the image no_screens = 64; Default values are set below... page_size = 64; page_no = 0; chip_size = no_screens * 256; iic_frequency=nano_iic_freq_fast; spi_frequency=nano_spi_freq_400khz; iic_write_time = 5; spi_write_time = 5; ScreenUpdate(); Screen update Rev: 1.4 (Apr 2009) Nano River Technolgies Page 36 of 67

This function updates the image window when the user clicks on the vertical scroll bar. private: System::Void vscrollbar_000_scroll(system::object^ sender, System::Windows::Forms::ScrollEventArgs^ e) { On a virtical slider movement update the screen ScreenUpdate(); These two functions re-calculate chip size and number of screens to display of the image in the case there has been an update to the chip size pull-down menu. One function is provided for I2C and one for the SPI case. private: System::Void combobox_001_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the chip size when IIC EEPROM is selected if (this->combobox_000->text=="iic") { page_no = 0; if (this->combobox_001->text=="512kbit") no_screens = 256; if (this->combobox_001->text=="256kbit") no_screens = 128; if (this->combobox_001->text=="128kbit") no_screens = 64; if (this->combobox_001->text=="64kbit") no_screens = 32; if (this->combobox_001->text=="32kbit") no_screens = 16; if (this->combobox_001->text=="16kbit") no_screens = 8; if (this->combobox_001->text=="8kbit") no_screens = 4; if (this->combobox_001->text=="4kbit") no_screens = 2; if (this->combobox_001->text=="2kbit") no_screens = 1; this->vscrollbar_000->value=0; chip_size = no_screens * 256; private: System::Void combobox_005_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the chip size when SPI EEPROM is selected if (this->combobox_000->text=="spi") { page_no = 0; if (this->combobox_005->text=="512kbit") no_screens = 256; if (this->combobox_005->text=="256kbit") no_screens = 128; if (this->combobox_005->text=="128kbit") no_screens = 64; if (this->combobox_005->text=="64kbit") no_screens = 32; if (this->combobox_005->text=="32kbit") no_screens = 16; if (this->combobox_005->text=="16kbit") no_screens = 8; if (this->combobox_005->text=="8kbit") no_screens = 4; if (this->combobox_005->text=="4kbit") no_screens = 2; if (this->combobox_005->text=="2kbit") no_screens = 1; this->vscrollbar_000->value=0; chip_size = no_screens * 256; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 37 of 67

These two functions re-calculate page size in the case there has been an update to the page size pull-down menu. One function is provided for I2C and one for the SPI case. private: System::Void combobox_002_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the page size variable when IIC is selected if (this->combobox_000->text=="iic") { if (this->combobox_002->text=="4byte") page_size = 4; if (this->combobox_002->text=="8byte") page_size = 8; if (this->combobox_002->text=="16byte") page_size = 16; if (this->combobox_002->text=="32byte") page_size = 32; if (this->combobox_002->text=="64byte") page_size = 64; if (this->combobox_002->text=="128byte") page_size = 128; if (this->combobox_002->text=="256kbit") page_size = 256; private: System::Void combobox_006_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the page size variable when SPI is selected if (this->combobox_000->text=="spi") { if (this->combobox_006->text=="4byte") page_size = 4; if (this->combobox_006->text=="8byte") page_size = 8; if (this->combobox_006->text=="16byte") page_size = 16; if (this->combobox_006->text=="32byte") page_size = 32; if (this->combobox_006->text=="64byte") page_size = 64; if (this->combobox_006->text=="128byte") page_size = 128; if (this->combobox_006->text=="256kbit") page_size = 256; These two functions re-calculate clock frequency in the case there has been an update to the clock frequency pull-down menu. One function is provided for I2C and one for the SPI case. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 38 of 67

private: System::Void combobox_003_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the clock frequency for IIC EEPROMs if (this->combobox_000->text=="iic") { if (this->combobox_003->text=="10khz") iic_frequency=nano_iic_freq_10khz; if (this->combobox_003->text=="20khz") iic_frequency=nano_iic_freq_20khz; if (this->combobox_003->text=="40khz") iic_frequency=nano_iic_freq_40khz; if (this->combobox_003->text=="60khz") iic_frequency=nano_iic_freq_60khz; if (this->combobox_003->text=="80khz") iic_frequency=nano_iic_freq_80khz; if (this->combobox_003->text=="std") iic_frequency=nano_iic_freq_std; if (this->combobox_003->text=="200khz") iic_frequency=nano_iic_freq_200khz; if (this->combobox_003->text=="fast") iic_frequency=nano_iic_freq_fast; private: System::Void combobox_007_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the clock frequency for SPI EEPROMs if (this->combobox_000->text=="spi") { if (this->combobox_007->text=="10khz") spi_frequency=nano_spi_freq_10khz; if (this->combobox_007->text=="20khz") spi_frequency=nano_spi_freq_20khz; if (this->combobox_007->text=="40khz") spi_frequency=nano_spi_freq_40khz; if (this->combobox_007->text=="60khz") spi_frequency=nano_spi_freq_60khz; if (this->combobox_007->text=="80khz") spi_frequency=nano_spi_freq_80khz; if (this->combobox_007->text=="100khz") spi_frequency=nano_spi_freq_100khz; if (this->combobox_007->text=="200khz") spi_frequency=nano_spi_freq_200khz; if (this->combobox_007->text=="400khz") spi_frequency=nano_spi_freq_400khz; These two functions re-calculate chip write time in the case there has been an update to the write time pull-down menu. One function is provided for I2C and one for the SPI case. private: System::Void combobox_004_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the chip write time for IIC EEPROMs if (this->combobox_000->text=="iic") { if (this->combobox_004->text=="5ms") iic_write_time=5; if (this->combobox_004->text=="10ms") iic_write_time=10; if (this->combobox_004->text=="15ms") iic_write_time=15; if (this->combobox_004->text=="20ms") iic_write_time=20; if (this->combobox_004->text=="50ms") iic_write_time=50; private: System::Void combobox_010_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the chip write time for SPI EEPROMs if (this->combobox_000->text=="iic") { if (this->combobox_010->text=="5ms") spi_write_time=5; if (this->combobox_010->text=="10ms") spi_write_time=10; if (this->combobox_010->text=="15ms") spi_write_time=15; if (this->combobox_010->text=="20ms") spi_write_time=20; if (this->combobox_010->text=="50ms") spi_write_time=50; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 39 of 67

These two functions re-calculate the SPI clock polarity and phase in the case there was a change to the polarity or phase pull-down menu respectively. private: System::Void combobox_008_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the polarity setting for SPI EEPROMs if (this->combobox_000->text=="spi") { if (this->combobox_008->text=="0") spi_polarity=0; if (this->combobox_008->text=="1") spi_polarity=1; private: System::Void combobox_009_selectedindexchanged(system::object^ sender, System::EventArgs^ e) { Update the phase setting for SPI EEPROMs if (this->combobox_000->text=="spi") { if (this->combobox_009->text=="0") spi_phase=0; if (this->combobox_009->text=="1") spi_phase=1; This function is provided for when there is a click on the Update button. In this case the address and new data is used to update one locate in the programmer memory. A screen update is made to make sure the user sees this too. private: System::Void button_002_click(system::object^ sender, System::EventArgs^ e) { This function is for the Update button click detection. When the button is clicked then the corresponding memory location is updated. Int32 updateaddress; Int32 updatedata; updateaddress = 0xFFFFFF & Int32::Parse(this-> textbox_003->text,system::globalization::numberstyles::hexnumber); updatedata = 0xFF & Int32::Parse(this-> textbox_004->text,system::globalization::numberstyles::hexnumber); memory[updateaddress] = updatedata; ScreenUpdate(); s2="updated location "; s2 = System::String::Concat( s2,updateaddress.tostring("x4")); s2 = System::String::Concat( s2," with "); s2 = System::String::Concat( s2,updatedata.tostring("x2")); s2 = System::String::Concat( s2,"."); this->richtextbox_002->text = s2; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 40 of 67

This function is provided for writing the image to the physical device. The function handles both I2C and SPI EEPROM types. The write time delay is allowed for between pages. private: System::Void button_003_click(system::object^ sender, System::EventArgs^ e) { Inplements the click activity for the WRITE button. Implements both IIC and SPI behaviour. bool error; error = false; if (this->combobox_000->text=="iic") { IIC CASE if (connected) { res = ::MBc::Nano_IICSetFrequency(MB.mb_hDevice,iic_frequency); SlaveAddress = Int32::Parse(this->textBox_000-> Text,System::Globalization::NumberStyles::HexNumber); Get Device ID StartAddress = 0x00; BufferLength = page_size; Set page size Get frequency for (j=0; j<(chip_size/page_size); j++) { Loop page at a time for (i=0; i<bufferlength; i++) { OutBuffer[i]=memory[i+j*page_size]; if (connected) res = ::MBc::Nano_IICWrite(MB.mb_hDevice,SlaveAddress,2,StartAddress,BufferLength, OutBuffer); IIC Write command if (res!=nano_success) error = true; Sleep(iic_write_time); Delay to allow for the chip write time StartAddress = StartAddress + page_size; if (error==true) s2="error during IIC write"; else s2="device IIC write"; this->richtextbox_002->text = s2; if (this->combobox_000->text=="spi") { SPI CASE if (connected) { res=::mbc::nano_spisetclockconfig(mb.mb_hdevice,spi_polarity,spi_phase); Set the SPI polarity/phase res=::mbc::nano_spisetfrequency(mb.mb_hdevice,spi_frequency); Set SPI frequency for (j=0; j<(chip_size/page_size); j++) { Loop page at a time Write Enable out_buffer[0] = 0x06; Opcode res=::mbc::nano_spireadwrite(mb.mb_hdevice, 0x01, in_buffer, out_buffer, 0x01); if (res!=nano_success) error = true; Sleep(1); Delay to make sure the write enable occurs Write out_buffer[0] = 0x02; Opcode for a WRITE out_buffer[1] = 0xFF & ((j*page_size)>>8); MSB Address out_buffer[2] = 0xFF & (j*page_size); LSB Address for (i=0; i<page_size; i++) out_buffer[i+3] = memory[i+j*page_size]; if (connected) res=::mbc::nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, page_size+3); if (res!=nano_success) error = true; Sleep(spi_write_time); if (error==true) s2="error during SPI write"; else s2="device SPI write"; this->richtextbox_002->text = s2; Delay to allow for the chip write time Rev: 1.4 (Apr 2009) Nano River Technolgies Page 41 of 67

This function is provided for reading the physical device into the programmer image. private: System::Void button_005_click(system::object^ sender, System::EventArgs^ e) { Inplements the click activity for the READ button. Implements both IIC and SPI behaviour. bool error; error = false; if (this->combobox_000->text=="iic") { IIC CASE if (connected) { res = ::MBc::Nano_IICSetFrequency(MB.mb_hDevice,iic_frequency); Set frequency SlaveAddress = Int32::Parse(this-> textbox_000->text,system::globalization::numberstyles::hexnumber); Get Device ID StartAddress = 0x00; BufferLength = page_size; Set page size for (j=0; j<(chip_size/page_size); j++) { if (connected) res = ::MBc::Nano_IICRead(MB.mb_hDevice,SlaveAddress,2,StartAddress, BufferLength,InBuffer); IIC Read if (res!=nano_success) error = true; for (i=0; i<bufferlength; i++) memory[i+j*page_size] = InBuffer[i]; StartAddress = StartAddress + page_size; if (error==true) s2="error during IIC read"; else s2="device IIC read"; this->richtextbox_002->text = s2; ScreenUpdate(); Update the screen if (this->combobox_000->text=="spi") { SPI CASE if (connected) { res=::mbc::nano_spisetclockconfig(mb.mb_hdevice,spi_polarity,spi_phase); Set the SPI polarity/phase res=::mbc::nano_spisetfrequency(mb.mb_hdevice,spi_frequency); Set the SPI frequency for (j=0; j<(chip_size/page_size); j++) { out_buffer[0] = 0x03; Opcode for a READ out_buffer[1] = 0xFF & ((j*page_size)>>8); MSB Address out_buffer[2] = 0xFF & (j*page_size); LSB Address if (connected) res=::mbc::nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, page_size+3); if (res!=nano_success) error = true; for (i=0; i<page_size; i++) memory[i+j*page_size] = in_buffer[i+3]; if (error==true) s2="error during SPI read"; else s2="device SPI read"; this->richtextbox_002->text = s2; ScreenUpdate(); SPI read Rev: 1.4 (Apr 2009) Nano River Technolgies Page 42 of 67

This function is provided for verifying the image that got written is the same as the programmer image. private: System::Void button_004_click(system::object^ sender, System::EventArgs^ e) { Inplements the click activity for the VERIFY button. Implements both IIC and SPI behaviour. bool error; bool match; error = false; match =true; if (this->combobox_000->text=="iic") { IIC CASE if (connected) { res = ::MBc::Nano_IICSetFrequency(MB.mb_hDevice,iic_frequency); Set frequency SlaveAddress = Int32::Parse(this->textBox_000->Text, System::Globalization::NumberStyles::HexNumber); Get Device ID StartAddress = 0x00; BufferLength = page_size; for (j=0; j<(chip_size/page_size); j++) { if (connected) res = ::MBc::Nano_IICRead(MB.mb_hDevice,SlaveAddress,2,StartAddress, BufferLength,InBuffer); IIC read if (res!=nano_success) error = true; for (i=0; i<bufferlength; i++) verify_memory[i+j*page_size] = InBuffer[i]; read into a verification array StartAddress = StartAddress + page_size; if (this->combobox_000->text=="spi") { SPI CASE if (connected) { res=::mbc::nano_spisetclockconfig(mb.mb_hdevice,spi_polarity,spi_phase); Set the SPI polarity/phase res=::mbc::nano_spisetfrequency(mb.mb_hdevice,spi_frequency); Set the SPI frequency for (j=0; j<(chip_size/page_size); j++) { out_buffer[0] = 0x03; Opcode for a READ out_buffer[1] = 0xFF & ((j*page_size)>>8); MSB Address out_buffer[2] = 0xFF & (j*page_size); LSB Address if (connected) res=::mbc::nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, page_size+3); if (res!=nano_success) error = true; for (i=0; i<page_size; i++) verify_memory[i+j*page_size] = in_buffer[i+3]; for (j=0; j<chip_size; j++) if (memory[j]!= verify_memory[j]) match = false; if (error==true) s2="error during device read"; else if (match!=true) s2="error during programming"; else s2="veification completed OK"; this->richtextbox_002->text = s2; Do the element by element check read into a verification array Rev: 1.4 (Apr 2009) Nano River Technolgies Page 43 of 67

To follow is a function to read in an intel hex format file, parse it and then use this as the programmer image. private: System::Void button_000_click(system::object^ sender, System::EventArgs^ e) { This is a simple parser for Intel HEX files. At this point the parser is limited to record types 00 and 01. Also the file must include a RETURN at the on the last line. int state= 0; A state variable char line [100]; Next line char bytesstr[2]; Number of bytes (as a string) long bytes; Number of bytes (as an long integer) int byte_count; Current byte being processed char addr1str[2],addr2str[2]; Address MSB and LSB (as strings) long int addr1,addr2; Address MSB and LSB (as a long integer) long int address; Address (as one integer) char datastr[2]; Current data byte (as a string) long data; Current data byte (as a long integer) char checksumstr[2]; Checksum (as a string) long checksum; Checksum (as a long integer) bool eof_marker; True if we have found an end of file record bool success; True is the file completes successfully char ch; The current character in the line int pos; Position of the current character char file_001[100]; The file to be used for input s2=""; for (i=0; i<memorymax; i++) memory[i] = 0xFF; Initialise the array Get the input file name sprintf(file_001, "%s",this->textbox_001->text); FILE *InFile = fopen(file_001,"r"); Conversion to Char Initialise success=false; eof_marker=false; Loop through the file - line by line while (!feof(infile) &&!success) { fgets (line, 100, InFile); pos=0; while (line[pos]!=null &&!feof(infile)) { ch=line[pos]; if (ch!='\n') { if ((state==0) && (ch==':') && (pos==0)) {state = 1; : found else if ((state==1) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 2; bytesstr[0]=ch; else if ((state==2) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 3; bytesstr[1]=ch; bytes = strtol(bytesstr,null,16); byte_count=1; byte count found else if ((state==3) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') Rev: 1.4 (Apr 2009) Nano River Technolgies Page 44 of 67

(ch>='a' && ch<='f') ) ) {state = 4; addr1str[0]=ch; else if ((state==4) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) {state = 5; addr1str[1]=ch; else if ((state==5) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) {state = 6; addr2str[0]=ch; else if ((state==6) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 7; addr2str[1]=ch; addr1 = strtol(addr1str,null,16); addr2 = strtol(addr2str,null,16); address = addr1*256 + addr2; address found else if ((state==7) & (ch=='0')) state = 8; else if ((state==8) & (ch=='0' ch=='1')) { state = 9; if (ch=='1') { eof_marker=true; if (bytes==0) {state=11; record type (only 00 or 01 accepted) else if ((state==9) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 10; datastr[0]=ch; else if ((state==10) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 9; datastr[1]=ch; if (byte_count==bytes) { state=11; data = strtol(datastr,null,16); /*NEW*/ memory[address]=data; else { data = strtol(datastr,null,16); /*NEW*/ memory[address]=data; byte_count++; address++; data found else if ((state==11) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 12; checksumstr[0]=ch; else if ((state==12) && ((ch>='0' && ch<='9') (ch>='a' && ch<='f') (ch>='a' && ch<='f') ) ) { state = 25; if (eof_marker) { state=30; success=true; checksumstr[1]=ch; checksum = strtol(checksumstr,null,16); else if (state==20) state=20; else if (state==25) state=20; else if (state==30) state=30; else state=20; checksum found State 20 Error State State 25 End Of Line State 30 End of File /Successfull else { if (state==25) state=0; pos++; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 45 of 67

fclose (InFile); if (success==true) s2="file read completed OK"; else { s2="error during file read!\n\n"; s2= System::String::Concat( s2,"file must be in Intel Hex format. "); s2= System::String::Concat( s2,"only supporting record type 00 and 01 at present.\n"); s2= System::String::Concat( s2,"must also include a RETURN on the last line.\n"); this->richtextbox_002->text = s2; Update the screen ScreenUpdate(); To follow is a function to take the programmer image, convert this to an intel hex file and then write the file to disk. private: System::Void button_001_click(system::object^ sender, System::EventArgs^ e) { Function to handle writing out the memory to file. char file_000[100]; Output file name int sum; The sum used in the checksum calculation int tmpsum; Temporary sum Get the output file name sprintf(file_000, "%s",this->textbox_002->text); Conversion to Char FILE *OutFile = fopen(file_000,"w"); for (j=0; j<(chip_size); j++) { if (((j)%16)==0) { fprintf (OutFile, ":10%04X00",j); sum = 0x10; Data Length tmpsum = j; ADD MSB of Address tmpsum = tmpsum & 0xFF00; tmpsum = tmpsum >> 8; sum = sum + tmpsum; tmpsum = 0xFF&(j); sum = sum + tmpsum; ADD LSB of Address fprintf (OutFile, "%02X",memory[j]); sum = sum + memory[j]; if (((j)%16)==15) { sum = sum & 0xFF; sum = 256 - sum; sum = sum & 0xFF; fprintf (OutFile, "%02X\n",sum); fprintf (OutFile, ":00000001FF\n"); fclose (OutFile); s2="file write completed"; this->richtextbox_002->text = s2; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 46 of 67

Two functions are provided to fill the programmer image 0xFF or with pseudo random numbers respectively. Upon completion the image window is updated. private: System::Void button_006_click(system::object^ sender, System::EventArgs^ e) { Function used to update all memory locations with random values srand(0); for (j=0; j<(chip_size); j++) { memory[j] = rand() & 0xFF; ScreenUpdate(); private: System::Void button_007_click(system::object^ sender, System::EventArgs^ e) { Function used to update all memory locations with FFs for (j=0; j<(chip_size); j++) { memory[j] = 0xFF; ScreenUpdate(); Some important links and includes are necessary in stdafx.h. This is best seen by viewing the file in the download from the web-site. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 47 of 67

6. IIC Command Tool (Linux and MacOS Versions) This example application is a C/C++ console application showing how to call functions associated with the IIC such as IIC read, IIC write, IIC scan and various configuration commands. The example is the same as the IIC Command Tool example from section 3, but ported to GCC for Linux and MacOS. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 48 of 67

6.1. Functionality The application works by prompting the user for a new command. There are three main types of commands that are accepted. IIC Scan Command %cmd> s Here the program will scan all IIC addresses and report which devices are connected to the bus. IIC Write Command %cmd> w devid <Device ID> -sa <Start Address> -l <Length> -d <Data Sequence> Here the user specifies the device ID, internal start address, transfer length and the data sequence. An IIC write transaction is then initiated. IIC Read Command %cmd> r devid <Device ID> -sa <Start Address> -l <Length> Here the user specifies the device ID, internal start address and transfer length. An IIC read transaction is then initiated and returns the read data. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 49 of 67

6.2. Project Structure This application is located in the Examples/ directory of the Linux and MacOS installation. The project file structure is implemented as follows. Examples/ common/ miniboard.h miniboard_class.h miniboard_class.c MiniBoard Header File MiniBoard Class Header File MiniBoard Class C++ File src/ IICCommandToolApplication.c Main Program (Top) scripts/ go_iiccommandtoolapplication Compile Script for Application The MiniBoard user interface is a simple class library of high level functions to control the board as I2C/SPI/GPIO or some combination. The class library is provided through miniboard_class.h and miniboard_class.c. The functions make simple calls to LibUsb OpenSource USB driver already assumed to have been installed as part of the installation process. In this example there is one main program IICCommandToolApplication.c. This program then makes calls to the class library to control in this case the I2C interface. A simple compile script has been provided to show exactly how to compile the application. This is go_iiccommandtoolapplication. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 50 of 67

To use this application, first navigate to the Examples/ directory. shell%> cd <installation_directory>/examples Next compile the application using the provided compile script. The compile script will use g++ for the compile. shell %>./scripts/go_iiccommandtoolapplication Finally run the application. shell %>./IICCommandToolApplication You should then be prompted for commands as shown earlier in this chapter. 6.3. Design Description The application (IICCommandToolApplication.c) is a port of the windows command tool application described in section 3 (IICCommandToolApplication.cpp). Please consult section 3 for a detailed description of the source code. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 51 of 67

7. Configuration Example (Linux and MacOS Versions) This is a very simple application giving a very basic setup for GPIO, I2C and SPI interfaces. The example does not show all possible configuration options. It is left to the user to read the API specification to see how to make more advanced applications. The example is meant as a starting point to show how to start developing applications for these interfaces. The example is provided for Linux and MacOS. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 52 of 67

7.1. Functionality The program runs through the following sequence. Step 1: USB connection In this step the program checks to see if it can establish connection to MiniBoard. Step2: GPIO Read/Write Two different patterns are written to the GPIO interface and then read back. Step3: I2C Read/Write Two different patterns are written to the I2C interface and then read back. This assumes a particular I2C command sequence for example a 2 byte start address etc as used for a standard I2C EEPROM. To talk with your own device you may need to change this. Step4: SPI Read/Write Two different patterns are written to the SPI interface and then read back. This assumes a particular SPI command sequence as used for a standard SPI EEPROM. To talk with your own device you may need to change this. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 53 of 67

7.2. Project Structure This application is located in the Examples/ directory of the Linux and MacOS installation. The project file structure is implemented as follows. Examples/ common/ miniboard.h miniboard_class.h miniboard_class.c MiniBoard Header File MiniBoard Class Header File MiniBoard Class C++ File src/ ConfigurationExample.c Main Program (Top) scripts/ go_configurationexample Compile Script for Application The MiniBoard user interface is a simple class library of high level functions to control the board as I2C/SPI/GPIO or some combination. The class library is provided through miniboard_class.h and miniboard_class.c. The functions make simple calls to LibUsb OpenSource USB driver already assumed to have been installed as part of the installation process. In this example there is one main program ConfigurationExample.c. This program then makes calls to the class library to control in this case the GPIO/I2C/SPI interfaces. A simple compile script has been provided to show exactly how to compile the application. This is go_configurationexample. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 54 of 67

To use this application, first navigate to the Examples/ directory. shell%> cd <installation_directory>/examples Next compile the application using the provided compile script. The compile script will use G++ for the compile. shell%>./scripts/go_configurationexample Finally run the application. shell%>./configurationexample You should then see data written to and read from the devices as shown earlier in this chapter. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 55 of 67

7.3. Design Description The application is implemented using a single file ConfigurationExample.c. The file starts by linking to the MiniBoard class library header file: Nano River Technologies File: ConfigurationExample (ConfigurationExample.c) Desciption: This is a simple command line application showing very simply how to start configuring the GPIO, SPI and I2C interfaces. This can be built upon by the user to create more advanced applications. Revision: Version 1.0 #include <stdio.h> #include <string.h> #include <stdbool.h> #include "../common/miniboard.h" #include "../common/miniboard_class.h" Next some global variables are defined. BOOL d; NANO_RESULT e; MBc MB; ULONG Value; BYTE SlaveAddress; ULONG StartAddress; BYTE StartAddressLength; WORD BufferLength; BYTE InBuffer[256]; BYTE OutBuffer[256]; BYTE in_buffer[512], out_buffer[512]; char c; int i; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 56 of 67

The main program then starts by trying to connect to the MiniBoard. The program tells whether or not a connection was established. int main(void) { printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("++ NANO RIVER TECHNOLOGIES - CONFIGURATION EXAMPLE (MiniBoard) ++\n"); printf("++ (31 Oct 2008) ++\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); printf ("<<<<< PRESS RETURN KEY >>>>>>\n"); c=getchar(); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("open DEVICE...\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); d=mb.opendevice(); if (d) printf (" MiniBoard Connected!!!\n"); else printf (" MiniBoard NOT Connected!!!\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n"); printf ("<<<<< PRESS any KEY >>>>>>\n\n"); c=getchar(); Next the program tries to write and then read 0x11223344 and then 0xDEADBEEF to the GPIO interface. The results are displayed for the user. GPIO printf("gpio READ/WRITE...\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); e=mb.nano_gpiosetdirection(mb.mb_hdevice,0xffffffff,0xffffffff); e=mb.nano_gpiowrite(mb.mb_hdevice,0x11223344,0xffffffff); printf("value (written) : %08X\n",0x11223344); e=mb.nano_gpioread(mb.mb_hdevice,&value); printf("readvalue (returned) : %08X\n",Value); e=mb.nano_gpiosetdirection(mb.mb_hdevice,0xffffffff,0xffffffff); e=mb.nano_gpiowrite(mb.mb_hdevice,0xdeadbeef,0xffffffff); printf("value (written) : %08X\n",0xDEADBEEF); e=mb.nano_gpioread(mb.mb_hdevice,&value); printf("readvalue (returned) : %08X\n",Value); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); Rev: 1.4 (Apr 2009) Nano River Technolgies Page 57 of 67

The program performs an IIC Write and then an IIC Read. Here we have assumed a 2 byte start address for a standard IIC EEPROM. The program writes and then reads 0x11223344 and then tries again with 0xDEADBEEF. IIC transactions occur at 400kBit/s fast rate. If these settings can not be used with your target device then consult the API specifications and change this code. IIC printf("iic READ/WRITE...\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); e=mb.nano_iicsetfrequency(mb.mb_hdevice,nano_iic_freq_fast); SlaveAddress=0x50; StartAddress=0x0000; StartAddressLength=2; BufferLength=0x04; OutBuffer[0]=0x11; OutBuffer[1]=0x22; OutBuffer[2]=0x33; OutBuffer[3]=0x44; printf("value (written) : %02X%02X%02X%02X\n", OutBuffer[0],OutBuffer[1],OutBuffer[2],OutBuffer[3]); e=mb.nano_iicwrite(mb.mb_hdevice,slaveaddress,startaddresslength,startaddress, BufferLength,OutBuffer); for (i=0; i<256; i++) { InBuffer[i]=0; usleep (5000); This delay is for the device (to allow for write time) e=mb.nano_iicread(mb.mb_hdevice,slaveaddress,startaddresslength,startaddress, BufferLength,InBuffer); printf("value (read) : %02X%02X%02X%02X\n", InBuffer[0],InBuffer[1],InBuffer[2],InBuffer[3]); SlaveAddress=0x50; StartAddress=0x0000; BufferLength=0x04; OutBuffer[0]=0xDE; OutBuffer[1]=0xAD; OutBuffer[2]=0xBE; OutBuffer[3]=0xEF; printf("value (written) : %02X%02X%02X%02X\n", OutBuffer[0],OutBuffer[1],OutBuffer[2],OutBuffer[3]); e=mb.nano_iicwrite(mb.mb_hdevice,slaveaddress,startaddresslength,startaddress, BufferLength,OutBuffer); for (i=0; i<256; i++) { InBuffer[i]=0; usleep (5000); This delay is for the device (to allow for write time) e=mb.nano_iicread(mb.mb_hdevice,slaveaddress,startaddresslength,startaddress, BufferLength,InBuffer); printf("value (read) : %02X%02X%02X%02X\n", InBuffer[0],InBuffer[1],InBuffer[2],InBuffer[3]); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); Rev: 1.4 (Apr 2009) Nano River Technolgies Page 58 of 67

The program performs an SPI write enable, SPI write command and then an SPI read command with data of 0x11223344. The process is repeated with 0xDEADBEEF. The sequence assumes a standard SPI EEPROM. SPI transactions occur at 400kBit/s. If these settings can not be used with your target device then consult the API specifications and change this code. SPI printf("spi READ/WRITE...\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); e=mb.nano_spisetclockconfig(mb.mb_hdevice,0x0, 0x0); e=mb.nano_spisetfrequency(mb.mb_hdevice,nano_spi_freq_400khz); Write Enable out_buffer[0] = 0x06; Opcode e=mb.nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, 0x01); Write out_buffer[0] = 0x02; Opcode out_buffer[1] = 0x00; Address out_buffer[2] = 0x00; Address out_buffer[3] = 0x11; Data out_buffer[4] = 0x22; Data out_buffer[5] = 0x33; Data out_buffer[6] = 0x44; Data printf("data written : %02X%02X%02X%02X\n", out_buffer[3],out_buffer[4],out_buffer[5],out_buffer[6],out_buffer[7]); e=mb.nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, 0x07); usleep(5000); Delay between reading and writing to ensure programming time Read out_buffer[0] = 0x03; Opcode out_buffer[1] = 0x00; Address out_buffer[2] = 0x00; Address e=mb.nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, 0x07); printf("data read : %02X%02X%02X%02X\n", in_buffer[3],in_buffer[4],in_buffer[5],in_buffer[6],in_buffer[7]); Write Enable out_buffer[0] = 0x06; Opcode e=mb.nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, 0x01); Write out_buffer[0] = 0x02; Opcode out_buffer[1] = 0x00; Address out_buffer[2] = 0x00; Address out_buffer[3] = 0xDE; Data out_buffer[4] = 0xAD; Data out_buffer[5] = 0xBE; Data out_buffer[6] = 0xEF; Data printf("data written : %02X%02X%02X%02X\n", out_buffer[3],out_buffer[4],out_buffer[5],out_buffer[6],out_buffer[7]); e=mb.nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, 0x07); usleep(5000); Delay between reading and writing to ensure programming time Read out_buffer[0] = 0x03; Opcode out_buffer[1] = 0x00; Address out_buffer[2] = 0x00; Address e=mb.nano_spireadwrite(mb.mb_hdevice, NANO_SPI_CHIPSELECT_CS, in_buffer, out_buffer, 0x07); printf("data read : %02X%02X%02X%02X\n", in_buffer[3],in_buffer[4],in_buffer[5],in_buffer[6],in_buffer[7]); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); Rev: 1.4 (Apr 2009) Nano River Technolgies Page 59 of 67

Finally the main program completes. Finished... printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf(" TEST COMPLETE...\n"); printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("\n"); printf ("<<<<< PRESS RETURN KEY >>>>>>\n"); c=getchar(); / / return 0; Rev: 1.4 (Apr 2009) Nano River Technolgies Page 60 of 67

8. IIC Checker Tool (MacOS Xcode Cocoa) This example application is a GUI application for MacOS using Xcode and Cocoa. The example shows how to use the MiniBoard from Cocoa applications to call I2C scan commands. Whilst the example is developed using MacOS 10.5 and Xcode 3.1 other versions should link in the same way. Scan Button Text Box 8.1. Functionality In this application the user should just press the scan button. If devices are present then they will be listed in the textbox output. Missing MiniBoard connection and missing I2C devices are also messaged. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 61 of 67

8.2. Project Structure This project was created as a standard Cocoa application in Xcode. The project structure is shown below. MiniBoard Class Library (Cocoa version) MiniBoard Class Library Header File MiniBoard Header File Controller Object Header to Control Buttons Controller Object to Control Buttons Top Level Code Cocoa Project Definition LibUSB Library In the classes folder Cocoa versions of the MiniBoard Class Library and MiniBoard header file are placed. Some modification was needed from the one used for GCC applications owing to the linking between standard C and Object C++ so please make sure you use these for Cocoa applications. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 62 of 67

Also in the classes folder is an application controller object which has been built up and linked to button and textbox. It has an action called scan which is linked to the button and an outlet called textbox1 connected to the textbox. Coding for this will be discussed further on. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 63 of 67

The user window has been built up graphically by dragging and dropping objects from the Cocoa library for example labels, a button and the textbox. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 64 of 67

Linking to the LibUSB dynamic library is achieved by highlighting IICChecker under targets and then calling the information browser. By selecting + then one can find libusb.dynlib to add assuming that LibUSB has been installed before-hand. Rev: 1.4 (Apr 2009) Nano River Technolgies Page 65 of 67