Demo of how to use CC1200 radios to send data.

Dependencies:   CC1200

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!

SerialStream.h

Committer:
MultipleMonomials
Date:
2020-08-28
Revision:
1:7e7812669c9c
Parent:
0:ea2678a73bde

File content as of revision 1:7e7812669c9c:

#ifndef SERIALSTREAM_H
#define SERIALSTREAM_H

#include <mbed.h>
#include <platform/Stream.h>

/**
 * SerialStream
 * Bringing MBed serial ports back like it's 1999... or at least 2019.
 *
 * This class adapts an MBed 6.0 serial port class into a Stream instance.
 * This lets you do two useful things with it:
 * - Call printf() and scanf() on it
 * - Pass it to code that expects a Stream to print things on.
 *
 */
template<class SerialClass>
class SerialStream : public Stream
{
	SerialClass & serialClass;

public:

	/**
	 * Create a SerialStream from a serial port.
	 * @param _serialClass BufferedSerial or UnbufferedSerial instance
	 * @param name The name of the stream associated with this serial port (optional)
	 */
	SerialStream(SerialClass & _serialClass, const char *name = nullptr):
	Stream(name),
	serialClass(_serialClass)
	{
	}


private:

	// override Stream::read() and write() to call serial class directly.
	// This avoids the overhead of feeding in individual characters.
	virtual ssize_t write(const void *buffer, size_t length)
	{
		return serialClass.write(buffer, length);
	}

	virtual ssize_t read(void *buffer, size_t length)
	{
		return serialClass.read(buffer, length);
	}

	// Dummy implementations -- these will never be called because we override write() and read() instead.
	// but we have to override them since they're pure virtual.
	virtual int _putc(int c) { return 0; }
	virtual int _getc() { return 0; }
};

#endif //SERIALSTREAM_H