SPI Master - Polled Data Transfer

Discussions around product based on ARM Cortex M0+ core.

Moderator: nferre

AGS
Posts: 9
Joined: Wed Jul 23, 2014 3:30 am

SPI Master - Polled Data Transfer

Wed Jul 23, 2014 4:05 am

Hi,

I'm new to Atmel-SAMD20 community, I used AT03255 to write the sample code below to send data using SPI bus, when I compile I get errors all over: for storage size unknown, implicit declaration of function, even PIN_PB04 undeclared, slave undeclared, spi_master_instance udeclared etc, I downloaded the quick start guide for SERCOM SPI Master - Polled, I have all the header files and SPI pin definitions in my solution expl env.
I know that the return statement in SPI_RW is not correct, is there anything else going on in configure_spi_master() or in SPI_init() that is causing all the compilation issue? Thanks for your guidance.

Code: Select all

void configure_spi_master(void)
{
struct spi_config config_spi_master;
struct spi_slave_inst_config slave_dev_config;
struct spi_slave_inst slave;

spi_slave_inst_get_config_defaults(&slave_dev_config);
slave_dev_config.ss_pin = EXT1_PIN_SPI_SS_0;

spi_attach_slave(&slave, &slave_dev_config);
spi_get_config_defaults(&config_spi_master);

config_spi_master.mux_setting = EXT1_SPI_SERCOM_MUX_SETTING;

config_spi_master.pinmux_pad0 = EXT1_SPI_SERCOM_PINMUX_PAD0;
config_spi_master.pinmux_pad1 = PINMUX_UNUSED;
config_spi_master.pinmux_pad2 = EXT1_SPI_SERCOM_PINMUX_PAD2;
config_spi_master.pinmux_pad3 = EXT1_SPI_SERCOM_PINMUX_PAD3;

spi_init(&spi_master_instance, EXT1_SPI_MODULE, &config_spi_master);
spi_enable(&spi_master_instance);	
}

void SPI_init(void)
{
	system_init(); 
	configure_spi_master();
	spi_select_slave(&spi_master_instance, &slave, true);
}
 
 
 unit8_t SPI_RW (unsigned char Data)
 {
	 while (spi_is_ready_to_write(&spi_master_instance));
	 spi_write(&spi_master_instance, Data);
	 while (spi_is_ready_to_read(&spi_master_instance)) 
	 
	// return *(spi_read(&spi_master_instance, &Data));
	
	 return Data;   // which line is correct ?
}
 
void SPI_Send ( unsigned char *Data, uint8_t Length,uint8_t IsLastCSHigh)
{
   	bool tc_busy_state = port_pin_get_input_level(PIN_PB04);
	   
	   while(!tc_busy_state);
	   delay_us(TBUSY);
	   tc_cs_low();
	   delay_us(TS);
	   while(Length--)
	   {
	    SPI_RW(*Data++);	
		delay_us(TB);
	   }
	if(IsLastCSHigh)
	{
		delay_us(TE);
		tc_cs_high ();	
   		delay_us(TA);
	}
}
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: SPI Master - Polled Data Transfer

Wed Jul 23, 2014 6:24 am

It would help, if you posted some of the compilation errors you are receiving.
AGS
Posts: 9
Joined: Wed Jul 23, 2014 3:30 am

Re: SPI Master - Polled Data Transfer

Wed Jul 23, 2014 7:19 am

  • Here are the errors:

    Error 12 'EXT1_PIN_SPI_SS_0' undeclared (first use in this function)
    Error 26 'EXT1_SPI_MODULE' undeclared (first use in this function)
    Error 18 'EXT1_SPI_SERCOM_MUX_SETTING' undeclared (first use in this function)
    Error 19 'EXT1_SPI_SERCOM_PINMUX_PAD0' undeclared (first use in this function)
    Error 21 My_SPI_QUICK_START_MASTER1(master_polled)
    Error 22 'EXT1_SPI_SERCOM_PINMUX_PAD3' undeclared (first use in this function)
    Error 49 'PIN_PB04' undeclared (first use in this function)
    Error 52 'PIN_PB04' undeclared (first use in this function)
    Error 20 'PINMUX_UNUSED' undeclared (first use in this function)
    Error 37 'slave' undeclared (first use in this function)
    Error 25 'spi_master_instance' undeclared (first use in this function)
    Error 36 'spi_master_instance' undeclared (first use in this function)
    Error 42 'spi_master_instance' undeclared (first use in this function)
    Error 50 implicit declaration of function 'delay_us'
    Error 47 implicit declaration of function 'port_pin_get_input_level' [-Werror=implicit-function-declaration]
    Error 14 implicit declaration of function 'spi_attach_slave' [-Werror=implicit-function-declaration] My_SPI_QUICK_START_MASTER1(master_polled)
    Error 27 implicit declaration of function 'spi_enable' [-Werror=implicit-function-declaration]
    Error 16 implicit declaration of function 'spi_get_config_defaults' [-Werror=implicit-function-declaration] My_SPI_QUICK_START_MASTER1(master_polled)
    Error 23 implicit declaration of function 'spi_init' [-Werror=implicit-function-declaration]
    Error 45 implicit declaration of function 'spi_is_ready_to_read' [-Werror=implicit-function-declaration]
    Error 40 implicit declaration of function 'spi_is_ready_to_write' [-Werror=implicit-function-declaration]
    Error 34 implicit declaration of function 'spi_select_slave' [-Werror=implicit-function-declaration]
    Error 10 implicit declaration of function 'spi_slave_inst_get_config_defaults' [-Werror=implicit-function-declaration]
    Error 43 implicit declaration of function 'spi_write' [-Werror=implicit-function-declaration]
    Error 32 implicit declaration of function 'system_init' [-Werror=implicit-function-declaration]
    Error 7 storage size of 'config_spi_master' isn't known
    Error 9 storage size of 'slave' isn't known
    Error 8 storage size of 'slave_dev_config' isn't known
    Error 38 unknown type name 'unit8_t'
AGS
Posts: 9
Joined: Wed Jul 23, 2014 3:30 am

Re: SPI Master - Polled Data Transfer

Wed Jul 23, 2014 9:54 am

I downloaded the example code using Quickstart example project and I have hundreds of .h files in my solution explorer, I also have my own .h file that goes with the SPI functions I created. Sounds like something basic is not taken care of, I'll investigate that. In the meantime, do you see any mistake in calling the functions or passing the parameters to the functions in the ASF code that I'm using?
jharley
Posts: 238
Joined: Thu Dec 06, 2012 6:40 am

Re: SPI Master - Polled Data Transfer

Wed Jul 23, 2014 2:26 pm

AGS wrote:I have hundreds of .h files in my solution explorer, I also have my own .h file that goes with the SPI functions I created
Do you also have any #include directives at the top of this file? Most of your errors are related to not having the correct #include directives in this file.

These should be declared as global scope variables, in this file.
AGS wrote:Error 37 'slave' undeclared (first use in this function)
Error 25 'spi_master_instance' undeclared (first use in this function)
Errors like this are telling you that the functions are missing prototypes, i.e. they should be declared in an 'h' file if they are global, then the 'h' file needs to be #include in this file. If they are local in scope they should be prototyped at the top of this file.
AGS wrote:Error 23 implicit declaration of function 'spi_init' [-Werror=implicit-function-declaration]
Error 45 implicit declaration of function 'spi_is_ready_to_read' [-Werror=implicit-function-declaration]
We cannot teach you 'C' programming here, and it appears that you are fairly new to the language.
I would recommend finding a tutorial on 'C' programming to assist you.

There are 1000's of free 'C' tutorials on-line, here are some links: one that discusses 'scope', and the other that discusses function prototyping. As most of your errors appear to be related to a proper understanding of these concepts.
http://crasseux.com/books/ctutorial/Scope.html
http://crasseux.com/books/ctutorial/Fun ... rototyping

Return to “SAM D20 Cortex-M0+ MCU”

Who is online

Users browsing this forum: No registered users and 1 guest