SAM4E16E - X-PRO : Problem with the SPI Communication

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

Fabien
Posts: 2
Joined: Wed Dec 10, 2014 1:36 pm

SAM4E16E - X-PRO : Problem with the SPI Communication

Fri Dec 19, 2014 3:15 pm

Hello all,

I am a student in an internship and I have started a new project with the SAM4E16E - XPRO and I would like to send data to an evaluation board (for the ADE7878 component) using the SPI communication.

For now, I am trying to use the ''Quick start guide for SAM SPI driver" after adding - with the ASF Wizard :
- SPI - Common USART SPI Mater and Standard SPI
- SPI - Serial Peripheral interface
- System Clock Control - SAM4E implementation
- And GPIO - General purpose Input/Output to my project.

I have also tried to use different informations from different topics for compiling my code, without results.
In fact, I am still unable to see any clock signals (SPI_SCK PA14) or other data from MOSI, MISO or CHIP SELECT pins (PA13, PA12, ...).

So, What am I doing wrong with SPI Service from Atmel Software Framework ?  

These are the initialization functions:

Code: Select all

void spi_master_initialize(void)
{											
	spi_enable_clock(SPI);
	spi_reset(SPI);
	spi_set_master_mode(SPI);
	spi_disable_mode_fault_detect(SPI);
	spi_disable_loopback(SPI);
	spi_set_peripheral_chip_select_value(SPI,spi_get_pcs(SPI_CHIP_SEL)); 
	spi_set_fixed_peripheral_select(SPI);
	spi_disable_peripheral_select_decode(SPI);
	spi_set_delay_between_chip_select(SPI, CONFIG_SPI_MASTER_DELAY_BCS);
	spi_enable(SPI);
}

void spi_master_set_up(void)
{
	spi_set_transfer_delay(SPI, SPI_CHIP_SEL, CONFIG_SPI_MASTER_DELAY_BS,
	CONFIG_SPI_MASTER_DELAY_BCT);
spi_set_bits_per_transfer(SPI, SPI_CHIP_SEL, CONFIG_SPI_MASTER_BITS_PER_TRANSFER);
	spi_set_baudrate_div(SPI, SPI_CHIP_SEL, 2);
	spi_calc_baudrate_div(BAUDRATE, sysclk_get_cpu_hz());
	spi_configure_cs_behavior(SPI, SPI_CHIP_SEL, SPI_CS_KEEP_LOW);
	spi_set_clock_polarity(SPI, SPI_CHIP_SEL, SPI_CLK_POLARITY);
	spi_set_clock_phase(SPI, SPI_CHIP_SEL, SPI_CLK_PHASE);
}

void spi_init_pin(void) {
	
	pio_configure_pin(SPI_MOSI_GPIO, SPI_MOSI_FLAGS);
	pio_configure_pin(SPI_MISO_GPIO, SPI_MISO_FLAGS);
	pio_configure_pin(SPI_SPCK_GPIO, SPI_SPCK_FLAGS);
	pio_configure_pin(SPI_NPCS1_PB14_GPIO, SPI_NPCS1_PB14_FLAGS);
}
And this is the implementation:

Code: Select all

int main (void)
{
	struct spi_device spi_device_conf = {
		.id = 0									///id?
	};

	status_code_t status;
	
	uint32_t myBaudRate = 100000;
	uint32_t mySPIselect = 0;
	uint8_t data_buffer[1] = {0xAA};
	
	board_init();
	sysclk_init();

	spi_master_initialize();
	spi_master_set_up();
	spi_init_pin();
	
	spi_master_init(SPI);
	spi_master_setup_device(SPI, &spi_device_conf, SPI_MODE_0, myBaudRate, mySPIselect);

while (1) {
		spi_select_device(SPI, &spi_device_conf);
		spi_write_packet(SPI, data_buffer, 1);
		spi_deselect_device(SPI, &spi_device_conf);
	}
with :

Code: Select all

#define SPI_CHIP_SEL                  0      // Chip select.
#define SPI_CHIP_PCS                  spi_get_pcs(SPI_CHIP_SEL)
#define SPI_CLK_POLARITY              0      // Clock polarity.
#define SPI_CLK_PHASE                 0      // Clock phase.
#define SPI_DLYBS                     0x10   // Delay before SPCK.
#define SPI_DLYBCT                    0x10   // Delay between consecutive transfers.
#define BAUDRATE					  100000 // Baud rate
If anyone has a simple code..
Thanks for any help.
jma
Posts: 7
Joined: Wed Oct 22, 2014 4:04 am

Re: SAM4E16E - X-PRO : Problem with the SPI Communication

Wed Dec 24, 2014 1:55 am

I think that you might want to take "spi_enable(SPI)" our of "spi_master_initialize" and call it after the call to "spi_master_setup_device"
Fabien
Posts: 2
Joined: Wed Dec 10, 2014 1:36 pm

Re: SAM4E16E - X-PRO : Problem with the SPI Communication

Mon Dec 29, 2014 12:17 pm

Thank you for your reply. I did it but I am still unable to see anything from my outputs..

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests