Skip to content

Commit

Permalink
Read from all 4 channels on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
jcxldn committed Oct 1, 2023
1 parent 1622a50 commit 060cd22
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "mcp3008/mcp3008.h"
#include "mcp3008/pio/mcp3008_pio.h"
#include "mcp3008/hardware/mcp3008_hardware.h"

extern void *__BUILD_INCLUDES_FLASHLOADER;

Expand Down Expand Up @@ -84,23 +85,48 @@ int main(void)
printf("HELLO, world!");

spi_inst_t *spi = spi0;

// TODO: fix schematic pinout (HW_SPI0)
spi_pinout_t pinout = {
.sck = 2,
.csn = 5,
.miso = 4,
.mosi = 3,
};
spi_dual_inst inst = mcp3008_init_hardware(spi, 3600000, &pinout);
int16_t res = mcp3008_read_hardware(&inst, 1, false);
printf("\nDATA HW_0: %x", res);

spi_inst_t *spi2 = spi1;
spi_pinout_t pinout2 = {
.sck = 10,
.csn = 9,
.miso = 8,
.mosi = 11,
};
spi_dual_inst inst2 = mcp3008_init_hardware(spi2, 3600000, &pinout2);
int16_t res2 = mcp3008_read_hardware(&inst2, 0, false);
printf("\nDATA HW_1: %x", res2);

spi_pinout_t pinout3 = {
.sck = 14,
.csn = 13,
.miso = 12,
.mosi = 15,
};
spi_dual_inst inst3 = mcp3008_init_pio(pio0, 3600000, &pinout3);
uint16_t res3 = mcp3008_read_pio(&inst3, 1, false);
printf("\nDATA PIO_0: %x", res3);

spi_pinout_t pinout4 = {
.sck = 18,
.csn = 17,
.miso = 16,
.mosi = 19,
};
spi_dual_inst inst4 = mcp3008_init_pio(pio1, 3600000, &pinout4);
uint16_t res4 = mcp3008_read_pio(&inst4, 1, false);
printf("\nDATA PIO_1: %x", res4);

// spi_dual_inst inst = mcp3008_init_hardware(spi, 3600000, &pinout);
// true/false has no effect
// uint16_t res = mcp3008_internal_do_adc(&inst, 1, false);

spi_dual_inst inst = mcp3008_init_pio(pio0, 3600000, &pinout);
uint16_t res = mcp3008_read_pio(&inst, 1, false);

printf("\nDATA: %x", res);
printf("\n");

// TinyUSB demos call this after creating tasks.
vTaskStartScheduler();
Expand Down

0 comments on commit 060cd22

Please sign in to comment.