![](/media/cache/profiles/TAG-avatar.png.50x50_q85.png)
Demo of how to use CC1200 radios to send data.
CC1200 Example Project
This project shows how to use my Mbed OS CC1200 driver to send messages over the air. It connects to the radio chips, configures them (using a couple of different configurations converted from SmartRF), and sends a message from a transmitter chip to a receiver.
Hardware Setup
This program assumes that two CC1200s are connected to your processor's SPI bus. The CC1200s' circuit boards must be configured for the 900MHz band. Also, if you are connecting the two radios together directly with a cable, make sure to include an attenuator (-20dB should work) to prevent overloading the radios' RX inputs.
I used a custom circuit board for my testing, but you should also be able to use an Mbed board connected to two CC1200 eval kits to run the program.
Note: License free transmission on the 900MHz band is only legal in Region 2 countries (North and South America). Make sure to follow all local regulations covering radio transmissions!
Diff: TestCC1200.cpp
- Revision:
- 1:7e7812669c9c
- Parent:
- 0:ea2678a73bde
- Child:
- 2:ff257762763e
diff -r ea2678a73bde -r 7e7812669c9c TestCC1200.cpp --- a/TestCC1200.cpp Mon Aug 10 01:57:54 2020 -0700 +++ b/TestCC1200.cpp Fri Aug 28 16:15:10 2020 -0700 @@ -56,10 +56,13 @@ // This should be identical to the SmartRF "500ksps 4-GFSK Max Throughput ARIB Standard" configuration pc.printf("2. 915MHz 500ksps 4-GFSK DEV=400kHz CHF=1666kHz Zero-IF\n"); pc.printf("3. 915MHz 38.4ksps 2-GFSK DEV=20kHz CHF=833kHz\n"); + pc.printf("4. 915MHz 100ksps 2-GFSK DEV=50kHz CHF=208kHz Fixed Length\n"); + pc.scanf("%d", &config); printf("Running test with config %d:\n\n", config); + CC1200::PacketMode mode = CC1200::PacketMode::VARIABLE_LENGTH; CC1200::Band band = CC1200::Band::BAND_820_960MHz; float frequency = 915e6; const float txPower = 0; @@ -110,6 +113,15 @@ modFormat = CC1200::ModFormat::GFSK_2; agcRefLevel = 0x27; } + else if(config == 4) + { + fskDeviation = 49896; + symbolRate = 100000; + rxFilterBW = 208300; + modFormat = CC1200::ModFormat::GFSK_2; + agcRefLevel = 0x2A; + mode = CC1200::PacketMode::FIXED_LENGTH; + } else { pc.printf("Invalid config number!"); @@ -120,6 +132,7 @@ { radio.configureFIFOMode(); + radio.setPacketMode(mode); radio.setModulationFormat(modFormat); radio.setFSKDeviation(fskDeviation); radio.setSymbolRate(symbolRate); @@ -158,10 +171,13 @@ rxRadio.startRX(); const char message[] = "Hello world!"; - char receiveBuffer[sizeof(message) + 1]; + char receiveBuffer[sizeof(message)]; - // make sure there's a null terminator even if data is corrupted - receiveBuffer[sizeof(receiveBuffer) - 1] = '\0'; + if(mode == CC1200::PacketMode::FIXED_LENGTH) + { + txRadio.setPacketLength(sizeof(message) - 1); + rxRadio.setPacketLength(sizeof(message) - 1); + } while(true) { @@ -170,7 +186,7 @@ pc.printf("\n---------------------------------\n"); pc.printf("<<SENDING: %s\n", message); - txRadio.enqueuePacket(message, sizeof(message)); + txRadio.enqueuePacket(message, sizeof(message) - 1); // update TX radio @@ -196,7 +212,8 @@ static_cast<uint8_t>(rxRadio.getState()), rxRadio.getRXFIFOLen()); if(hasPacket) { - rxRadio.receivePacket(receiveBuffer, sizeof(message)); + rxRadio.receivePacket(receiveBuffer, sizeof(message) - 1); + receiveBuffer[sizeof(message)-1] = '\0'; pc.printf(">>RECEIVED: %s\n", receiveBuffer); } else