mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
reference code confirming Chip Reset function
This commit is contained in:
parent
c83c43a83e
commit
9b8154f821
3 changed files with 18 additions and 53 deletions
4
README
4
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
|
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
|
||||||
|
|
54
newusb.pde
54
newusb.pde
|
@ -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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
13
usbhost.h
13
usbhost.h
|
@ -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 );
|
||||||
|
@ -166,4 +167,4 @@ uint8_t MAX3421e< SS, INTR >::init()
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //_USBHOST_H_
|
#endif //_USBHOST_H_
|
||||||
|
|
Loading…
Reference in a new issue