/****************************************************************************** **Name: SI4432_TxPacket **Function: transmit package data in buffer to FIFO **Input: buffer, bytes to sent **Output: 0--error ** 1--ok ******************************************************************************/ byte SI4432_TxPacket(byte *buffer, int len) { if (!buffer) return 0; // no nil buffer! if (len > FIFOSIZE) return 0; // no over size ego SPIRead(0x03); //Clr nIRQ SPIRead(0x04); BurstWrite(0x7F, buffer, len); SPIWrite(0x0709); //Tx state while(digitalRead(nIRQ) && (millis()-lastTime<Tx_WAIT_TIMEOUT)); irqStatus1 = SPIRead(0x03); //Clr nIRQ irqStatus2 = SPIRead(0x04); if (irqStatus1 & 0x04 == 0x04) return 1; return 0; }
//===================================== u8 sx1278_LoRaTxPacket(void) //===================================== { u8 TxFlag=0; u8 addr; BurstWrite(0x00, (u8 *)sx1278Data, 21); SPIWrite(LR_RegOpMode,0x8b); //Tx Mode while(1) { if(Get_NIRQ()) //Packet send over { SPIRead(LR_RegIrqFlags); SPIWrite(LR_RegIrqFlags,LoRa_ClearIRQ_Value); //Clear irq SPIWrite(LR_RegOpMode,LoRa_Standby_Value); //Entry Standby mode break; } } }
//===================================== void sx1278_Config(void) //===================================== { u8 i; SPIWrite(LR_RegOpMode,LoRa_Sleep_Value); //Change modem mode Must in Sleep mode for(i=250;i!=0;i--) //Delay NOP(); delay_ms(15); //lora mode SPIWrite(LR_RegOpMode,LoRa_Entry_Value); BurstWrite(LR_RegFrMsb,sx1278FreqTable[Freq_Sel],3); //setting frequency parameter //setting base parameter SPIWrite(LR_RegPaConfig,sx1278PowerTable[Power_Sel]); //Setting output power parameter SPIWrite(LR_RegOcp,0x0B); //RegOcp,Close Ocp SPIWrite(LR_RegLna,0x23); //RegLNA,High & LNA Enable if(sx1278SpreadFactorTable[Lora_Rate_Sel]==6) //SFactor=6 { u8 tmp; SPIWrite(LR_RegModemConfig1,((sx1278LoRaBwTable[BandWide_Sel]<<4)+(CR<<1)+0x01));//Implicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04) SPIWrite(LR_RegModemConfig2,((sx1278SpreadFactorTable[Lora_Rate_Sel]<<4)+(CRC<<2)+0x03)); tmp = SPIRead(0x31); tmp &= 0xF8; tmp |= 0x05; SPIWrite(0x31,tmp); SPIWrite(0x37,0x0C); } else { SPIWrite(LR_RegModemConfig1,((sx1278LoRaBwTable[BandWide_Sel]<<4)+(CR<<1)+0x00));//Explicit Enable CRC Enable(0x02) & Error Coding rate 4/5(0x01), 4/6(0x02), 4/7(0x03), 4/8(0x04) SPIWrite(LR_RegModemConfig2,((sx1278SpreadFactorTable[Lora_Rate_Sel]<<4)+(CRC<<2)+0x03)); //SFactor & LNA gain set by the internal AGC loop } SPIWrite(LR_RegSymbTimeoutLsb,0xFF); //RegSymbTimeoutLsb Timeout = 0x3FF(Max) SPIWrite(LR_RegPreambleMsb,0x00); //RegPreambleMsb SPIWrite(LR_RegPreambleLsb,12); //RegPreambleLsb 8+4=12byte Preamble SPIWrite(REG_LR_DIOMAPPING2,0x01); //RegDioMapping2 DIO5=00, DIO4=01 SPIWrite(LR_RegOpMode,LoRa_Standby_Value); //Entry standby mode }
void RealTimeClock::SetTime( const TimeData& Time ) { m_SPI.BurstWrite(RTC_02_Sec,(const uint8_t*)&Time,sizeof(Time)); }