void RFM70::setMode(uint8_t mode) { if (mode) { setModeRX(); } else { setModeTX(); } }
void RFM70::initRegisters() { int i=0; // Init bank 0 registers selectBank(0); // The last two regs in the bank0Init list will be handled later for (int i = 0; i < 20; i++) { uint8_t data[] = {RFM70_bank0Init[i][0],RFM70_bank0Init[i][1]}; spiSend(0, data, 2); } // Init address registers in bank 0 spiSend(0, (uint8_t *) RFM70_cmd_adrRX0, NELEMS(RFM70_cmd_adrRX0)); spiSend(0, (uint8_t *) RFM70_cmd_adrRX1, NELEMS(RFM70_cmd_adrRX1)); spiSend(0, (uint8_t *) RFM70_cmd_adrTX, NELEMS(RFM70_cmd_adrTX)); uint8_t data[] = {RFM70_REG_FEATURE, 0x00}; #if 1 i=readRegVal(RFM70_REG_FEATURE); if (i==0) { spiSend(0, (uint8_t *)RFM70_cmd_activate, 2); } #endif // Set Registers 1D and 1C data[0] = RFM70_bank0Init[22][0]; data[1] = RFM70_bank0Init[22][1]; spiSend(0, data, 2); data[0] = RFM70_bank0Init[21][0]; data[1] = RFM70_bank0Init[21][1]; spiSend(0, data, 2); // Init bank 1 registers selectBank(1); for (int i = 0; i < 14; i++) { spiSend(0, (uint8_t *) RFM70_bank1Init[i], NELEMS(RFM70_bank1Init[i])); } // Set ramp curve spiSend(0, (uint8_t *) RFM70_bank1R0EInit, NELEMS(RFM70_bank1R0EInit)); // Do we have to toggle some bits here like in the example code? spiSend(0, (uint8_t *) RFM70_cmd_tog1, NELEMS(RFM70_cmd_tog1)); spiSend(0, (uint8_t *) RFM70_cmd_tog2, NELEMS(RFM70_cmd_tog2)); delayMs(RFM70_END_INIT_WAIT_MS); // Check the ChipID if (readRegVal(0x08) != 0x63) { debug(RFM70_DEBUG_WRONG_CHIP_ID); } printf("chid id is 0x%02x\n", readRegVal(0x08)); // debug(RFM70_SHOW_REGISTERS); selectBank(0); setModeRX(); }
bool initRegisters() { // init bank 0 registers selectBank(0); // !! The last two regs in the bank0Init list will be handled later for (int i = 0; i < 20; i++) writeRegVal(pgm_read_byte(&RFM73_bank0Init[i][0]), pgm_read_byte(&RFM73_bank0Init[i][1])); // init address registers in bank 0 writeRegPgmBuf((uint8_t *)RFM73_cmd_adrRX0, sizeof(RFM73_cmd_adrRX0)); writeRegPgmBuf((uint8_t *)RFM73_cmd_adrRX1, sizeof(RFM73_cmd_adrRX1)); writeRegPgmBuf((uint8_t *)RFM73_cmd_adrTX, sizeof(RFM73_cmd_adrTX)); // activate Feature register if (!readRegVal(RFM73_REG_FEATURE)) writeRegPgmBuf((uint8_t *)RFM73_cmd_activate, sizeof(RFM73_cmd_activate)); // now set Registers 1D and 1C writeRegVal(pgm_read_byte(&RFM73_bank0Init[22][0]), pgm_read_byte(&RFM73_bank0Init[22][1])); writeRegVal(pgm_read_byte(&RFM73_bank0Init[21][0]), pgm_read_byte(&RFM73_bank0Init[21][1])); // init bank 1 registers selectBank(1); for (int i = 0; i < 14; i++) writeRegPgmBuf((uint8_t *)RFM73_bank1Init[i], sizeof(RFM73_bank1Init[i])); // set ramp curve writeRegPgmBuf((uint8_t *)RFM73_bank1R0EInit, sizeof(RFM73_bank1R0EInit)); // do we have to toggle some bits here like in the example code? writeRegPgmBuf((uint8_t *)RFM73_cmd_tog1, sizeof(RFM73_cmd_tog1)); writeRegPgmBuf((uint8_t *)RFM73_cmd_tog2, sizeof(RFM73_cmd_tog2)); _delay_ms(RFM73_END_INIT_WAIT_MS); //Check the ChipID if (readRegVal(0x08) != 0x63) { return false; } selectBank(0); setModeRX(); return true; }
void RFM70::initRegisters() { // Init bank 0 registers selectBank(0); // The last two regs in the bank0Init list will be handled later for (int i = 0; i < 20; i++) { writeRegVal(pgm_read_byte(&RFM70_bank0Init[i][0]), pgm_read_byte(&RFM70_bank0Init[i][1])); } // Init address registers in bank 0 writeRegPgmBuf((uint8_t *) RFM70_cmd_adrRX0, sizeof(RFM70_cmd_adrRX0)); writeRegPgmBuf((uint8_t *) RFM70_cmd_adrRX1, sizeof(RFM70_cmd_adrRX1)); writeRegPgmBuf((uint8_t *) RFM70_cmd_adrTX, sizeof(RFM70_cmd_adrTX)); // Activate Feature register if (!readRegVal(RFM70_REG_FEATURE)) { writeRegPgmBuf((uint8_t *) RFM70_cmd_activate, sizeof(RFM70_cmd_activate)); } // Now set Registers 1D and 1C writeRegVal(pgm_read_byte(&RFM70_bank0Init[22][0]), pgm_read_byte(&RFM70_bank0Init[22][1])); writeRegVal(pgm_read_byte(&RFM70_bank0Init[21][0]), pgm_read_byte(&RFM70_bank0Init[21][1])); // Init bank 1 registers selectBank(1); for (int i = 0; i < 14; i++) { writeRegPgmBuf((uint8_t *) RFM70_bank1Init[i], sizeof(RFM70_bank1Init[i])); } // set ramp curve writeRegPgmBuf((uint8_t *) RFM70_bank1R0EInit, sizeof(RFM70_bank1R0EInit)); // do we have to toggle some bits here like in the example code? writeRegPgmBuf((uint8_t *) RFM70_cmd_tog1, sizeof(RFM70_cmd_tog1)); writeRegPgmBuf((uint8_t *) RFM70_cmd_tog2, sizeof(RFM70_cmd_tog2)); delayMs(RFM70_END_INIT_WAIT_MS); //Check the ChipID if (readRegVal(0x08) != 0x63) { debug(RFM70_DEBUG_WRONG_CHIP_ID); } selectBank(0); setModeRX(); }
void startListening(const uint32_t &localAddress) { if (getMode() != MODE_PRX) { setModeRX(); } uint8_t adr[5]; memcpy(adr, &localAddress, 4); adr[4] = 0; if (!configRxPipe(1, adr, 0, 1)) { Serial.println("ERROR: cannot config RX Pipe"); } else { // Enable radio unit in the RFM73 CE_HIGH; } }