From 9b8154f821feb8462e50285d8c3d449bd87e8480 Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Tue, 18 Jan 2011 01:49:57 -0700 Subject: [PATCH] reference code confirming Chip Reset function --- README | 4 ++-- newusb.pde | 54 +++++++++--------------------------------------------- usbhost.h | 13 +++++++------ 3 files changed, 18 insertions(+), 53 deletions(-) diff --git a/README b/README index 7328e500..5aef8626 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ This is Rev.2.0 of MAX3421E-based USB Host Library for Arduino. At the moment, this repo contains current development copy of the code facilitating developer's exchange. For those not involved in the project, the code in its' current state doesn't bear any value. -In other words, nothing works yet. +In other words, nothing works yet. The project-related activity is blogged at http://www.circuitsathome.com -The code uses slightly modified Konstantin Chizhov's AVR pin templates, see the original here -> https://github.com/KonstantinChizhov/AvrProjects \ No newline at end of file +The code uses slightly modified Konstantin Chizhov's AVR pin templates, see the original here -> https://github.com/KonstantinChizhov/AvrProjects diff --git a/newusb.pde b/newusb.pde index 0fd7d701..06ce5195 100644 --- a/newusb.pde +++ b/newusb.pde @@ -1,58 +1,22 @@ -/* new USB library tests */ +/* reference USB library test sketch */ -//nclude #include "usbhost.h" MAX3421e Max; -uint8_t buf[10] = {0}; void setup() { -// Max.regWr( rPINCTL,( bmFDUPSPI + bmINTLEVEL )); -// Max.regWr( rUSBCTL, bmCHIPRES ); //Chip reset. This stops the oscillator -// Max.regWr( rUSBCTL, 0x00 ); //Remove the reset -// delay( 100 ); Serial.begin( 115200 ); - Serial.println("Start"); - - // pinModeFast2( 8, OUTPUT) - + Serial.println("\r\nStart"); + if ( Max.reset() == -1 ) { + Serial.println("OSCOKIRQ failed to assert"); + while(1); + } } void loop() { -// uint16_t i; -// Max.regWr( rUSBCTL, bmCHIPRES ); -// Max.regWr( rUSBCTL, 0x00 ); -// for( i = 0; i < 65535; i++ ) { -// if( ( Max.regRd( rUSBIRQ ) & bmOSCOKIRQ )) { -// break; -// } -// } - Serial.println( Max.reset(), DEC ); - //Max.reset(); - //delay( 100 ); - //Max.regRd( rREVISION ); - //Serial.println( Max.regRd( rREVISION ), HEX ); - - //Serial.println("tick"); - // uint8_t tmp; - // for( uint16_t i = 0; i < 256; i++ ) { - // tmp = Max.SPIxfer( i ); - // if( tmp != i ) { - // Serial.println("error"); - // } - // if( SPSR & 0x40 ) { - // Serial.println("WCOL"); - // } - // } - // static bool oldintval = 0; - // if( Max.intval() != oldintval ) { - // oldintval = Max.intval(); - // Serial.println( oldintval, DEC ); - // } - // Max.sstoggle(); - - //digitalWriteFast2( 8, 0 ); - //digitalWriteFast2( 8, 1 ); + Serial.print("Revision Register: "); + Serial.println( Max.regRd( rREVISION ), HEX ); + delay( 1000 ); } diff --git a/usbhost.h b/usbhost.h index 766d9bfd..b66c4aa9 100644 --- a/usbhost.h +++ b/usbhost.h @@ -9,7 +9,7 @@ /* SPI initialization */ -template< typename CLK, typename MOSI, typename MISO > class SPi +template< typename CLK, typename MOSI, typename MISO, typename SPI_SS > class SPi { public: static void init() { @@ -17,6 +17,7 @@ template< typename CLK, typename MOSI, typename MISO > class SPi CLK::SetDirWrite(); MOSI::SetDirWrite(); MISO::SetDirRead(); + SPI_SS::SetDirWrite(); /* mode 00 (CPOL=0, CPHA=0) master, fclk/2. Mode 11 (CPOL=11, CPHA=11) is also supported by MAX3421E */ SPCR = 0x50; SPSR = 0x01; @@ -28,10 +29,10 @@ template< typename CLK, typename MOSI, typename MISO > class SPi /* SPI pin definitions. see avrpins.h */ #if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) -typedef SPi< Pb1, Pb2, Pb3 > spi; +typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi; #endif #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) -typedef SPi< Pb5, Pb3, Pb4 > spi; +typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi; #endif template< typename SS, typename INTR > class MAX3421e /* : public spi */ @@ -45,7 +46,7 @@ template< typename SS, typename INTR > class MAX3421e /* : public spi */ uint8_t* bytesRd( uint8_t reg, uint8_t nbytes, uint8_t* data_p ); uint8_t gpioRd(); uint16_t reset(); - uint8_t init(); + int8_t init(); }; /* constructor */ template< typename SS, typename INTR > @@ -156,7 +157,7 @@ uint16_t MAX3421e< SS, INTR >::reset() } /* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */ template< typename SS, typename INTR > -uint8_t MAX3421e< SS, INTR >::init() +int8_t MAX3421e< SS, INTR >::init() { if( reset() == 0 ) { //OSCOKIRQ hasn't asserted in time return ( -1 ); @@ -166,4 +167,4 @@ uint8_t MAX3421e< SS, INTR >::init() return( 0 ); } -#endif //_USBHOST_H_ +#endif //_USBHOST_H_