Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: CC1200-MorseEncoder CC1200-Examples
Diff: CC1200.cpp
- Revision:
- 1:98af824b145e
- Parent:
- 0:0c3532738887
- Child:
- 2:2a447e8e50b8
--- a/CC1200.cpp Tue Jun 30 02:26:28 2020 -0700 +++ b/CC1200.cpp Sun Aug 09 23:39:21 2020 -0700 @@ -1,3 +1,5 @@ +#pragma clang diagnostic push +#pragma ide diagnostic ignored "readability-magic-numbers" // // Created by jamie on 3/27/2020. // @@ -283,11 +285,11 @@ writeRegister(Register::RFEND_CFG0, rfendCfg0); } -void CC1200::setOnTransmitState(CC1200::State state) +void CC1200::setOnTransmitState(CC1200::State txState) { uint8_t rfendCfg0 = readRegister(Register::RFEND_CFG0); rfendCfg0 &= ~(0b11 << RFEND_CFG0_TXOFF_MODE); - rfendCfg0 |= getOffModeBits(state) << RFEND_CFG0_TXOFF_MODE; + rfendCfg0 |= getOffModeBits(txState) << RFEND_CFG0_TXOFF_MODE; writeRegister(Register::RFEND_CFG0, rfendCfg0); } @@ -569,7 +571,7 @@ return CC1200_OSC_FREQ / (static_cast<float>(adcDecimation) * static_cast<float>(cicDecimation) * 2); } -void CC1200::setRXFilterBandwidth(float bandwidthHz, bool isCC1201) +void CC1200::setRXFilterBandwidth(float bandwidthHz) { // settings that the chip supports const uint8_t possibleADCDecimations[] = {12, 24, 48}; // indexes in this array represent the register value @@ -629,6 +631,20 @@ writeRegister(Register::MDMCFG1, mdmCfg1Value); + // also set MDMCFG0.DATA_FILTER_EN, which should be 0b11 iff bandwidth / symbol rate > 10 + uint8_t mdmCfg0Val = readRegister(Register::MDMCFG0); + + if(bandwidthHz / symbolRateSps > 10.0f) + { + mdmCfg0Val |= 0b11 << MDMCFG0_DATA_FILTER_EN; + } + else + { + mdmCfg0Val &= ~(0b11 << MDMCFG0_DATA_FILTER_EN); + } + + writeRegister(Register::MDMCFG0, mdmCfg0Val); + // finally, we need to set RX_CONFIG_LIMITATION. It's not exactly clear what this does, but its setting changes // based on the filter BW. uint8_t syncCfg0Value = readRegister(Register::SYNC_CFG0); @@ -716,6 +732,62 @@ writeRegister(Register::PREAMBLE_CFG1, preambleCfg1); } +void CC1200::setPARampRate(uint8_t firstRampLevel, uint8_t secondRampLevel, CC1200::RampTime rampTime) +{ + uint8_t paCfg0Val = 0; + paCfg0Val |= (firstRampLevel << PA_CFG0_FIRST_IPL); + paCfg0Val |= (secondRampLevel << PA_CFG0_SECOND_IPL); + paCfg0Val |= (static_cast<uint8_t>(rampTime) << PA_CFG0_RAMP_SHAPE); + + writeRegister(Register::PA_CFG0, paCfg0Val); +} + +void CC1200::setAGCReferenceLevel(uint8_t level) +{ + writeRegister(Register::AGC_REF, level); +} + +void CC1200::setAGCSyncBehavior(CC1200::SyncBehavior behavior) +{ + uint8_t agcCfg3Val = readRegister(Register::AGC_CFG3); + agcCfg3Val &= ~(0b111 << AGC_CFG3_AGC_SYNC_BEHAVIOUR); + agcCfg3Val |= static_cast<uint8_t>(behavior) << AGC_CFG3_AGC_SYNC_BEHAVIOUR; + writeRegister(Register::AGC_CFG3, agcCfg3Val); +} + +void CC1200::setAGCGainTable(CC1200::GainTable table, uint8_t minGainIndex, uint8_t maxGainIndex) +{ + uint8_t agcCfg3Val = readRegister(Register::AGC_CFG3); + uint8_t agcCfg2Val = readRegister(Register::AGC_CFG2); + + agcCfg3Val &= ~(0b11111 << AGC_CFG3_AGC_MIN_GAIN); + agcCfg2Val &= ~(0b11 << AGC_CFG2_FE_PERFORMANCE_MODE); + agcCfg2Val &= ~(0b11111 << AGC_CFG2_AGC_MAX_GAIN); + + agcCfg3Val |= maxGainIndex << AGC_CFG3_AGC_MIN_GAIN; + agcCfg2Val |= static_cast<uint8_t>(table) << AGC_CFG2_FE_PERFORMANCE_MODE; + agcCfg2Val |= maxGainIndex << AGC_CFG2_AGC_MAX_GAIN; + + writeRegister(Register::AGC_CFG3, agcCfg3Val); + writeRegister(Register::AGC_CFG2, agcCfg2Val); +} + +void CC1200::setAGCHysteresis(uint8_t hysteresisCfg) +{ + uint8_t agcCfg0Val = readRegister(Register::AGC_CFG0); + agcCfg0Val &= ~(0b11 << AGC_CFG0_AGC_HYST_LEVEL); + agcCfg0Val |= hysteresisCfg << AGC_CFG0_AGC_HYST_LEVEL; + writeRegister(Register::AGC_CFG0, agcCfg0Val); +} + +void CC1200::setAGCSlewRate(uint8_t slewrateCfg) +{ + uint8_t agcCfg0Val = readRegister(Register::AGC_CFG0); + agcCfg0Val &= ~(0b11 << AGC_CFG0_AGC_SLEWRATE_LIMIT); + agcCfg0Val |= slewrateCfg << AGC_CFG0_AGC_SLEWRATE_LIMIT; + writeRegister(Register::AGC_CFG0, agcCfg0Val); +} + void CC1200::setIFMixCFG(uint8_t value) { uint8_t ifMixCfg = readRegister(ExtRegister::IF_MIX_CFG); @@ -846,7 +918,7 @@ { spi.select(); loadStatusByte(spi.write(CC1200_READ | CC1200_MEM_ACCESS)); - uint8_t value = spi.write(CC1200_TX_FIFO | address); + uint8_t value = spi.write(CC1200_RX_FIFO | address); spi.deselect(); #if CC1200_REGISTER_LEVEL_DEBUG @@ -857,25 +929,4 @@ } - - - - - - - - - - - - - - - - - - - - - - +#pragma clang diagnostic pop \ No newline at end of file