[phpBB Debug] PHP Warning: in file /mnt/forum-shared/ext/sitesplat/BBCore/event/listener.php on line 70: in_array() expects parameter 2 to be array, boolean given
SAM3X SPI troubleshooting - SparkFun Electronics

SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By OnyxIbex
#180455
I am using a custom board SAM3X8C and am having some trouble programming (Atmel Studio 6) the SPI interface to work with my ILI9341 LCD. The LCD module works with a separate board using an atmega2560 so I don’t believe the fault to be with the LCD itself. When I run the code provided below all I see is a blank screen (the backlight is on whenever there is power). All I am trying to accomplish is the fill the screen an arbitrary color (I can hopefully figure out the rest from there).

I am trying to use the ASF library for the “LCD - ILI9341 Display Controller (component)”. Following the example provided by Atmel’s ASF documentation (http://asf.atmel.com/docs/latest/sam3x/ ... group.html and http://asf.atmel.com/docs/latest/sam3x/ ... 41_qs.html) I have configured the conf_ili9341 header file as such:
Code: Select all
#define CONF_ILI9341_CLOCK_SPEED		8000000UL
#define CONF_ILI9341_SPI			SPI0
#define CONF_ILI9341_CS_PIN			PIO_PA28_IDX
#define CONF_ILI9341_DC_PIN			PIO_PB3_IDX
#define CONF_ILI9341_BACKLIGHT_PIN	PIO_PA21_IDX
#define CONF_ILI9341_RESET_PIN		PIO_PA29_IDX
The hardware side has been checked and re-checked over and over and looks correct. Following the datasheet I have SPI0 configured to use peripheral A and the pinout is reflected in the initialization inside main().
Code: Select all
#include "asf.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_ili9341.h"

int main(void)
{
	sysclk_init();
	board_init();
	
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA25A_SPI0_MISO);
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA26A_SPI0_MOSI);
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA27A_SPI0_SPCK);
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA28A_SPI0_NPCS0);
	
	pmc_enable_periph_clk(ID_SPI0);
	
	ili9341_init();
	ili9341_backlight_on();
	ili9341_set_top_left_limit(0, 0);
	ili9341_set_bottom_right_limit(240, 320);
	ili9341_duplicate_pixel(ILI9341_COLOR(200, 20, 130), 240UL * 320UL);
}
Can anyone offer any suggestions on where to troubleshoot next or different code to try? Maybe I am just missing part of the SPI or LCD initialization. I am at a loss right now. I don’t have a scope to monitor the SPI lines unfortunately. I know the ASF wizard can be a bit funky to use correctly, so if anyone thinks that is the problem, could you suggest the right way to do it? Any and all feedback will be greatly appreciated!
By OnyxIbex
#180483
The following code workflow solved my issue.
Code: Select all
sysclk_init();
	board_init();
	
	pmc_enable_periph_clk(ID_PIOA);
	pmc_enable_periph_clk(ID_PIOB);
	
	pio_set_output(PIOA, PIO_PA29, LOW, DISABLE, ENABLE);	// reset
	pio_set_output(PIOB, PIO_PB3, LOW, DISABLE, ENABLE);	// dcx
	
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA25A_SPI0_MISO);
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA26A_SPI0_MOSI);
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA27A_SPI0_SPCK);
	pio_set_peripheral(PIOA, PIO_PERIPH_A, PIO_PA28A_SPI0_NPCS0);
	
	pmc_enable_periph_clk(ID_SPI0);
	
	spi_enable(SPI0);
	spi_master_init(SPI0);
	
	ili9341_init();
	ili9341_backlight_on();
	ili9341_set_top_left_limit(0, 0);
	ili9341_set_bottom_right_limit(320, 240);
   ili9341_duplicate_pixel(ILI9341_COLOR(200, 20, 130), 240UL * 320UL);
Thanks anyways! Hopefully this will help someone like me in the future. It could probably be simplified a lot anyways.