Skip to content

Commit

Permalink
more (not)xbee joint futzing, still doesn't work :(
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Shipman committed Nov 29, 2023
1 parent d62245a commit f0de7af
Show file tree
Hide file tree
Showing 30 changed files with 18,965 additions and 17,430 deletions.
2 changes: 1 addition & 1 deletion Code/XbeeJoint/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pico_enable_stdio_usb(test 1)

pico_add_extra_outputs(test)

target_link_libraries(test pico_stdlib hardware_flash hardware_sync hardware_spi)
target_link_libraries(test pico_stdlib hardware_flash hardware_sync hardware_spi pico_rand)
52 changes: 40 additions & 12 deletions Code/XbeeJoint/test/SX1262.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@
#include "(Not)XBee_Joint.h"
#include "hardware/gpio.h"
#include "hardware/spi.h"
#include "pico/rand.h"
#include "pico/stdlib.h"

spi_inst_t *spi = spi0;

const uint8_t read_reg_cmd = 0x1D;
const uint8_t get_status_cmd = 0xC0;
const uint8_t nop_cmd = 0x00;
const uint8_t addr2 = 0x06;
const uint8_t addr1 = 0xB8;
const uint8_t addr2 = 0x07;
const uint8_t addr1 = 0x40;
uint8_t msg = 0x00;
const uint8_t StdbyConfig = 0x01;
const uint8_t set_standby_cmd = 0x80;
Expand All @@ -42,6 +43,8 @@ const uint8_t set_radio_clear_irq_cmd = SX126X_CMD_CLEAR_IRQ_STATUS;
const uint8_t read_buffer_cmd = SX126X_CMD_READ_BUFFER;
const uint8_t get_irq_status_cmd = SX126X_CMD_GET_IRQ_STATUS;
const uint8_t get_rx_buffer_cmd = SX126X_CMD_GET_RX_BUFFER_STATUS;
const uint8_t set_lora_symb_timeout_cmd = SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT;
const uint8_t calibrate_image_cmd = SX126X_CMD_CALIBRATE_IMAGE;

void radio_init() {
printf("Initializing Radio\n");
Expand Down Expand Up @@ -81,7 +84,7 @@ void radio_init() {
write_radio_buffer();

// Step 8: Set Modulation Parameters
set_radio_modulation_param();
set_radio_lora_modulation_param();

// Step 9: Set Packet Parameters
set_packet_parameters();
Expand All @@ -91,6 +94,11 @@ void radio_init() {

// Step 11: Define Sync Word
set_radio_sync_word();
set_lora_symb_timeout();

// TODO calibrate image

read_radio_registers();
}

void get_radio_status() {
Expand Down Expand Up @@ -127,18 +135,15 @@ void read_radio_registers() {
printf("reg: %x%x\n", addr2, addr1);
gpio_put(CS_PIN, 0);
spi_write_read_blocking(spi, &read_reg_cmd, &msg, 1);
printf("data: %x\n", msg);

spi_write_read_blocking(spi, &addr2, &msg, 1);
printf("data: %x\n", msg);

spi_write_read_blocking(spi, &addr1, &msg, 1);
printf("data: %x\n", msg);

spi_write_read_blocking(spi, &nop_cmd, &msg, 1);
printf("data: %x\n", msg);
printf("status: %x\n", msg);

for (int j = 0; j < 4; j++) {
for (int j = 0; j <= 1; j++) {
spi_write_read_blocking(spi, &nop_cmd, &msg, 1);
printf("read: %x\n", msg);
}
Expand Down Expand Up @@ -229,7 +234,7 @@ void set_radio_rf_freq() {
}

void set_tx_params() {
const uint8_t power = 0x16;
const uint8_t power = 0x0;
const uint8_t ramp_time = 0x04;

gpio_put(CS_PIN, 0);
Expand All @@ -252,16 +257,18 @@ void set_buffer_base_address() {

void write_radio_buffer() {
const uint8_t offset = 0x00;
const uint8_t data = 0x00;
const uint8_t data = (uint8_t)get_rand_32();

gpio_put(CS_PIN, 0);
spi_write_blocking(spi, &write_radio_buffer_cmd, 1);
spi_write_blocking(spi, &offset, 1);
spi_write_blocking(spi, &data, 1);
gpio_put(CS_PIN, 1);

printf("Wrote %x to radio buffer\n", data);
}

void set_radio_modulation_param() {
void set_radio_lora_modulation_param() {
const uint8_t spreading_factor = 0x07;
const uint8_t bandwidth = 0x04;
const uint8_t coding_rate = 0x04;
Expand Down Expand Up @@ -323,6 +330,11 @@ void set_radio_sync_word() {
spi_write_blocking(spi, &msb2, 1);
spi_write_blocking(spi, &msb1, 1);
spi_write_blocking(spi, &data2, 1);
gpio_put(CS_PIN, 1);
sleep_ms(10);

gpio_put(CS_PIN, 0);
spi_write_blocking(spi, &write_radio_register_cmd, 1);
spi_write_blocking(spi, &lsb2, 1);
spi_write_blocking(spi, &lsb1, 1);
spi_write_blocking(spi, &data1, 1);
Expand Down Expand Up @@ -460,7 +472,7 @@ void clear_irq_status() {
}

void read_radio_buffer() {
uint8_t offset = 0x00;
uint8_t offset = 0x7F;

uint8_t buf[20] = {0};

Expand Down Expand Up @@ -528,4 +540,20 @@ void get_rx_buffer_status() {

printf("Payload Length %x\n", length);
printf("Buffer Pointer %x\n", buffer_start);
}

void set_lora_symb_timeout() {
uint8_t symb_num = 0x0F;

spi_write_blocking(spi, &set_lora_symb_timeout_cmd, 1);
spi_write_blocking(spi, &symb_num, 1);
}

void calibrate_image() {
uint8_t freq1 = 0xE1;
uint8_t freq2 = 0xE9;

spi_write_blocking(spi, &calibrate_image_cmd, 1);
spi_write_blocking(spi, &freq1, 1);
spi_write_blocking(spi, &freq2, 1);
}
6 changes: 5 additions & 1 deletion Code/XbeeJoint/test/SX1262.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ void set_radio_packet_type_lora(void);
void set_radio_pa_config(void);
void set_radio_rf_freq(void);
void set_buffer_base_address(void);
void set_radio_modulation_param(void);
void set_radio_lora_modulation_param(void);
void set_dio2_rf_switch(void);
void write_radio_buffer(void);
void set_packet_parameters(void);
Expand All @@ -471,5 +471,9 @@ void clear_irq_status(void);
void get_irq_status(void);
void get_rx_buffer_status(void);
void radio_receive_single(void);
void set_radio_packet_type_fsk(void);
void set_radio_fsk_modulation_param(void);
void set_lora_symb_timeout(void);
void calibrate_image(void);

#endif
2 changes: 1 addition & 1 deletion Code/XbeeJoint/test/build/CMakeCache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ PICO_BOOT_STAGE2_DIR:INTERNAL=/Users/michaelshipman/Developer/command_module/Cod
PICO_CMAKE_PRELOAD_PLATFORM_DIR:INTERNAL=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/cmake/preload/platforms
PICO_CMAKE_PRELOAD_PLATFORM_FILE:INTERNAL=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/cmake/preload/platforms/rp2040.cmake
PICO_COMPILER_ASM:INTERNAL=/opt/homebrew/bin/arm-none-eabi-gcc
PICO_DOXYGEN_EXCLUDE_PATHS:INTERNAL= /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/cmsis /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/cmsis /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs
PICO_DOXYGEN_EXCLUDE_PATHS:INTERNAL= /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/cmsis /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/cmsis /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/cmsis /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/cmsis /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs
PICO_DOXYGEN_PATHS:INTERNAL= /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/common /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/lib/cyw43-driver/src /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040
PICO_NO_HARDWARE:INTERNAL=0
PICO_ON_DEVICE:INTERNAL=1
Expand Down
8 changes: 4 additions & 4 deletions Code/XbeeJoint/test/build/CMakeFiles/Makefile2
Original file line number Diff line number Diff line change
Expand Up @@ -1507,12 +1507,12 @@ CMakeFiles/test.dir/all: CMakeFiles/ELF2UF2Build.dir/all
CMakeFiles/test.dir/all: pico-sdk/src/rp2_common/boot_stage2/CMakeFiles/bs2_default_padded_checksummed_asm.dir/all
$(MAKE) $(MAKESILENT) -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
$(MAKE) $(MAKESILENT) -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles --progress-num=23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96 "Built target test"
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles --progress-num=23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97 "Built target test"
.PHONY : CMakeFiles/test.dir/all

# Build rule for subdir invocation for target.
CMakeFiles/test.dir/rule: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles 86
$(CMAKE_COMMAND) -E cmake_progress_start /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles 87
$(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 CMakeFiles/test.dir/all
$(CMAKE_COMMAND) -E cmake_progress_start /Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles 0
.PHONY : CMakeFiles/test.dir/rule
Expand Down Expand Up @@ -1663,7 +1663,7 @@ pico-sdk/src/rp2_common/tinyusb/CMakeFiles/PioasmBuild.dir/clean:
pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir/all: pico-sdk/src/rp2_common/tinyusb/CMakeFiles/PioasmBuild.dir/all
$(MAKE) $(MAKESILENT) -f pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir/build.make pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir/depend
$(MAKE) $(MAKESILENT) -f pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir/build.make pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir/build
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles --progress-num=98 "Built target tinyusb_pico_pio_usb_usb_tx_pio_h"
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles --progress-num=99 "Built target tinyusb_pico_pio_usb_usb_tx_pio_h"
.PHONY : pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir/all

# Build rule for subdir invocation for target.
Expand All @@ -1689,7 +1689,7 @@ pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_tx_pio_h.dir
pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_rx_pio_h.dir/all: pico-sdk/src/rp2_common/tinyusb/CMakeFiles/PioasmBuild.dir/all
$(MAKE) $(MAKESILENT) -f pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_rx_pio_h.dir/build.make pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_rx_pio_h.dir/depend
$(MAKE) $(MAKESILENT) -f pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_rx_pio_h.dir/build.make pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_rx_pio_h.dir/build
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles --progress-num=97 "Built target tinyusb_pico_pio_usb_usb_rx_pio_h"
@$(CMAKE_COMMAND) -E cmake_echo_color "--switch=$(COLOR)" --progress-dir=/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/test/build/CMakeFiles --progress-num=98 "Built target tinyusb_pico_pio_usb_usb_rx_pio_h"
.PHONY : pico-sdk/src/rp2_common/tinyusb/CMakeFiles/tinyusb_pico_pio_usb_usb_rx_pio_h.dir/all

# Build rule for subdir invocation for target.
Expand Down
2 changes: 1 addition & 1 deletion Code/XbeeJoint/test/build/CMakeFiles/progress.marks
Original file line number Diff line number Diff line change
@@ -1 +1 @@
94
95
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(CMAKE_TARGET_DEFINITIONS_ASM
"LIB_PICO_PLATFORM=1"
"LIB_PICO_PRINTF=1"
"LIB_PICO_PRINTF_PICO=1"
"LIB_PICO_RAND=1"
"LIB_PICO_RUNTIME=1"
"LIB_PICO_STANDARD_LINK=1"
"LIB_PICO_STDIO=1"
Expand Down Expand Up @@ -118,6 +119,7 @@ set(CMAKE_ASM_TARGET_INCLUDE_PATH
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/lib/tinyusb/hw"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/include"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/hardware_spi/include"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_rand/include"
)

# The set of dependency files which are needed:
Expand Down Expand Up @@ -172,6 +174,7 @@ set(CMAKE_DEPENDS_DEPENDENCY_FILES
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_malloc/pico_malloc.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_malloc/pico_malloc.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_malloc/pico_malloc.c.obj.d"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_platform/platform.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_platform/platform.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_platform/platform.c.obj.d"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_printf/printf.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_printf/printf.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_printf/printf.c.obj.d"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_rand/rand.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_rand/rand.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_rand/rand.c.obj.d"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_runtime/runtime.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_runtime/runtime.c.obj.d"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_standard_link/binary_info.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_standard_link/binary_info.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_standard_link/binary_info.c.obj.d"
"/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_stdio/stdio.c" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj" "gcc" "CMakeFiles/test.dir/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_stdio/stdio.c.obj.d"
Expand Down
Binary file modified Code/XbeeJoint/test/build/CMakeFiles/test.dir/SX1262.cpp.obj
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ CMakeFiles/test.dir/SX1262.cpp.obj: \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_structs/include/hardware/structs/spi.h \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs/include/hardware/regs/spi.h \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2040/hardware_regs/include/hardware/regs/dreq.h \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_rand/include/pico/rand.h \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/common/pico_stdlib/include/pico/stdlib.h \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/rp2_common/pico_stdio/include/pico/stdio.h \
/Users/michaelshipman/Developer/command_module/Code/XbeeJoint/pico-sdk/src/common/pico_time/include/pico/time.h \
Expand Down
Binary file not shown.
Loading

0 comments on commit f0de7af

Please sign in to comment.