reference code confirming Chip Reset function

This commit is contained in:
Oleg Mazurov 2011-01-18 01:49:57 -07:00
parent c83c43a83e
commit 9b8154f821
3 changed files with 18 additions and 53 deletions

2
README
View file

@ -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 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. 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 The code uses slightly modified Konstantin Chizhov's AVR pin templates, see the original here -> https://github.com/KonstantinChizhov/AvrProjects

View file

@ -1,58 +1,22 @@
/* new USB library tests */ /* reference USB library test sketch */
//nclude <digitalWriteFast.h>
#include "usbhost.h" #include "usbhost.h"
MAX3421e<P10, P9> Max; MAX3421e<P10, P9> Max;
uint8_t buf[10] = {0};
void setup() { 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.begin( 115200 );
Serial.println("Start"); Serial.println("\r\nStart");
if ( Max.reset() == -1 ) {
// pinModeFast2( 8, OUTPUT) Serial.println("OSCOKIRQ failed to assert");
while(1);
}
} }
void loop() { void loop() {
// uint16_t i; Serial.print("Revision Register: ");
// Max.regWr( rUSBCTL, bmCHIPRES ); Serial.println( Max.regRd( rREVISION ), HEX );
// Max.regWr( rUSBCTL, 0x00 ); delay( 1000 );
// 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 );
} }

View file

@ -9,7 +9,7 @@
/* SPI initialization */ /* SPI initialization */
template< typename CLK, typename MOSI, typename MISO > class SPi template< typename CLK, typename MOSI, typename MISO, typename SPI_SS > class SPi
{ {
public: public:
static void init() { static void init() {
@ -17,6 +17,7 @@ template< typename CLK, typename MOSI, typename MISO > class SPi
CLK::SetDirWrite(); CLK::SetDirWrite();
MOSI::SetDirWrite(); MOSI::SetDirWrite();
MISO::SetDirRead(); 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 */ /* mode 00 (CPOL=0, CPHA=0) master, fclk/2. Mode 11 (CPOL=11, CPHA=11) is also supported by MAX3421E */
SPCR = 0x50; SPCR = 0x50;
SPSR = 0x01; SPSR = 0x01;
@ -28,10 +29,10 @@ template< typename CLK, typename MOSI, typename MISO > class SPi
/* SPI pin definitions. see avrpins.h */ /* SPI pin definitions. see avrpins.h */
#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) #if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__)
typedef SPi< Pb1, Pb2, Pb3 > spi; typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
#endif #endif
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
typedef SPi< Pb5, Pb3, Pb4 > spi; typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;
#endif #endif
template< typename SS, typename INTR > class MAX3421e /* : public spi */ 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* bytesRd( uint8_t reg, uint8_t nbytes, uint8_t* data_p );
uint8_t gpioRd(); uint8_t gpioRd();
uint16_t reset(); uint16_t reset();
uint8_t init(); int8_t init();
}; };
/* constructor */ /* constructor */
template< typename SS, typename INTR > 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 */ /* initialize MAX3421E. Set Host mode, pullups, and stuff. Returns 0 if success, -1 if not */
template< typename SS, typename INTR > 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 if( reset() == 0 ) { //OSCOKIRQ hasn't asserted in time
return ( -1 ); return ( -1 );