示例#1
0
/**
 * setup
 * Initialises all appropriate global-level variables and sets up all modules
 * appropriately. Also retrieves previous state from EEPROM.
 */
void setup()
{
    char welcomeStr1[] = "Welcome to ";
    char welcomeStr2[] = "   FennecScales!";

    int timer = 0;
    setupPower();

    retrieveState();
    initialiseRS232();
    initialiseADC();
    setupTMR1();
    setupSPI();
    //initialiseEEPROM();
    //initiateTTS();
    initLCD();
    initialiseNumPad();
    //initialisePushBtn();

    clearLCD();
    stringToLCD(welcomeStr1, LCD_LINE_1);
    stringToLCD(welcomeStr2, LCD_LINE_2);

                /* Configure interrupts */
    INTCONbits.GIE = 1; // Enable global interrupts and priority
    INTCONbits.PEIE = 1;
    RCONbits.IPEN = 1;

    for (timer = 0; timer <= 0x3FF; ++timer)
    {
        writeLEDbar(timer, 0x3FF);
        
    }

}
示例#2
0
文件: spitest.c 项目: yoakim82/aircom
void trxSPI(uint8_t tx[], uint8_t rx[])
{
	
	// open SPI device
	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("can't open device");
	
	// setup SPI device parameters
	setupSPI(fd);
	
	rx = transfer(fd, tx);

	close(fd);

}
示例#3
0
文件: main.c 项目: gtgs/gt-jtx
int main(void) {
	setupSPI();
	char m;
   _delay_ms(50);
   spiExchange(0xFF);
   while(1) {            							 // Infinite loop; define here the
		retex = spiExchange(SPPMLEN);					/**GCV**/
		retex = spiExchange(0x46);		         /**fourth channel **/

		retex = spiExchange(0x50);					/**dont care**/
		channelValue |= retex << 8;				/**make hibyte **/
		retex = spiExchange(NOP);
		channelValue |= retex;						/**make lobyte**/
		m = 0 ;
   }
};
void trxSetup(void) {

    setupSPI();     // Set up SPI com port
    spicSetupChannel1();
    spic1SetCallback(&trxSpiCallback);  // Configure callback for spi interrupts
    trxReadReg(RG_IRQ_STATUS);   // Clear pending interrupts
    trxSetStateOff(); // Transition to TRX_OFF for configuring device
    trxWriteSubReg(SR_IRQ_MASK, TRX_IRQ_TRX_END); // Interrupt at end of transceive
    trxWriteSubReg(SR_SLOTTED_OPERATION, 0);  // Disable slotted operation
    trxWriteSubReg(SR_TX_AUTO_CRC_ON, 1); // Enable automatic TX CRC
    trxWriteSubReg(SR_CLKM_CTRL, CLKM_NO_CLOCK); // No clock on CLKM pin
    trxWriteSubReg(SR_IRQ_MASK_MODE, IRQ_MASK_MODE_ON); // Turn off interrupt polling
    trxWriteSubReg(SR_MAX_CSMA_RETRIES, DEFAULT_CSMA_RETRIES); // Set CSMA attempts
    trxWriteSubReg(SR_MAX_FRAME_RETRIES, DEFAULT_FRAME_RETRIES); // Set resend attempts
    trxWriteSubReg(SR_RX_SAFE_MODE, 0); // Disable frame buffer protection
    trxWriteSubReg(SR_AACK_FVN_MODE, FRAME_VERSION_IGNORED); // Ignore frame version
    trxWriteSubReg(SR_SPI_CMD_MODE, SPI_CMD_MODE_MONITOR_PHY_RSSI); // First byte of SPI is RSSI register
    trxSetStateIdle();
    ConfigINT4(RISING_EDGE_INT & EXT_INT_ENABLE & EXT_INT_PRI_5); // Radio IC interrupt

    last_rssi = 0;
    is_ready = 1;

}
void setup() 
{
	Serial.begin(9600);
	setupSPI();}
示例#6
0
void setup(void)
{
  watchdogConfig(WATCHDOG_OFF);

  setupSPI();
#ifdef SDN_pin
  pinMode(SDN_pin, OUTPUT); //SDN
  digitalWrite(SDN_pin, 0);
#endif
  //LED and other interfaces
  pinMode(Red_LED, OUTPUT); //RED LED
  pinMode(Green_LED, OUTPUT); //GREEN LED
#ifdef Red_LED2
  pinMode(Red_LED2, OUTPUT); //RED LED
  pinMode(Green_LED2, OUTPUT); //GREEN LED
#endif
  // pinMode(BTN, INPUT); //Button
  pinMode(SLAVE_SELECT, INPUT);
  digitalWrite(SLAVE_SELECT, HIGH); // enable pullup for TX:s with open collector output
  buzzerInit();

  serialInit(115200,SERIAL_8N1);

  checkOperatingMode();

  printStr("OpenLRSng DL starting ");
  printVersion(version);
  printStr(" on HW ");
  printUL(BOARD_TYPE);
  printStr(" (");
  printUL(RFMTYPE);
  printStr("MHz) MDOE=");

  buzzerOn(BZ_FREQ);
  digitalWrite(BTN, HIGH);
  Red_LED_ON ;
  sei();

  delay(50);
  if (!slaveMode) {
    printStrLn("MASTER");
    if (!bindReadEeprom()) {
      printStrLn("eeprom bogus reinit....");
      bindInitDefaults();
      bindWriteEeprom();
    }
    if (!digitalRead(BTN)) {
      bindMode();
    }
  } else {
    printStrLn("SLAVE");
    if (!digitalRead(BTN) || !bindReadEeprom()) {
      bindRX(false);
    } else {
      bindRX(true);
    }
  }

  packetInterval = getInterval(&bind_data);

  printStrLn("Entering normal mode");

  serialFlush();
  serialInit(bind_data.serial_baudrate, bind_data.serial_mode);

  Red_LED_OFF;
  buzzerOff();

  init_rfm(0);
  rfmSetChannel(RF_channel);
  rx_reset();

  if (slaveMode) {
    to_rx_mode();
    RF_Mode = Receive;
  }

  watchdogConfig(WATCHDOG_2S);
  lastReceived=micros();
}
void CRC_Hardware::init() {
	seedRandomGenerator();
	setupPins();
	setupSPI();
	setupI2C();
}
示例#8
0
文件: spi.cpp 项目: fenrig/car_node
SPI::SPI(){
    dumpstat();
    setupSPI();
    dumpstat();
}