Jamie Smith / CC1200

Dependents:   CC1200-MorseEncoder CC1200-Examples

Files at this revision

API Documentation at this revision

Comitter:
Jamie Smith
Date:
Mon Aug 10 01:30:40 2020 -0700
Parent:
1:98af824b145e
Child:
3:f464b14ce62f
Commit message:
Update to Mbed OS 6. Also fix CC1200::hasReceivedPacket, which has never actually worked until now (whoops)

Changed in this revision

CC1200.cpp Show annotated file Show diff for this revision Revisions of this file
CC1200.h Show annotated file Show diff for this revision Revisions of this file
--- a/CC1200.cpp	Sun Aug 09 23:39:21 2020 -0700
+++ b/CC1200.cpp	Mon Aug 10 01:30:40 2020 -0700
@@ -95,7 +95,7 @@
 	wait_us(100);
 	rst.write(1);
 
-	const float resetTimeout = .01f;
+	const auto resetTimeout = 10ms;
 	Timer timeoutTimer;
 	timeoutTimer.start();
 
@@ -105,7 +105,7 @@
 		wait_us(250);
 		updateState();
 
-		if(timeoutTimer.read() > resetTimeout)
+		if(timeoutTimer.elapsed_time() > resetTimeout)
 		{
 			debugStream->printf("Timeout waiting for ready response from CC1200\n");
 			return false;
@@ -202,9 +202,13 @@
 		return false;
 	}
 
-	// get value of first byte of the packet, which is the length
-	uint8_t rxFirstByteAddr = readRegister(ExtRegister::RXFIRST);
-	uint8_t packetLen = readRXFIFOByte(rxFirstByteAddr);
+	// get value of first byte of the packet, which is the length.
+
+	// The datasheet is wrong about this!  It says that the first byte in the RX FIFO can
+	// be found by accessing address RXFIRST via direct fifo access.
+	// However, in my own testing, RXFIRST points to the second entry in the FIFO, and
+	// the first entry must be accessed through RXFIFO_PRE_BUF.
+	uint8_t packetLen = readRegister(ExtRegister::RXFIFO_PRE_BUF);
 
 	// if we have received a full packet's worth of bytes, then we have received a full packet.
 	return bytesReceived >= static_cast<size_t>(packetLen + 1); // Add one because length field does not include itself
@@ -918,11 +922,12 @@
 {
 	spi.select();
 	loadStatusByte(spi.write(CC1200_READ | CC1200_MEM_ACCESS));
-	uint8_t value = spi.write(CC1200_RX_FIFO | address);
+	spi.write(CC1200_RX_FIFO | address);
+	int value = spi.write(0);
 	spi.deselect();
 
 #if CC1200_REGISTER_LEVEL_DEBUG
-	debugStream->printf("Read RX FIFO[0x%" PRIx8 "] -> 0x%" PRIx8 "\n", static_cast<uint8_t>(address), value);
+	debugStream->printf("Read RX FIFO[0x%" PRIx8 "]: 0x%x 0x%x -> 0x%" PRIx8 "\n", static_cast<uint8_t>(address), CC1200_READ | CC1200_MEM_ACCESS, CC1200_RX_FIFO | address, value);
 #endif
 
 	return value;
--- a/CC1200.h	Sun Aug 09 23:39:21 2020 -0700
+++ b/CC1200.h	Mon Aug 10 01:30:40 2020 -0700
@@ -6,6 +6,7 @@
 #define LIGHTSPEEDRANGEFINDER_CC1200_H
 
 #include <mbed.h>
+#include <Stream.h>
 
 #include <cstdint>
 
@@ -137,13 +138,15 @@
 		TXLAST = 0xD5,
 		NUM_TXBYTES = 0xD6,
 		NUM_RXBYTES = 0xD7,
+		//...
+		RXFIFO_PRE_BUF = 0xDA
 	};
 
 	// Command strobe definitions.  See user guide section 3.2.2
 	enum class Command : uint8_t
 	{
 		SOFT_RESET = 0x30,
-		ENABLE_FREQ_SYNTH = 0x31,
+		FAST_TX_ON = 0x31,
 		OSC_OFF = 0x32,
 		CAL_FREQ_SYNTH = 0x33,
 		RX = 0x34,