Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Eliminated GPX, BPNT. Made register rd/wr interrupt-safe

  • Loading branch information...
commit ad140e23880a459ef3875bb8abd543df3652f1f4 1 parent abbca9f
@felis authored
Showing with 23 additions and 11 deletions.
  1. +22 −10 Max3421e.cpp
  2. +1 −1  Max3421e_constants.h
View
32 Max3421e.cpp
@@ -23,12 +23,12 @@ void MAX3421E::init()
{
/* setup pins */
pinMode( MAX_INT, INPUT);
- pinMode( MAX_GPX, INPUT );
+ // pinMode( MAX_GPX, INPUT );
pinMode( MAX_SS, OUTPUT );
- pinMode( BPNT_0, OUTPUT );
- pinMode( BPNT_1, OUTPUT );
- digitalWrite( BPNT_0, LOW );
- digitalWrite( BPNT_1, LOW );
+ //pinMode( BPNT_0, OUTPUT );
+ //pinMode( BPNT_1, OUTPUT );
+ //digitalWrite( BPNT_0, LOW );
+ //digitalWrite( BPNT_1, LOW );
Deselect_MAX3421E;
pinMode( MAX_RESET, OUTPUT );
digitalWrite( MAX_RESET, HIGH ); //release MAX3421E from reset
@@ -42,15 +42,20 @@ void MAX3421E::toggle( byte pin )
/* Single host register write */
void MAX3421E::regWr( byte reg, byte val)
{
+ uint8_t SaveSREG = SREG; //save interrupt flag
+ cli(); //disable interrupts
Select_MAX3421E;
Spi.transfer( reg + 2 ); //set WR bit and send register number
Spi.transfer( val );
Deselect_MAX3421E;
+ SREG = SaveSREG; //restore interrupt flag
}
/* multiple-byte write */
/* returns a pointer to a memory position after last written */
char * MAX3421E::bytesWr( byte reg, byte nbytes, char * data )
{
+ uint8_t SaveSREG = SREG; //save interrupt flag
+ cli(); //disable interrupts
Select_MAX3421E; //assert SS
Spi.transfer ( reg + 2 ); //set W/R bit and select register
while( nbytes ) {
@@ -59,6 +64,7 @@ char * MAX3421E::bytesWr( byte reg, byte nbytes, char * data )
nbytes--;
}
Deselect_MAX3421E; //deassert SS
+ SREG = SaveSREG; //restore interrupt flag
return( data );
}
/* GPIO write. GPIO byte is split between 2 registers, so two writes are needed to write one byte */
@@ -76,16 +82,21 @@ void MAX3421E::gpioWr( byte val )
byte MAX3421E::regRd( byte reg )
{
byte tmp;
+ uint8_t SaveSREG = SREG; //save interrupt flag
+ cli(); //disable interrupts
Select_MAX3421E;
Spi.transfer ( reg ); //send register number
tmp = Spi.transfer ( 0x00 ); //send empty byte, read register contents
- Deselect_MAX3421E;
+ Deselect_MAX3421E;
+ SREG = SaveSREG; //restore interrupt flag
return (tmp);
}
/* multiple-bytes register read */
/* returns a pointer to a memory position after last read */
char * MAX3421E::bytesRd ( byte reg, byte nbytes, char * data )
{
+ uint8_t SaveSREG = SREG; //save interrupt flag
+ cli(); //disable interrupts
Select_MAX3421E; //assert SS
Spi.transfer ( reg ); //send register number
while( nbytes ) {
@@ -94,6 +105,7 @@ char * MAX3421E::bytesRd ( byte reg, byte nbytes, char * data )
nbytes--;
}
Deselect_MAX3421E; //deassert SS
+ SREG = SaveSREG; //restore interrupt flag
return( data );
}
/* GPIO read. See gpioWr for explanation */
@@ -212,10 +224,10 @@ byte MAX3421E::Task( void )
if( pinvalue == LOW ) {
rcode = IntHandler();
}
- pinvalue = digitalRead( MAX_GPX );
- if( pinvalue == LOW ) {
- GpxHandler();
- }
+// pinvalue = digitalRead( MAX_GPX );
+// if( pinvalue == LOW ) {
+// GpxHandler();
+// }
// usbSM(); //USB state machine
return( rcode );
}
View
2  Max3421e_constants.h
@@ -6,7 +6,7 @@
/* Arduino pin definitions */
#define MAX_SS 10
#define MAX_INT 9
-#define MAX_GPX 8
+#define MAX_GPX 3
#define MAX_RESET 7
#define BPNT_0 3
Please sign in to comment.
Something went wrong with that request. Please try again.