예제 #1
0
/* Constructor */
MAX3421E::MAX3421E( void )
{
    // initialize SPI pins
    pinMode( SCK_PIN, OUTPUT );
    pinMode( MISO_PIN, INPUT );
    pinMode( MOSI_PIN, OUTPUT );
    pinMode( SS_PIN, OUTPUT );
    digitalWrite( SCK_PIN, HIGH );
    digitalWrite( MOSI_PIN, HIGH );
    digitalWrite( SS_PIN, HIGH );

    // initialize pins
    pinMode( INT_PIN, INPUT );
    pinMode( GPX_PIN, INPUT );
    pinMode( RST_PIN, OUTPUT );
    setRST( HIGH );

    if (SPI_SAUxEN == 0) {
#ifdef WORKAROUND_READ_MODIFY_WRITE
        SBI2(SFR2_PER0, SFR2_BIT_SAUxEN); /* supply SAUx clock */
#else
        SPI_SAUxEN = 1U;          /* supply SAUx clock */
#endif
        NOP();
        NOP();
        NOP();
        NOP();
        SPI_SPSx = 0x0001U;
    }

#ifdef WORKAROUND_READ_MODIFY_WRITE
    SPI_STx      |= SPI_CHx;      /* disable CSIxx */
    CBI(SFR_IFxx,  SFR_BIT_CSIIFxx);  /* clear INTCSIxx interrupt flag */
    SBI(SFR_MKxx,  SFR_BIT_CSIMKxx);  /* disable INTCSIxx interrupt */
    CBI(SFR_PR1xx, SFR_BIT_CSIPR1xx); /* set INTCSIxx high priority */
    CBI(SFR_PR0xx, SFR_BIT_CSIPR0xx);
#else
    SPI_STx      |= SPI_CHx;      /* disable CSIxx */
    SPI_CSIIFxx   = 0U;           /* clear INTCSIxx interrupt flag */
    SPI_CSIMKxx   = 1U;           /* disable INTCSIxx interrupt */
    SPI_CSIPR1xx  = 0U;           /* set INTCSIxx high priority */
    SPI_CSIPR0xx  = 0U;
#endif
    SPI_SIRxx     = 0x0007U;      /* clear error flag */
    SPI_SMRxx     = 0x0020U;
    SPI_SCRxx     = 0xF007U;
    SPI_SDRxx     = 0x0200U;

    SPI_SOx      |= SPI_CHx << 8; /* CSIxx clock initial level */
    SPI_SOx      &= ~SPI_CHx;     /* CSIxx SO initial level */
    SPI_SOEx     |= SPI_CHx;      /* enable CSIxx output */
    SPI_SSx      |= SPI_CHx;      /* enable CSIxx */
}
예제 #2
0
void SPIClass::begin() {
  pinMode(SCK, OUTPUT);
  pinMode(MISO, INPUT_PULLUP);
  pinMode(MOSI, OUTPUT);
  pinMode(SS, OUTPUT);

  digitalWrite(SCK, HIGH);
  digitalWrite(MOSI, HIGH);
  digitalWrite(SS, HIGH);

  if (SPI_SAUxEN == 0) {
#ifdef WORKAROUND_READ_MODIFY_WRITE
    SBI2(SFR2_PER0, SFR2_BIT_SAUxEN);  // クロック供給開始
#else
    SPI_SAUxEN = 1;                    // クロック供給開始
#endif
    NOP();
    NOP();
    NOP();
    NOP();
    SPI_SPSx = 0x0001;                 // 動作クロック設定
  }

#ifdef WORKAROUND_READ_MODIFY_WRITE
  SPI_STx      |= SPI_CHx;             // シリアル通信停止
  SBI(SFR_MKxx,  SFR_BIT_CSIMKxx);     // 割り込み処理禁止
  CBI(SFR_IFxx,  SFR_BIT_CSIIFxx);     // 割り込み要求フラグをクリア
  CBI(SFR_PR1xx, SFR_BIT_CSIPR1xx);    // 割り込み優先順位の設定
  CBI(SFR_PR0xx, SFR_BIT_CSIPR0xx);
#else
  SPI_STx      |= SPI_CHx;             // シリアル通信停止
  SPI_CSIMKxx   = 1;                   // 割り込み処理禁止
  SPI_CSIIFxx   = 0;                   // 割り込み要求フラグをクリア
  SPI_CSIPR1xx  = 0;                   // 割り込み優先順位の設定
  SPI_CSIPR0xx  = 0;
#endif
  SPI_SIRxx     = 0x0007;              // エラーフラグをクリア
  SPI_SMRxx     = 0x0020;              // モード設定
  SPI_SCRxx     = 0xF007;              // シリアル通信動作設定
  SPI_SDRxx     = SPI_CLOCK_DIV4 << 9; // 動作クロックの分周設定

  start();
}
예제 #3
0
static void initISR(timer16_Sequence_t timer)
{  
    if( timer == _timer1){
        if( SRV_TAUxEN == 0 ){
#ifdef WORKAROUND_READ_MODIFY_WRITE
            SBI2( SRV_SFR2_PERx, SRV_SFR2_BIT_TAUxEN );        /* supplies input clock */
#else
            SRV_TAUxEN = 1U;          /* supplies input clock */
#endif
            SRV_TPSx   = TIMER_CLOCK;
        }

#ifdef WORKAROUND_READ_MODIFY_WRITE
        /* Set INTTM04 low priority */
        SBI( SRV_SFR_PR1xx, SRV_SFR_BIT_TMPR1xx );
        SBI( SRV_SFR_PR0xx, SRV_SFR_BIT_TMPR0xx );
        /* Mask channel 04 interrupt */
        CBI( SRV_SFR_MKxx, SRV_SFR_BIT_TMMKxx );    /* enable INTTM04 interrupt */
        CBI( SRV_SFR_IFxx, SRV_SFR_BIT_TMIFxx );    /* clear INTTM04 interrupt flag */
#else
        /* Set INTTM04 low priority */
        SRV_TMPR1xx = 1U;
        SRV_TMPR0xx = 1U;
        /* Mask channel 04 interrupt */
        SRV_TMMKxx  = 0U;    /* enable INTTM04 interrupt */
        SRV_TMIFxx  = 0U;    /* clear INTTM04 interrupt flag */
#endif
        /* Channel 0 used as interval timer */
        SRV_TMRxx   = 0x8000U;
        SRV_TDRxx   = (unsigned int)usToTicks(REFRESH_INTERVAL);
        SRV_TSx    |= SRV_CHx;     /* operation is enabled (start trigger is generated) */

        delay(1);
        
        Channel[timer] = -1;
        handle_interrupts(_timer1);   /* TDR0x setting */

    }
}