/** * @brief clear previous setting and set to default value * @param none * @return none */ void ADXL345::clearSettings(void){ setRange(RANGE_2G); setDataRate(RATE_100HZ); writeByte(THRESH_TAP_REG, 0x00); writeByte(DUR_REG, 0x00); writeByte(LATENT_REG, 0x00); writeByte(WINDOW_REG, 0x00); writeByte(THRESH_ACT_REG, 0x00); writeByte(THRESH_INACT_REG, 0x00); writeByte(TIME_INACT_REG, 0x00); writeByte(THRESH_FF_REG, 0x00); writeByte(TIME_FF_REG, 0x00); writeByte(INT_MAP_REG, 0x00); writeByte(INT_ENABLE_REG, 0x00); uint8_t value; value = readByte(ACT_INACT_CTL_REG); value &= 0x88; writeByte(ACT_INACT_CTL_REG, value); value = readByte(TAP_AXES_REG); value &= 0xF8; writeByte(TAP_AXES_REG, value); }
void ADXL345::clearSettings(void) { setRange(ADXL345_RANGE_2G); setDataRate(ADXL345_DATARATE_100HZ); writeRegister8(ADXL345_REG_THRESH_TAP, 0x00); writeRegister8(ADXL345_REG_DUR, 0x00); writeRegister8(ADXL345_REG_LATENT, 0x00); writeRegister8(ADXL345_REG_WINDOW, 0x00); writeRegister8(ADXL345_REG_THRESH_ACT, 0x00); writeRegister8(ADXL345_REG_THRESH_INACT, 0x00); writeRegister8(ADXL345_REG_TIME_INACT, 0x00); writeRegister8(ADXL345_REG_THRESH_FF, 0x00); writeRegister8(ADXL345_REG_TIME_FF, 0x00); uint8_t value; value = readRegister8(ADXL345_REG_ACT_INACT_CTL); value &= 0b10001000; writeRegister8(ADXL345_REG_ACT_INACT_CTL, value); value = readRegister8(ADXL345_REG_TAP_AXES); value &= 0b11111000; writeRegister8(ADXL345_REG_TAP_AXES, value); }
/*! Try to connect to a sensor backend. Returns true if a suitable backend could be found, false otherwise. The type must be set before calling this method if you are using QSensor directly. \sa isConnectedToBackend() */ bool QSensor::connectToBackend() { Q_D(QSensor); if (isConnectedToBackend()) return true; int dataRate = d->dataRate; int outputRange = d->outputRange; d->backend = QSensorManager::createBackend(this); if (d->backend) { // Reset the properties to their default values and re-set them now so // that the logic we've put into the setters gets called. if (dataRate != 0) { d->dataRate = 0; setDataRate(dataRate); } if (outputRange != -1) { d->outputRange = -1; setOutputRange(outputRange); } } return isConnectedToBackend(); }
bool Adafruit_LIS3DH::begin(uint8_t i2caddr) { _i2caddr = i2caddr; if (_cs == -1) { // i2c Wire.begin(); } else { digitalWrite(_cs, HIGH); pinMode(_cs, OUTPUT); if (_sck == -1) { // hardware SPI SPI.begin(); } else { // software SPI pinMode(_sck, OUTPUT); pinMode(_mosi, OUTPUT); pinMode(_miso, INPUT); } } /* Check connection */ uint8_t deviceid = readRegister8(LIS3DH_REG_WHOAMI); if (deviceid != 0x33) { /* No LIS3DH detected ... return false */ //Serial.println(deviceid, HEX); return false; } // enable all axes, normal mode writeRegister8(LIS3DH_REG_CTRL1, 0x07); // 400Hz rate setDataRate(LIS3DH_DATARATE_400_HZ); // High res enabled writeRegister8(LIS3DH_REG_CTRL4, 0x08); // DRDY on INT1 writeRegister8(LIS3DH_REG_CTRL3, 0x10); // Turn on orientation config //writeRegister8(LIS3DH_REG_PL_CFG, 0x40); // enable adc & temp sensor writeRegister8(LIS3DH_REG_TEMPCFG, 0xC0); for (uint8_t i=0; i<0x30; i++) { Serial.print("$"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX); } return true; }
void ImuRosI::attachHandler() { Imu::attachHandler(); is_connected_ = true; // Reset error number to no error if the prev error was disconnect if (error_number_ == 13) error_number_ = 0; diag_updater_.force_update(); // Set device params. This is in attachHandler(), since it has to be repeated on reattachment. setDataRate(period_); }
void DW1000Class::enableMode(const byte mode[]) { setDataRate(mode[0]); setPulseFrequency(mode[1]); setPreambleLength(mode[2]); // TODO add channel and code to mode tuples // TODO add channel and code settings with checks (see Table 58) setChannel(CHANNEL_5); if(mode[1] == TX_PULSE_FREQ_16MHZ) { setPreambleCode(PREAMBLE_CODE_16MHZ_4); } else { setPreambleCode(PREAMBLE_CODE_64MHZ_10); } }
/** Power on and prepare for general usage. * This will prepare the magnetometer with default settings, ready for single- * use mode (very low power requirements). Default settings include 8-sample * averaging, 15 Hz data output rate, normal measurement bias, a,d 1090 gain (in * terms of LSB/Gauss). Be sure to adjust any settings you need specifically * after initialization, especially the gain settings if you happen to be seeing * a lot of -4096 values (see the datasheet for mor information). */ void HMC5883L::initialize() { // write CONFIG_A register setSampleAveraging(HMC5883L_AVERAGING_8); setMeasurementBias(HMC5883L_BIAS_NORMAL); setDataRate(HMC5883L_RATE_15); // write CONFIG_B register setGain(HMC5883L_GAIN_1090); // write MODE register setMode(HMC5883L_MODE_SINGLE); }
bool Radio::setup(void) { HalfDuplexSPI::setup(); csnHigh(); // Must allow the radio time to settle else configuration bits will not necessarily stick. // This is actually only required following power up but some settling time also appears to // be required after resets too. For full coverage, we'll always assume the worst. // Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped. // Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure. // WARNING: Delay is based on P-variant whereby non-P *may* require different timing. _delay_ms(5); // Reset CONFIG and enable 16-bit CRC. write_register(CONFIG, 0 | _BV(EN_CRC) | _BV(CRCO)); // Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier // WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet // sizes must never be used. See documentation for a more complete explanation. setRetries(5, 15); uint8_t setup = read_register(RF_SETUP); // Then set the data rate to the slowest (and most reliable) speed supported by all // hardware. setDataRate(DataRate::RATE_1MBPS); write_register(FEATURE, 0); write_register(DYNPD, 0); // Reset current status // Notice reset and flush is the last thing we do write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT)); setChannel(76); // Flush buffers flush_rx(); flush_tx(); //Power up by default when setup() is called. powerUp(); // Enable PTX, do not write CE high so radio will remain in standby I mode ( 130us max to transition to RX or TX // instead of 1500us from powerUp ) PTX should use only 22uA of power. write_register(CONFIG, (read_register(CONFIG)) & ~_BV(PRIM_RX)); // If setup is 0 or ff then there was no response from module. return setup != 0 && setup != 0xff; }
void BayRF24::init(uint64_t address, uint8_t c = 0x71, rf24_pa_dbm_e pa_level = RF24_PA_HIGH, rf24_datarate_e rate = RF24_250KBPS) { _pipe = address; RF24::begin(); setChannel(c); setPayloadSize(32); enableDynamicPayloads(); setCRCLength (RF24_CRC_16); setDataRate(rate); setPALevel(pa_level); _pa_level = pa_level; //changed 0.1.2 - as we normally have a storage on board //User can call client.setRetries(15,15) after client.init setRetries(15, 8); setAutoAck(true); if (_powerdown) powerDown(); }
bool HMC5883L::begin() { Wire.begin(); if ((fastRegister8(HMC5883L_REG_IDENT_A) != 0x48) || (fastRegister8(HMC5883L_REG_IDENT_B) != 0x34) || (fastRegister8(HMC5883L_REG_IDENT_C) != 0x33)) { return false; } setRange(HMC5883L_RANGE_1_3GA); setMeasurementMode(HMC5883L_CONTINOUS); setDataRate(HMC5883L_DATARATE_15HZ); setSamples(HMC5883L_SAMPLES_1); mgPerDigit = 0.92f; return true; }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the OLED display and write status. // // // Enable the peripherals used by this example. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); //PC5,PC7 EN,CSN SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE,1<<5|1<<7); //SPI配置 unsigned long ulDataTx[NUM_SSI_DATA]; unsigned long ulDataRx[NUM_SSI_DATA]; unsigned long ulindex; unsigned long ultemp=0; SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0RX); GPIOPinConfigure(GPIO_PA5_SSI0TX); GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 4000000, 8); /* GPIODirModeSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_DIR_MODE_OUT); GPIOPadConfigSet(GPIO_PORTA_BASE, GPIO_PIN_3, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_DIR_MODE_OUT); GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_0 , GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU); */ SSIEnable(SSI0_BASE); // // Enable processor interrupts. // IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // IntEnable(INT_UART0); UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTStdioInit(0); UARTSend((unsigned char *)"Enter text:\n\r", 12); UARTSend((unsigned char *)"Enter text:\n\r", 12); //清零接收缓冲区 while(SSIDataGetNonBlocking(SSI0_BASE, &ulDataRx[0])) { } ulDataTx[0] = 's'; ulDataTx[1] = 'p'; ulDataTx[2] = 'i'; set_nrf24l01_csn_l(); /* for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++) { UARTprintf("'%c' ", ulDataTx[ulindex]); SSIDataPut(SSI0_BASE, ulDataTx[ulindex]); } */ set_nrf24l01_csn_h(); _delay_ms(1); if( setDataRate( RF24_250KBPS ) ) { p_variant = true ; } //初始化NRF24L01 set_module_tx(); nrf_write_reg(NRF_CONFIG,0x0a); print_byte_register("CONFIG\t",NRF_CONFIG,1); init_NRF24L01(); set_module_tx(); unsigned char transfer_value[]="EEWORLD_MSP430_00"; //set_module_tx(); //读不出来spi数据的原因是,原来里面有没读取完的数据,需要先清理,再读写. setChannel(74); UARTprintf("getchannel:%d\r\n",getChannel()); // setChannel(24); // UARTprintf("getchannel:%d\r\n",getChannel()); //写地址 nrf_write_buf(TX_ADDR,(uint8_t*)&addresses[0],5); uint8_t recvbuf[5]; nrf_read_buf(TX_ADDR,&recvbuf[0],5); for(int i=0;i<5;i++) { UARTprintf("%d:%d ",i,recvbuf[i]); } UARTprintf("\r\n"); //end of test write address uint8_t data[32]; for(int i=0;i<32;i++) { data[i]=i; } UARTprintf("\r\n"); //while(SSIDataGetNonBlocking(SSI0_BASE, &ulDataRx[0])) //{ //} //重新发送前,避免写缓冲区满 flush_tx(); spi_write_reg(STATUS, ( spi_read_reg(STATUS) ) | _BV(MAX_RT) ); //role=role_ping_out openWritingPipe(addresses[0]); openReadingPipe(1,addresses[1]); nrf_write_buf(RX_ADDR_P0,(uint8_t*)&addresses[0],5); unsigned char test; //while(1) { test=spi_read_reg(0x05); UARTprintf("test:%d\r\n",test); _delay_ms(1000); } //调试关闭 //nrf_write_reg(EN_AA,0x00); nrf_write_reg(EN_RXADDR,0x02); //nrf_write_reg(SETUP_RETR,0x00); nrf_write_reg(RX_PW_P1,0x20); //set_module_tx(); nrf_write_reg(NRF_CONFIG,0x0b); nrf_write_reg(CONFIG, nrf_read_reg(CONFIG) | _BV(PRIM_RX)); nrf_write_reg(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); set_nrf24l01_ce_h(); nrf_write_buf(RX_ADDR_P0,(uint8_t*)&addresses[0],5); set_nrf24l01_ce_h(); if(nrf_read_reg(FEATURE) & _BV(EN_ACK_PAY)) { flush_tx(); } flush_rx(); print_status(get_status()); nrf_write_reg(SETUP_AW,0x03); print_byte_register("SETUP_AW\t",SETUP_AW,1); print_address_register("RX_ADDR_P0-1",RX_ADDR_P0,2); print_byte_register("RX_ADDR_P2-5",RX_ADDR_P2,4); print_address_register("TX_ADDR\t",TX_ADDR,1); print_byte_register("RX_PW_P0-6",RX_PW_P0,6); print_byte_register("EN_AA\t",EN_AA,1); print_byte_register("EN_RXADDR",EN_RXADDR,1); print_byte_register("RF_CH\t",RF_CH,1); print_byte_register("RF_SETUP",RF_SETUP,1); print_byte_register("CONFIG\t",NRF_CONFIG,1); print_byte_register("DYNPD/FEATURE",DYNPD,2); UARTprintf("Data Rate\t = %s\r\n", pgm_read_word(&rf24_datarate_e_str_P[getDataRate()])); UARTprintf("Model\t\t = %s\r\n", pgm_read_word(&rf24_model_e_str_P[isPVariant()])); UARTprintf("CRC Length\t = %s\r\n",pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()])); UARTprintf("PA Power\t = %s\r\n", pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()])); Init_Timer_A(); set_nrf24l01_ce_h(); //将业务数据写入:WR_TX_PLOAD uint8_t fifo_status,status,state,i; while(1) { fifo_status=spi_read_reg(FIFO_STATUS); if(fifo_status&0x02) { status=spi_read_reg(STATUS); if(status&_BV(RX_DR)) { state=spi_send_byte(RD_RX_PLOAD); for(i=0;i<RX_PLOAD_WIDTH;i++) { status=spi_send_byte(0xff); //buf[i]=status; } nrf_write_reg(FLUSH_RX,0xFF); //UARTprintf("."); counter++; } if(status &0x02) { nrf_write_reg(FLUSH_RX,0xFF); //UARTprintf("."); counter++; } nrf_rx_packet(data); } } while(available(0)) { //UARTprintf("."); if(nrf_rx_packet(data) == 0) { counter++; } //UARTprintf("."); //_delay_ms(50); /* set_nrf24l01_ce_l(); nrf_write_buf(WR_TX_PLOAD,data,TX_PLOAD_WIDTH); set_nrf24l01_ce_h(); _delay_ms(30); */ } }
RotationController::RotationController(): InputController(), m_factor(0.5) { setDataRate(&m_rotationSensor); doStart(); }
MagnetometerController::MagnetometerController(): m_width(View::m_imageWidth){ setDataRate(&m_magnetometer); m_magnetometer.setProperty("returnGeoValues", true); doStart(); }
bool Adafruit_LIS3DH::begin(uint8_t i2caddr) { _i2caddr = i2caddr; if (_cs == -1) { // i2c Wire.begin(); } else { digitalWrite(_cs, HIGH); pinMode(_cs, OUTPUT); #ifndef __AVR_ATtiny85__ if (_sck == -1) { // hardware SPI SPI.begin(); } else { // software SPI pinMode(_sck, OUTPUT); pinMode(_mosi, OUTPUT); pinMode(_miso, INPUT); } #endif } /* for (uint8_t i=0; i<0x30; i++) { Serial.print("$"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX); } */ /* Check connection */ uint8_t deviceid = readRegister8(LIS3DH_REG_WHOAMI); if (deviceid != 0x33) { /* No LIS3DH detected ... return false */ //Serial.println(deviceid, HEX); return false; } // Set default values for registers writeRegister8(LIS3DH_REG_CTRL1, 0x07); // enable all axes, normal mode writeRegister8(LIS3DH_REG_CTRL2, 0x00); writeRegister8(LIS3DH_REG_CTRL3, 0x00); writeRegister8(LIS3DH_REG_CTRL4, 0x00); writeRegister8(LIS3DH_REG_CTRL5, 0x00); writeRegister8(LIS3DH_REG_CTRL6, 0x00); writeRegister8(LIS3DH_REG_INT1CFG, 0x00); writeRegister8(LIS3DH_REG_INT1THS, 0x00); writeRegister8(LIS3DH_REG_INT1DUR, 0x00); writeRegister8(LIS3DH_REG_CLICKCFG, 0x00); writeRegister8(LIS3DH_REG_CLICKSRC, 0x00); writeRegister8(LIS3DH_REG_CLICKTHS, 0x00); writeRegister8(LIS3DH_REG_TIMELIMIT, 0x00); writeRegister8(LIS3DH_REG_TIMELATENCY, 0x00); writeRegister8(LIS3DH_REG_TIMEWINDOW, 0x00); writeRegister8(LIS3DH_REG_FIFOCTRL, 0x00); // 400Hz rate (default data rate is shutdown mode, so set to continuous) setDataRate(LIS3DH_DATARATE_400_HZ); // High res & BDU enabled writeRegister8(LIS3DH_REG_CTRL4, 0x88); // enable adcs writeRegister8(LIS3DH_REG_TEMPCFG, 0x80); /* for (uint8_t i=0; i<0x30; i++) { Serial.print("$"); Serial.print(i, HEX); Serial.print(" = 0x"); Serial.println(readRegister8(i), HEX); } */ return true; }
bool QRF24::begin() { debug = true; // Init BCM2835 chipset for talking with us if (!bcm2835_init()) return false; // Initialise the CE pin of NRF24 (chip enable) bcm2835_gpio_fsel(ce_pin, BCM2835_GPIO_FSEL_OUTP); bcm2835_gpio_write(ce_pin, LOW); // used to drive custom I/O to trigger my logic analyser // bcm2835_gpio_fsel(GPIO_CTRL_PIN , BCM2835_GPIO_FSEL_OUTP); // start the SPI library: // Note the NRF24 wants mode 0, MSB first and default to 1 Mbps bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // Set SPI bus Speed bcm2835_spi_setClockSpeed(spi_speed); // This initialize the SPI bus with // csn pin as chip select (custom or not) bcm2835_spi_begin(csn_pin); // wait 100ms delay(100); // Must allow the radio time to settle else configuration bits will not necessarily stick. // This is actually only required following power up but some settling time also appears to // be required after resets too. For full coverage, we'll always assume the worst. // Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped. // Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure. // WARNING: Delay is based on P-variant whereby non-P *may* require different timing. delay( 5 ) ; // Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier // WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet // sizes must never be used. See documentation for a more complete explanation. //printf("write_register(%02X, %02X)\n", SETUP_RETR, (0b0100 << ARD) | (0b1111 << ARC)); writeRegister(SETUP_RETR,(0b0100 << ARD) | (0b1111 << ARC)); // Restore our default PA level setPALevel( RF24_PA_MAX ) ; // Determine if this is a p or non-p RF24 module and then // reset our data rate back to default value. This works // because a non-P variant won't allow the data rate to // be set to 250Kbps. if( setDataRate( RF24_250KBPS ) ) { p_variant = true ; } // Then set the data rate to the slowest (and most reliable) speed supported by all // hardware. setDataRate( RF24_1MBPS ) ; // Initialize CRC and request 2-byte (16bit) CRC setCRCLength( RF24_CRC_16 ) ; // Disable dynamic payloads, to match dynamic_payloads_enabled setting writeRegister(DYNPD,0); // Reset current status // Notice reset and flush is the last thing we do writeRegister(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); // Set up default configuration. Callers can always change it later. // This channel should be universally safe and not bleed over into adjacent // spectrum. setChannel(76); // Flush buffers flushRx(); flushTx(); return true; }