Sorry didn't think to do that. Here is the python.And here is the most recent of the C program.
Code:
import machineimport utimeimport ustructimport sysimport array as arr############################################################################# Settings# Assign chip select (CS) pin (and start it high)cs = machine.Pin(17, machine.Pin.OUT)ce = machine.Pin(13, machine.Pin.OUT)# Initialize SPIspi = machine.SPI(0, baudrate=1000000, polarity=1, phase=0, bits=8, firstbit=machine.SPI.MSB, sck=machine.Pin(18), mosi=machine.Pin(19), miso=machine.Pin(16))################################################################################ Functionsdef reg_write(spi, cs, data): """ Write 1 byte to the specified register. """ # Construct message (set ~W bit low, MB bit low) msg = bytearray() msg.append((data >> 16) & 0x7F) msg.append((data >> 8) & 0xFF) msg.append(data & 0xFF) # Send out SPI message cs.value(0) spi.write(msg) cs.value(1) ################################################################################ Mainregisters = arr.array('I', [0x7D2288,0x7C0000,0x7B0000,0x7A0000,0x790000,0x780000,0x770000,0x760000,0x750000,0x740000,0x730000,0x727802,0x710000,0x700000,0x6F0000,0x6E0000,0x6D0000,0x6C0000,0x6B0000,0x6A0007,0x694440,0x682710,0x670000,0x660000,0x650000,0x642710,0x630000,0x620000,0x610000,0x600000,0x5F0000,0x5E0000,0x5D0000,0x5C0000,0x5B0000,0x5A0000,0x590000,0x580000,0x570000,0x560000,0x55D800,0x540001,0x530000,0x522800,0x510000,0x50CCCC,0x4F004C,0x4E0001,0x4D0000,0x4C000C,0x4B0840,0x4A0000,0x49003F,0x480001,0x470081,0x46C350,0x450000,0x4403E8,0x430000,0x4201F4,0x410000,0x401388,0x3F0000,0x3E00AF,0x3D00A8,0x3C03E8,0x3B0001,0x3A9001,0x390020,0x380000,0x370000,0x360000,0x350000,0x340421,0x330080,0x320080,0x314180,0x3003E0,0x2F0300,0x2E07F0,0x2DC61F,0x2C1FA3,0x2B0000,0x2A0000,0x290000,0x280000,0x2703E8,0x260000,0x250305,0x24003C,0x230004,0x220010,0x211E01,0x2005BF,0x1FC3E6,0x1E18A6,0x1D0000,0x1C0488,0x1B0002,0x1A0808,0x190624,0x18071A,0x17007C,0x160001,0x150409,0x144848,0x1327B7,0x120064,0x110096,0x100080,0x0F060E,0x0E1820,0x0D4000,0x0C5001,0x0BB018,0x0A10F8,0x090004,0x082000,0x0700B2,0x06C802,0x0530C8,0x040A43,0x030782,0x020500,0x010808,0x00211C])# Start CS pin highcs.value(1)ce.value(1)for x in registers: reg_write(spi, cs, x) Code:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include "pico/stdlib.h" #include "hardware/spi.h" #include "pico/binary_info.h" // SPI Defines // We are going to use SPI 0, and allocate it to the following GPIO pins // Pins can be changed, see the GPIO function select table in the datasheet for information on GPIO assignments #define SPI_PORT spi0 #define PIN_MISO 16 #define PIN_CS 17 #define PIN_SCK 18 #define PIN_MOSI 19 //defines other ports #define RAMPCLK 20 #define RAMPDIR 21 #define SYNC 22 #define CE 13 #define Lines 126 //Defines amount of lines in HexRegisters.txt #define LengthOfData 15 //Defines max length of string int main() { // set of register values to test with programming uint32_t Data[126] = {0x7D2288, 0x7C0000, 0x7B0000, 0x7A0000, 0x790000, 0x780000, 0x770000, 0x760000, 0x750000, 0x740000, 0x730000, 0x727802, 0x710000, 0x700000, 0x6F0000, 0x6E0000, 0x6D0000, 0x6C0000, 0x6B0000, 0x6A0007, 0x694440, 0x680000, 0x670000, 0x660000, 0x650000, 0x640000, 0x630000, 0x620000, 0x610000, 0x600000, 0x5F0000, 0x5E0000, 0x5D0000, 0x5C0000, 0x5B0000, 0x5A0000, 0x590000, 0x580000, 0x570000, 0x560000, 0x550000, 0x540000, 0x530000, 0x520000, 0x510000, 0x500000, 0x4F0000, 0x4E0001, 0x4D0000, 0x4C000C, 0x4B0800, 0x4A0000, 0x49003F, 0x480001, 0x470081, 0x46C350, 0x450000, 0x4403E8, 0x430000, 0x4201F4, 0x410000, 0x401388, 0x3F0000, 0x3E00AF, 0x3D00A8, 0x3C03E8, 0x3B0001, 0x3A9001, 0x390020, 0x380000, 0x370000, 0x360000, 0x350000, 0x340421, 0x330080, 0x320080, 0x314180, 0x3003E0, 0x2F0300, 0x2E07F0, 0x2DC61F, 0x2C1FA3, 0x2B0000, 0x2A0000, 0x290000, 0x280000, 0x2703E8, 0x260000, 0x250305, 0x24003C, 0x230004, 0x220010, 0x211E01, 0x2005BF, 0x1FC3E6, 0x1E18A6, 0x1D0000, 0x1C0488, 0x1B0002, 0x1A0808, 0x190624, 0x18071A, 0x17007C, 0x160001, 0x150409, 0x144848, 0x1327B7, 0x120064, 0x110096, 0x100080, 0x0F060E, 0x0E1820, 0x0D4000, 0x0C5001, 0x0BB018, 0x0A10F8, 0x090004, 0x082000, 0x0700B2, 0x06C802, 0x0530C8, 0x040A43, 0x030782, 0x020500, 0x010808, 0x00211C, }; stdio_init_all(); gpio_init(PIN_CS); gpio_set_dir(PIN_CS, GPIO_OUT); gpio_put(PIN_CS, 1); // SPI initialisation. This example will use SPI at 40MHz. spi_init(SPI_PORT,1000*1000); spi_set_format(SPI_PORT, 8, SPI_CPOL_1, SPI_CPHA_0, SPI_MSB_FIRST); gpio_set_function(PIN_MISO, GPIO_FUNC_SPI); gpio_set_function(PIN_SCK, GPIO_FUNC_SPI); gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI); int length = sizeof(SPI_PORT); memset(SPI_PORT, 0, length); gpio_set_drive_strength(PIN_SCK, GPIO_DRIVE_STRENGTH_12MA); gpio_set_drive_strength(PIN_MOSI, GPIO_DRIVE_STRENGTH_12MA); // Chip select is active-low, so we'll initialise it to a driven-high state gpio_init(RAMPCLK); gpio_init(RAMPDIR); gpio_init(SYNC); gpio_set_dir(RAMPCLK, GPIO_OUT); gpio_set_dir(RAMPDIR, GPIO_OUT); gpio_set_dir(SYNC, GPIO_OUT); gpio_put(RAMPCLK, 0); gpio_put(RAMPDIR, 0); gpio_put(SYNC, 0); gpio_init(CE); gpio_set_dir(CE, GPIO_OUT); gpio_put(CE, 1); sleep_us(500); uint32_t R125data = Data[0]; uint8_t R125value[3]; R125value[0] = (R125data >> 16) & 0x7F; R125value[1] = (R125data >> 8) & 0xFF; R125value[2] = R125data & 0xFF; gpio_put(PIN_CS, 0); spi_write_blocking(SPI_PORT, R125value, 3); gpio_put(PIN_CS, 1); for (int i = 1; i < 126; i++) { uint32_t ROthersData = Data[i]; uint8_t ROtherValue[3]; ROtherValue[0] = (R125data >> 16) & 0x7F; ROtherValue[0] = (ROthersData >> 8) & 0xFF; ROtherValue[1] = ROthersData & 0xFF; gpio_put(PIN_CS, 0); spi_write_blocking(SPI_PORT, ROtherValue, 3); gpio_put(PIN_CS, 1); } gpio_put(PIN_CS, 1); //Should have an output signal with 3000 MHz }Statistics: Posted by JacksonH — Fri Jul 25, 2025 1:11 pm