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
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

View file

@ -1,58 +1,22 @@
/* new USB library tests */
/* reference USB library test sketch */
//nclude <digitalWriteFast.h>
#include "usbhost.h"
MAX3421e<P10, P9> 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 );
}

View file

@ -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 );