Future Technology Devices International Ltd VMusic SPI .

Transcription

Future Technology Devices International LtdVMusic SPI Application NoteDocument Reference No.: FT 000029Version 1.01Issue Date: 2008-06-02Future Technology Devices International Ltd (FTDI)373 Scotland Street, Glasgow G5 8QB United KingdomTel.: 44 (0) 141 429 2777Fax: 44 (0) 141 429 2758E-Mail (Support): vinculum.support@ftdichip.com Web: http://www.ftdichip.comVinculum is part of Future Technology Devices International Ltd. Neither the whole nor any part of the information contained in, or the product described inthis manual, may be adapted or reproduced in any material or electronic form without the prior written consent of the copyright holder. This product and itsdocumentation are supplied on an as-is basis and no warranty as to their suitability for any particular purpose is either made or implied. Future TechnologyDevices International Ltd will not accept any claim for damages howsoever arising as a result of use or failure of this product. Your statutory rights are notaffected. This product or any variant of it is not intended for use in any medical appliance, device or system in which the failure of the product mightreasonably be expected to result in personal injury. This document provides preliminary information that may be subject to change without notice. Nofreedom to use patents or other intellectual property rights is implied by the publication of this document. Future Technology Devices International Ltd, 373Scotland Street, Glasgow G5 8QB United Kingdom. Scotland Registered Number: SC136640 Copyright 2008 Future Technology Devices International Ltd

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 35Table of Contents1Introduction. 42Requirements. 532.1Hardware .52.2Firmware .62.3Software .6SPI Interface Module . 73.1Pin Definitions .73.2External Functions .73.2.1spiInit . 83.2.2spiReadWait . 83.2.3spiRead. 83.2.4spiWrite. 83.343.3.1spiXfer. 93.3.2spiDelay . 10Command Monitor Module. 114.1External Functions .114.1.1monSendByte . 114.1.2monCmdSend. 124.1.3monCmdSendByteParam. 124.1.4monCmdSendParam . 124.1.5monResponse. 124.1.6monPrompt . 134.25Internal Functions .9Internal Functions .13Program Control . 145.1Initialisation.146Summary . 167Copyright and Disclaimer . 178Contact Information. 18 Copyright 2008 Future Technology Devices International Ltd1

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 35List of TablesTable 1.1 Button Functions . 4Table 2.1 VMusic2 Connections. 6Table 2.2 PICDEM 2 PLUS Connections. 6 Copyright 2008 Future Technology Devices International Ltd2

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 35List of FiguresFigure 2.1 VMusic SPI Application Demo Hardware . 5Figure 3.1 SPI Data Direction Definition Code. 7Figure 3.2 Monitor Callable Functions for SPI Interface. 7Figure 3.3 SPI Pin Definition Code. 7Figure 4.1 Monitor Response Enumeration . 11Figure 5.1 Synchronisation with Echo Commands. 14Figure 5.2 Change to Short Command Set . 14Figure 5.3 Main Control Loop. 15 Copyright 2008 Future Technology Devices International Ltd3

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 351IntroductionThe Vinculum VNC1L IC and firmware libraries provided by FTDI allow embedded systems to easilycommunicate with USB devices. Using the VNC1L device, microcontrollers can now communicate with arange of USB devices including Bulk Only Mass Storage Class (BOMS), Communication Device Class(CDC), Printer Class, Human Interface Device (HID) class devices and USB hubs.To provide a visual demonstration of the capabilities of the VNC1L using the VMusic2 module, a sampleapplication using a PIC microcontroller demonstration board has been created. This example shows how touse a PICDEM 2 PLUS Demo Board to issue the desired commands to the VNC1L in order to control aVMusic2 module.This application note shows example methods of using the SPI interface to communicate with the VNC1L;sending and receiving data from the firmware command monitor; managing and decoding responses fromthe command monitor.The application provides simple media player functionality using buttons, potentiometer and the LCD on thePICDEM 2 PLUS Demo Board. The buttons send commands to the VNC1L to control playback and selecttracks; the LCD shows elapsed time and file metadata obtained by the VNC1L firmware; the potentiometeradjusts the playback volume. The buttons may perform different functions depending on the length of timethey are held. Table 1.1 lists the functions of the buttons.StateButtonActionStoppedS3PlayS2Play RandomS3 (Long)Next TrackS2 (Long)Previous TrackS3 (Short)Next TrackS2 (Short)Previous TrackS3 and S2 (Long)StopS3 and S2 (Short)PauseS3 and S2 (Short)PlayS3 and S2 (Long)StopPlayingPausedTable 1.1 Button FunctionsImplementation details for programming the SPI bus and communicating with the command monitor areprovided. Other functions of the application are not specifically related to the function of the VNC1L deviceand are left to the user to interpret. Copyright 2008 Future Technology Devices International Ltd4

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 3522.1RequirementsHardwareThis application requires a VMusic2 module, a Microchip PICDEM 2 PLUS Demo Board and a cable toconnect the VMusic2 and PICDEM 2 PLUS board. A PIC18F452 or PIC18F4520 microcontroller is neededto run the provided code.Figure 2.1 VMusic SPI Application Demo HardwareThe connecting cable comprises four I/O port signals and 5V and GND signals. This carries power and theSPI interface signals - SCLK, CS, SDI and SDO. Table 2.1 shows the connection between the CN2 (monitorinterface) on the VMusic2 module and the 2mm ribbon cable supplied with the module. In Table 2.2 the portconnections where the cable should be connected to on the PICDEM 2 PLUS board are listed. Copyright 2008 Future Technology Devices International Ltd5

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 35Pin NumberSignal NameColourPin NumberSignal eenRC1SDIOrange5SCLKYellow 5V 5VRed4SDIOrangeRC0SDOBrown3 5VRedGNDGNDBlack2SDOBrown1GNDBlackTable 2.2 PICDEM 2 PLUS ConnectionsTable 2.1 VMusic2 ConnectionsThe VMusic2 Module must be set to SPI mode using jumper CN3 to connect the UART/SPI pin to GND.J7 and J9 on the PICDEM 2 PLUS board must be unpopulated and J6 populated. The 4MHz cannedoscillator, supplied with the board, is required.2.2FirmwareThe VNC1L device on the VMusic2 Module must be programmed with VMSC1 firmware version 3.63 or laterfor this sample project. All of the VMSC1 firmware commands are specified in the Vinculum Firmware UserManual.2.3SoftwareSample C code for the PIC18F452 or PIC18F4520 microcontroller is available as a free download from theFTDI web site. The code for the PIC microcontroller must be compiled with SourceBoost C or ported to anequivalent compiler before being programmed onto the device. Copyright 2008 Future Technology Devices International Ltd6

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 353SPI Interface ModuleThe SPI Interface module controls the application’s communication with the SPI interface on the VNC1L. Thefiles SPI.c and SPI.h manage the interface as an SPI Master, controlling the SCLK (clock), CS (chip select)and SDI (data in) signals. The SDO (data out) signal is controlled by the VNC1L.The direction of data is encoded in the SPI transaction as either a read or a write. The definitions are shownin Figure 3.1.#define DIR SPIWRITE 0#define DIR SPIREAD 1Figure 3.1 SPI Data Direction Definition CodeEach callable function in the SPI Interface Module is aliased using a pre-processor definition to allow theentire module to be replaced by a functionally equivalent module for handling communications. This may bea UART or Parallel FIFO interface. The module is called the Monitor Interface. The definitions are included inthe SPI.h file and are shown in Figure 3.2. The calling application should only use the generic interfaceroutine names and not the SPI specific ones.#define#define#define#define#definemonInit spiInitmonRead spiReadmonReadWait spiReadWaitmonWrite spiWritemonInterruptFigure 3.2 Monitor Callable Functions for SPI Interface3.1Pin DefinitionsThe SPI Interface between the PICDEM 2 PLUS and the VNC1L on the VMusic2 Module utilises 4 signals.All signal names given here are relative to the VNC1L device. The pin definitions for the signals used by theSPI interface are shown in Figure 3.3.#define PORT SDI#define TRIS SDIportc.1trisc.1// SDI (on VMusic) is RC1 (Port C bit 1)#define PORT SDO#define TRIS SDOportc.0trisc.0// SDO (on VMusic) is RC0 (Port C bit 0)#define PORT SCLK portc.5#define TRIS SCLK trisc.5// SCLK is RC5 (Port C bit 5)#define PORT CS#define TRIS CS// CS is RC2 (Port C bit 2)portc.2trisc.2Figure 3.3 SPI Pin Definition Code3.2External FunctionsThe SPI Interface code presents 4 subroutines externally: spiInit – initialise the SPI interface I/O pins. spiReadWait – read continually from the SPI interface until a byte is received. spiRead – check SPI interface for available byte of data. spiWrite – write a byte of data to the SPI interface. Copyright 2008 Future Technology Devices International Ltd7

Document Reference No.: FT 000029VMusic SPI Application Note Version 1.01Clearance No.: FTDI# 35These commands can be used to allow a program to access the VNC1L firmware command alls:None.This routine sets up the 4 interface pins SCLK (output), CS (output), SDI (output) and SDO (input). It will alsoinitialise the 3 output signal to a logic low.3.2.2spiRea

This application requires a VMusic2 module, a Microchip PICDEM 2 PLUS Demo Board and a cable to connect the VMusic2 and PICDEM 2 PLUS board. A PIC18F452 or PIC18F4520 microcontroller is needed to run the provided code. Figure 2.1 VMusic SPI Application Demo Hardware . The connecting cable comprises four I/O port signals and 5V and GND signals. This carries power and the SPI