Start work on testing SPI interface, looks like the AT86RF215 might be dead
This commit is contained in:
parent
ad4621cb2e
commit
e93f115c23
|
@ -66,7 +66,9 @@ static void parse_and_execute_cmd(const uint8_t* s, int c_len) {
|
|||
|
||||
if (is_read) {
|
||||
// we're good, time to execute
|
||||
//puts("doing read\n");
|
||||
spi_register_read(addr, buf, len);
|
||||
//puts("read finish\n");
|
||||
uint8_t output_str[3*sizeof(buf) + 1];
|
||||
for (int i = 0; i < len; i++) {
|
||||
output_str[3*i] = tohex[(buf[i] >> 4) & 0xf];
|
||||
|
|
|
@ -76,12 +76,12 @@ static void dump_expected(struct test_case* tc) {
|
|||
}
|
||||
|
||||
int main() {
|
||||
const uint8_t test0[] = "r0102 1\n";
|
||||
const uint8_t test1[] = "r1234 1a\n";
|
||||
const uint8_t test2[] = "wffe7 3 11 22 33\n";
|
||||
const uint8_t test0[] = "r0102 1";
|
||||
const uint8_t test1[] = "r1234 1a";
|
||||
const uint8_t test2[] = "wffe7 3 11 22 33";
|
||||
const uint8_t test2_buf[] = {0x11, 0x22, 0x33};
|
||||
const uint8_t test3[] = "\n";
|
||||
const uint8_t test4[] = "w1ae7 8 1122 3344 ffee e0 f5\n";
|
||||
const uint8_t test3[] = "";
|
||||
const uint8_t test4[] = "w1ae7 8 1122 3344 ffee e0 f5";
|
||||
const uint8_t test4_buf[] = {0x11, 0x22, 0x33, 0x44, 0xff, 0xee, 0xe0, 0xf5};
|
||||
struct test_case cases[] = {
|
||||
{test0, sizeof(test0), 1, 0, 0x0102, 1, NULL},
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
#include "spi_parser.h"
|
||||
|
||||
#define AT86_RSTN 7
|
||||
#define AT86_RSTN 5
|
||||
|
||||
#define SPI spi0
|
||||
|
||||
static void cs_select() {
|
||||
asm volatile("nop \n nop \n nop");
|
||||
|
@ -22,28 +24,28 @@ static void cs_deselect() {
|
|||
static void spi_register_write(uint16_t address, const uint8_t *buf, uint16_t len) {
|
||||
uint8_t cmd[2] = { address >> 8, address };
|
||||
cmd[0] &= ~(3 << 6); // mask out top two bits
|
||||
cmd[0] |= (2 << 6);
|
||||
// set MODE[0] to set to write
|
||||
// to set MODE to read
|
||||
cs_select();
|
||||
spi_write_blocking(PICO_DEFAULT_SPI, cmd, 2);
|
||||
spi_write_blocking(PICO_DEFAULT_SPI, buf, len);
|
||||
spi_write_blocking(SPI, cmd, 2);
|
||||
spi_write_blocking(SPI, buf, len);
|
||||
cs_deselect();
|
||||
}
|
||||
|
||||
static void spi_register_read(uint16_t address, uint8_t *buf, uint16_t len) {
|
||||
uint8_t cmd[2] = { address >> 8, address };
|
||||
cmd[0] &= ~(3 << 6); // mask out top two bits
|
||||
cmd[0] |= (2 << 6);
|
||||
// set MODE[0] to set to write
|
||||
cs_select();
|
||||
spi_write_blocking(PICO_DEFAULT_SPI, cmd, 2);
|
||||
spi_read_blocking(PICO_DEFAULT_SPI, 0, buf, len);
|
||||
spi_write_blocking(SPI, cmd, 2);
|
||||
spi_read_blocking(SPI, 0, buf, len);
|
||||
cs_deselect();
|
||||
}
|
||||
|
||||
int main() {
|
||||
stdio_init_all();
|
||||
// 10 MHz
|
||||
spi_init(PICO_DEFAULT_SPI, 10*1000*1000);
|
||||
spi_init(SPI, 100*1000);
|
||||
gpio_set_function(PICO_DEFAULT_SPI_RX_PIN, GPIO_FUNC_SPI);
|
||||
gpio_set_function(PICO_DEFAULT_SPI_SCK_PIN, GPIO_FUNC_SPI);
|
||||
gpio_set_function(PICO_DEFAULT_SPI_TX_PIN, GPIO_FUNC_SPI);
|
||||
|
@ -62,18 +64,31 @@ int main() {
|
|||
// UART parse loop
|
||||
int maybe_ch = getchar_timeout_us(1000);
|
||||
if (maybe_ch != PICO_ERROR_TIMEOUT) {
|
||||
if (maybe_ch == 0x0a) {
|
||||
cmd[cmd_idx] = 0;
|
||||
if ((maybe_ch != 0x1b) && (maybe_ch != 0x0d)) {
|
||||
putchar(maybe_ch);
|
||||
}
|
||||
//const char tohex[] = "0123456789abcdef";
|
||||
//putchar(tohex[(maybe_ch >> 4) & 0xf]);
|
||||
//putchar(tohex[maybe_ch & 0xf]);
|
||||
if (maybe_ch == 0x0d) {
|
||||
puts("\r\n");
|
||||
cmd[cmd_idx] = 0;
|
||||
++cmd_idx;
|
||||
// process command
|
||||
/*
|
||||
puts("sending cmd ");
|
||||
for (int i = 0; i < cmd_idx; i++) {
|
||||
const char tohex[] = "0123456789abcdef";
|
||||
putchar(tohex[(cmd[i] >> 4) & 0xf]);
|
||||
putchar(tohex[cmd[i] & 0xf]);
|
||||
}
|
||||
*/
|
||||
parse_and_execute_cmd(cmd, cmd_idx);
|
||||
puts("cmd finished\n");
|
||||
cmd_idx = 0;
|
||||
} else if (maybe_ch == 0x1b) {
|
||||
putchar('^');
|
||||
putchar('\n');
|
||||
cmd_idx = 0;
|
||||
} else {
|
||||
putchar(maybe_ch);
|
||||
cmd[cmd_idx] = maybe_ch;
|
||||
if (cmd_idx < sizeof(cmd)-1) {
|
||||
++cmd_idx;
|
||||
|
|
Loading…
Reference in New Issue