Ejemplo n.º 1
0
uint8_t cc1101_t::ReadFIFO(void *Ptr, int8_t *PRssi) {
    uint8_t b, *p = (uint8_t*)Ptr;
    // Check if received successfully
    b = ReadRegister(CC_PKTSTATUS);
    //    Uart.Printf("St: %X  ", b);
    if(b & 0x80) {  // CRC OK
        // Read FIFO
        CsLo();                // Start transmission
        if(BusyWait() != OK) { // Wait for chip to become ready
            CsHi();
            return FAILURE;
        }
        ISpi.ReadWriteByte(CC_FIFO|CC_READ_FLAG|CC_BURST_FLAG); // Address with read & burst flags
        for(uint8_t i=0; i<IPktSz; i++) { // Read bytes
            b = ISpi.ReadWriteByte(0);
            *p++ = b;
            // Uart.Printf(" %X", b);
        }
        // Receive two additional info bytes
        b = ISpi.ReadWriteByte(0); // RSSI
        ISpi.ReadWriteByte(0);     // LQI
        CsHi();                    // End transmission
        if(PRssi != nullptr) *PRssi = RSSI_dBm(b);
        return OK;
    }
    else return FAILURE;
}
Ejemplo n.º 2
0
void cc1101_t::WriteStrobe (uint8_t AStrobe){
    CsLo();                             // Start transmission
    BusyWait();                         // Wait for chip to become ready
    IState = ReadWriteByte(AStrobe);    // Write strobe
    CsHi();                             // End transmission
    IState &= 0b01110000;               // Mask needed bits
}
Ejemplo n.º 3
0
void cc1101_t::WriteRegister (uint8_t ARegAddr, uint8_t AData){
    CsLo();                     // Start transmission
    BusyWait();                 // Wait for chip to become ready
    ReadWriteByte(ARegAddr);    // Transmit header byte
    ReadWriteByte(AData);       // Write data
    CsHi();                     // End transmission
}
Ejemplo n.º 4
0
// =========================== Registers & Strobes =============================
uint8_t cc1101_t::ReadRegister (uint8_t ARegAddr) {
    CsLo();                                 // Start transmission
    BusyWait();                             // Wait for chip to become ready
    ISpi.ReadWriteByte(ARegAddr | CC_READ_FLAG); // Transmit header byte
    uint8_t FReply = ISpi.ReadWriteByte(0);      // Read reply
    CsHi();                                 // End transmission
    return FReply;
}
Ejemplo n.º 5
0
void Adc_t::StartDMAMeasure() {
    (void)SPI_ADC->DR;  // Clear input register
    dmaStreamSetMemory0(DMA_ADC, &IRslt);
    dmaStreamSetTransactionSize(DMA_ADC, 3);
    dmaStreamSetMode(DMA_ADC, ADC_DMA_MODE);
    dmaStreamEnable(DMA_ADC);
    CsLo();
    ISpi.Enable();
}
Ejemplo n.º 6
0
uint8_t cc1101_t::WriteStrobe (uint8_t AStrobe) {
    CsLo();                             // Start transmission
    if(BusyWait() != OK) { // Wait for chip to become ready
        CsHi();
        return FAILURE;
    }
    IState = ISpi.ReadWriteByte(AStrobe);   // Write strobe
    CsHi();                                 // End transmission
    IState &= 0b01110000;                   // Mask needed bits
    return OK;
}
Ejemplo n.º 7
0
uint8_t cc1101_t::WriteRegister (uint8_t ARegAddr, uint8_t AData) {
    CsLo();                     // Start transmission
    if(BusyWait() != OK) {      // Wait for chip to become ready
        CsHi();
        return FAILURE;
    }
    ISpi.ReadWriteByte(ARegAddr);   // Transmit header byte
    ISpi.ReadWriteByte(AData);      // Write data
    CsHi();                         // End transmission
    return OK;
}
Ejemplo n.º 8
0
void cc1101_t::WriteTX(uint8_t* Ptr, uint8_t Length) {
    CsLo();                                                     // Start transmission
    BusyWait();                                                 // Wait for chip to become ready
    ISpi.ReadWriteByte(CC_FIFO|CC_WRITE_FLAG|CC_BURST_FLAG);    // Address with write & burst flags
    uint8_t b;
    //Uart.Printf("TX: ");
    for(uint8_t i=0; i<Length; i++) {
        b = *Ptr++;
        ISpi.ReadWriteByte(b);  // Write bytes
      //  Uart.Printf("%X ", b);
    }
    CsHi();    // End transmission
    //Uart.Printf("\r");
}
Ejemplo n.º 9
0
uint16_t Adc_t::Measure() {
    ISpi.Enable();
    CsLo();
    uint8_t b;
    uint32_t r = 0;
    b = ISpi.ReadWriteByte(0);
    r = b;
    b = ISpi.ReadWriteByte(0);
    r = (r << 8) | b;
    b = ISpi.ReadWriteByte(0);
    r = (r << 8) | b;
    CsHi();
    ISpi.Disable();
    r >>= 2;
    r &= 0xFFFF;
    return r;
}
Ejemplo n.º 10
0
uint8_t cc1101_t::ReadFifo(uint8_t *PBuf, uint8_t Length) {
    uint8_t b, Cnt=0;
    Cnt = ReadRegister(CC_RXBYTES);
    b = ReadRegister(CC_PKTSTATUS);
    //Uart.Printf("Sz: %X; st: %X\r", Cnt, b);

    if(b & 0x80) {
        CsLo();                                             // Start transmission
        //BusyWait();                                       // Wait for chip to become ready
        ReadWriteByte(CC_FIFO|CC_READ_FLAG|CC_BURST_FLAG);  // Address with read & burst flags
        for (uint8_t i=0; i<Length; i++) {                  // Read bytes
            b = ReadWriteByte(0);
            *PBuf++ = b;
            //Uart.Printf(" %X", b);
        }
        CsHi();    // End transmission
    }
    else Cnt = 0;   // Signal that nothing was read
    FlushRxFIFO();
    return 1;
}
Ejemplo n.º 11
0
uint8_t cc1101_t::ReadFIFO(rPkt_t *pPkt) {
    uint8_t b, *p = (uint8_t*)pPkt;
     // Check if received successfully
     b = ReadRegister(CC_PKTSTATUS);
     //    Uart.Printf("St: %X  ", b);
     if(b & 0x80) {  // CRC OK
         // Read FIFO
         CsLo();                                            // Start transmission
         BusyWait();                                        // Wait for chip to become ready
         ReadWriteByte(CC_FIFO|CC_READ_FLAG|CC_BURST_FLAG); // Address with read & burst flags
         for(uint8_t i=0; i<RPKT_LEN; i++) {                // Read bytes
             b = ReadWriteByte(0);
             *p++ = b;
       //      Uart.Printf(" %X", b);
         }
         // Receive two additional info bytes
         b = ReadWriteByte(0);   // RSSI
         ReadWriteByte(0);       // LQI
         CsHi();                 // End transmission
         pPkt->RSSI = RSSI_dBm(b);
         return OK;
     }
     else return FAILURE;
}