Ejemplo n.º 1
0
int Max6651ClosedLoop::begin() {
    println("Max6651ClosedLoop::begin()");
    if (!i2c_) {
        //println("No I2C interface configured.");
        return -1;
    }
    int error = setConfigRegister(mode_config_);
    write(COMMAND_GPIO_DEFINE, gpio_config_);
    write(COMMAND_ALARM_ENABLE, alarm_config_);
    write(COMMAND_TACH_COUNT_TIME, tachometer_count_time_);
    targetSpeed(maximumSpeed());
    // TODO: Return error code
    return error;
}
Ejemplo n.º 2
0
void nRF905_init()
{
#ifdef ARDUINO
	pinMode(TRX_EN, OUTPUT);
	pinMode(PWR_MODE, OUTPUT);
	pinMode(TX_EN, OUTPUT);
	pinMode(CD, INPUT);
#if !NRF905_AM_SW
	pinMode(AM, INPUT);
#endif
#if !NRF905_DR_SW
	pinMode(DR, INPUT);
#endif

	pinMode(CSN, OUTPUT);
	digitalWrite(CSN, HIGH);

	SPI.begin();
	SPI.setClockDivider(SPI_CLOCK_DIV2);
#else
	TRX_EN_DDR |= (1<<TRX_EN_BIT);
	PWR_MODE_DDR |= (1<<PWR_MODE_BIT);
	TX_EN_DDR |= (1<<TX_EN_BIT);

	CD_DDR &= ~(1<<CD_BIT);
#if !NRF905_AM_SW
	AM_DDR &= ~(1<<AM_BIT);
#endif
#if !NRF905_DR_SW
	DR_DDR &= ~(1<<DR_BIT);
#endif

	spi_init();
#endif

	// Set default values
	config.reg1 = 0x00;
	config.reg2 = (0xC7 | NRF905_CLK_FREQ);
	config.payloadSize = NRF905_MAX_PAYLOAD;

#if NRF905_INTERRUPTS
	memset((byte*)rxBuffer, 0, sizeof(rxBuffer));
	gotData = false;

	// Set interrupts
	REG_EXTERNAL_INT_CTL |= BIT_EXTERNAL_INT_CTL;
	NRF905_INT_ON();
#endif

	// Startup
	nRF905_powerUp();
	receiveMode();
	enableStandbyMode();

//	config();

	// 4 byte TX and RX addresses
	setConfigRegister(NRF905_CMD_W_CONFIG | NRF905_REG_ADDR_WIDTH, 0b01000100);

	// Default config
	nRF905_setFrequency(NRF905_BAND_433, 433200000);
	nRF905_setAutoRetransmit(NRF905_AUTO_RETRAN_DISABLE);
	nRF905_setLowRxPower(NRF905_LOW_RX_DISABLE);
	nRF905_setTransmitPower(NRF905_PWR_10);
	nRF905_setCRCMode(NRF905_CRC_MODE_16);
	nRF905_setCRC(NRF905_CRC_ENABLE);
	nRF905_setClockOut(NRF905_OUTCLK_DISABLE);
	nRF905_setClockOutFreq(NRF905_OUTCLK_500KHZ);
	nRF905_setPayloadSize(NRF905_MAX_PAYLOAD);
	nRF905_setTXAddress(0xE7E7E7E7);
	nRF905_setRXAddress(0xE7E7E7E7);
}