Hello!
As a complete beginner with pin related stuff, I started practicing GPIO/SPI usage with MCP23X17 GPIO expander board. I'll be using the dedicated SPI pins for connections towards Linux and USART pins for GPIO expander.
However, I'm facing difficulties getting anything working from SAME70 board outwards. From using tracepoints, I can see the program goes to the second io_write(...), but hangs a minute without affecting the expander.
I haven't modified anything but the main.c from the default Atmel START project generated with the settings written in the code as comment.
#include <atmel_start.h>
/*
Atmel START configs:
SPI Master Sync:
Pins[CS, SCK, MISO, MOSI]: PB3, PB13, PB0, PB1
Speed: 500 kHz
Character size: 8 bits
Baud rate: 500 kHz
*/// Copied from diver_examples.c, just modified the signal to these two arrays
static uint8_t reset_arr[3] = {0b01000000, 0b00001001, 0b00000000};
static uint8_t led_arr[3] = {0b01000000, 0b00001001, 0b11110000};
static const uint16_t sleep_time = 1000;static struct io_descriptor* SPI_0_expander_example(void)
{
struct io_descriptor *io;
spi_m_sync_get_io_descriptor(&SPI_0, &io);spi_m_sync_enable(&SPI_0);
return io;
}int main(void)
{
/* Initializes MCU, drivers and middleware */
atmel_start_init();
struct io_descriptor *io = SPI_0_expander_example();
/* Replace with your application code */
while (1) {
io_write(io, reset_arr, 3);
delay_ms(sleep_time);
io_write(io, led_arr, 3);
delay_ms(sleep_time);
}
}
I suspect the problem could be my configs for the Atmel START. It could be that I'm just misunderstanding the whole system for choosing the pins for SPI from USART, which would mean I'm missing something like CS completely or something. Or I might not have realised some settings I need to sync with the expander.
Any advice where I'm going wrong?
EDIT: Fixed the first mistake, used sleep() instead of delay_ms() in the program
EDIT2: Updated the problem from the above fix
EDIT3: I've certainly missed something... I'm getting some leds lit up and staying lit every now and then when I try to get only the left ones blinking. Am I missing some definitions for the speed or are the SPI modes somehow different? Or could the addressing the expander and it's pins be incorrect?