Browse Source

Send my first packet :)

curiousmuch 5 years ago
parent
commit
d2a40825ba
3 changed files with 109 additions and 29 deletions
  1. 87 10
      main/c1120.c
  2. 21 18
      main/cc1120_protocol.h
  3. 1 1
      main/main.c

+ 87 - 10
main/c1120.c

@@ -377,6 +377,8 @@ void cc1120_lut_init(void)
 	}
 }
 
+#define PREAMBLE_LENGTH 20
+#define SUFFIX_LENGTH 1
 
 // test function to generate APRS s1 or s2
 void IRAM_ATTR cc1120_radio_APRSTXPacket(void)
@@ -394,18 +396,59 @@ void IRAM_ATTR cc1120_radio_APRSTXPacket(void)
 	// acquire SPI bus for fastest possible SPI transactions
 	spi_device_acquire_bus(spi, portMAX_DELAY);
 
-	/* Send 0's */
+	int16_t i,j;
 
-	/* Send Flag */
-
-	/* Send Packet */
 	while(1)
 	{
-		int16_t i,j;
+		// start CW transmission
+		cc1120_spi_write_byte(CC112X_FIFO, 0x12);
+		cc1120_spi_strobe(CC112X_STX);
+
+		sample_count = 0;
+		new_sample = 0;
+		/* Send Flag */
+		for (i = 0; i<PREAMBLE_LENGTH; i++)
+		{
+			aprs_flags.byte = 0x7E;
+			for(j=0; j<8; j++)
+			{
+				aprs_flags.cur_bit = aprs_flags.byte & 0x01;
+
+				// NRZ-I Encoding
+				if (aprs_flags.cur_bit)
+				{
+					// do nothing
+					aprs_flags.one_count++;
+
+				}
+				else
+				{
+					aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
+					aprs_flags.one_count = 0;
+				}
+
+				aprs_flags.byte = (aprs_flags.byte >> 1);
+
+				while(sample_count < 11)	// wait for symbol to be sent
+				{
+					if ( new_sample )
+					{
+						LUT_lookup();
+						new_sample = 0;
+					}
+				}
+				sample_count = 0;
+				//printf("Symbol: %x\n", aprs_flags.cur_bit);
+
+			}
+		}
+		aprs_flags.one_count = 0;
+
+		/* Send Packet */
 		for (i=0;i<aprs_flags.packet_len;i++)
 		{
 			aprs_flags.byte = APRS_TEST_PACKET[i];
-			for(j=8;j>0;--j)
+			for(j=0; j<8; j++)
 			{
 				aprs_flags.cur_bit = aprs_flags.byte & 0x01;	// bool of first bit
 
@@ -458,13 +501,47 @@ void IRAM_ATTR cc1120_radio_APRSTXPacket(void)
 				//printf("Symbol: %x\n", aprs_flags.cur_bit);
 			}
 		}
-		vTaskDelay(500/portTICK_PERIOD_MS);
-	}
+		aprs_flags.one_count = 0;
+
+		/* Send Flag */
+		for (i = 0; i<SUFFIX_LENGTH; i++)
+		{
+			aprs_flags.byte = 0x7E;
+			for(j=0; j<8;j++)
+			{
+				aprs_flags.cur_bit = aprs_flags.byte & 0x01;
+
+				// NRZ-I Encoding
+				if (aprs_flags.cur_bit)
+				{
+					// do nothing
+					aprs_flags.one_count++;
+
+				}
+				else
+				{
+					aprs_flags.tone = aprs_flags.tone ^ 1; // switch tone
+					aprs_flags.one_count = 0;
+				}
+
+				aprs_flags.byte = (aprs_flags.byte >> 1);
 
-	/* Send CRC */
+				while(sample_count < 11)	// wait for symbol to be sent
+				{
+					if ( new_sample )
+					{
+						LUT_lookup();
+						new_sample = 0;
+					}
+				}
+				sample_count = 0;
 
-	/* Send Flag */
+			}
+		}
+		cc1120_spi_strobe(CC112X_SIDLE);
 
+		vTaskDelay(10000/portTICK_PERIOD_MS);
+	}
 }
 
 void cc1120_radio_init(const cc1120_reg_settings_t* rf_settings, uint8_t len)

+ 21 - 18
main/cc1120_protocol.h

@@ -12,48 +12,51 @@
 #include <stdint.h>
 #include "cc1120.h"
 
-/* APRS Radio Configuration */
+/* APRS Configuration */
 // Address Config = No address check
-// Bit Rate = 6
+// Bit Rate = 0.825
 // Carrier Frequency = 144.389999
-// Deviation = 5.004883
+// Deviation = 5.004883 (MOVE TO 3kHZ)
 // Device Address = 0
 // Manchester Enable = false
 // Modulation Format = 2-FSK
-// PA Ramping = true
+// PA Ramping = false
 // Packet Bit Length = 0
-// Packet Length = 255
-// Packet Length Mode = Variable
+// Packet Length = 3
+// Packet Length Mode = Not supported
 // Performance Mode = High Performance
-// RX Filter BW = 20.000000
-// Symbol rate = 6
+// RX Filter BW = 15.384615
+// Symbol rate = 0.825
 // TX Power = 15
 // Whitening = false
+
 static const cc1120_reg_settings_t APRS_SETTINGS[]=
 {
-  {CC112X_IOCFG3,            0xB0},
-  {CC112X_IOCFG2,            0x06},
+  {CC112X_IOCFG3,            0x1e},
+  {CC112X_IOCFG2,            0x08},
   {CC112X_IOCFG1,            0xB0},
-  {CC112X_IOCFG0,            0x40},
+  {CC112X_IOCFG0,            0x09},
   {CC112X_SYNC_CFG1,         0x0B},
   {CC112X_DEVIATION_M,       0x48},
   {CC112X_DCFILT_CFG,        0x1C},
-  {CC112X_PREAMBLE_CFG1,     0x18},
+  {CC112X_PREAMBLE_CFG1,     0x00},
   {CC112X_IQIC,              0xC6},
-  {CC112X_CHAN_BW,           0x0A},
+  {CC112X_CHAN_BW,           0x0D},
   {CC112X_MDMCFG0,           0x05},
-  {CC112X_SYMBOL_RATE2,      0x68},
-  {CC112X_SYMBOL_RATE1,      0x93},
-  {CC112X_SYMBOL_RATE0,      0x75},
+  {CC112X_SYMBOL_RATE2,      0x3B},
+  {CC112X_SYMBOL_RATE1,      0x08},
+  {CC112X_SYMBOL_RATE0,      0x9A},
   {CC112X_AGC_REF,           0x20},
   {CC112X_AGC_CS_THR,        0x19},
   {CC112X_AGC_CFG1,          0xA9},
   {CC112X_AGC_CFG0,          0xCF},
   {CC112X_FIFO_CFG,          0x00},
   {CC112X_FS_CFG,            0x1B},
-  {CC112X_PKT_CFG0,          0x20},
+  {CC112X_PKT_CFG2,          0x06},
+  {CC112X_PKT_CFG1,          0x00},
+  {CC112X_PKT_CFG0,          0x40},
+  {CC112X_PA_CFG2,           0x3F},
   {CC112X_PA_CFG0,           0x7E},
-  {CC112X_PKT_LEN,           0xFF},
   {CC112X_IF_MIX_CFG,        0x00},
   {CC112X_FREQOFF_CFG,       0x22},
   {CC112X_CFM_DATA_CFG,      0x01},

+ 1 - 1
main/main.c

@@ -17,7 +17,7 @@ extern uint8_t sample_count;
 
 void IRAM_ATTR app_main()
 {
-	cc1120_radio_init(CW_SETTINGS, sizeof(CW_SETTINGS)/sizeof(cc1120_reg_settings_t));
+	cc1120_radio_init(APRS_SETTINGS, sizeof(APRS_SETTINGS)/sizeof(cc1120_reg_settings_t));
 	vTaskDelay(500/portTICK_PERIOD_MS);
 	cc1120_radio_APRSTXPacket();
 	//xTaskCreatePinnedToCore();