moving from asf3 to 4 - documentation or examples?

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, I wrote this code using ASF3 to write to a spi port and got it to work only because there was fair documentation and examples to use the functions:

 

Here is a snippit of code I used to transmit one byte (taken from the example code)

 

//initialize the port

_gpio_set_direction(GPIO_PORTC,0x0b000000 ,GPIO_DIRECTION_OUT); //set pins as outputs   

//transmit the byte

spi_set_peripheral_chip_select_value(SPI0, SPI_CHIP_SEL);  //set the CS pin used in the SPI
spi_select_device(SPI0, &spi_device_conf); //example uses &SPIC but SPI0 works instead
spi_write_packet(SPI0, data_buffer, 1); //write 1 byte from data buffer to spi
spi_deselect_device(SPI0, &spi_device_conf); //and deselect the lcd (is this the CS line?

 

But I've started a new project using START (asf4?) to see if I coulg get a better jump start on the project but there is no documentation that I can find and no examples.  I'm having trouble with some parameters as well.  For example on this line:

 

_spi_m_sync_disable(struct _spi_m_sync_dev *dev);

 

I can't figure out what to use for struct _spi_m_sync_dev *dev.  I tried using SPI0 but that's the wrong kind of pointer.  The message says:

Message        expected 'struct _spi_sync_dev *' but argument is of type 'Spi * {aka struct <anonymous> *}'  

 

Also I have to figure out how to translate all these commands (taken from an ASF3 example and which seem to work) into the much different START commands but there seems

to be quite a variety of commands in different header files, such as hpl_spi_m_sync.h which I think is the one I should use since I'm using the spi in master mode and master clock (sync mode)

But there are many files to choose from and I'm having a hard time finding the correct substitute calls. 

 

For example here is the AS3 code that works (taken from an example)

 

(code for AS3)

    pio_set_peripheral(PIOD,PIO_TYPE_PIO_PERIPH_B,0x02700000); //the mask is pins 20,21,22,25 which is sdi0 and sdi0 is peripheral b
    // Configure an SPI peripheral.
    spi_enable_clock(SPI0);
    spi_disable(SPI0);
    spi_reset(SPI0);
    spi_set_lastxfer(SPI0);
    spi_set_master_mode(SPI0);
    spi_disable_mode_fault_detect(SPI0);
    spi_set_peripheral_chip_select_value(SPI0, SPI_CHIP_SEL); //1 is the cs output number
    spi_set_clock_polarity(SPI0, SPI_CHIP_SEL, 1);//set the phase
    spi_set_clock_phase(SPI0, SPI_CHIP_SEL, 1); //and polarity both to 1 which is what lcd wants
    spi_set_bits_per_transfer(SPI0, SPI_CHIP_SEL,0); //0 is CS and 0 is 8Bits

 

To translate this to AS4 some calls I can't find:

 

Set the peripheral in the pio?

Enable the clock?

Disable: can use?  _spi_m_sync_disable(struct _spi_m_sync_dev *dev);

Reset?

Set lastxfer?

Set mastermode?

Disable fault detect?

Set peripheral chip select?

Set clock and phase use (MODE_3)?  _spi_m_sync_set_mode(struct _spi_m_sync_dev *dev, const enum spi_transfer_mode mode); 

Set baudrate? _spi_m_sync_set_baudrate(struct _spi_m_sync_dev *dev, const uint32_t baud_val);

Set char size? _spi_m_sync_set_char_size(struct _spi_m_sync_dev *dev, const enum spi_char_size char_size);

and anything else.

 

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nafai wrote:
But I've started a new project using START (asf4?) to see if I coulg get a better jump start on the project but there is no documentation that I can find ...
START, Help tab, left column

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah...thanks, couldn't find that before.

 

Could you answer this one specific question to get me going since I just can't figure it out

 

_spi_m_sync_disable(struct _spi_m_sync_dev *dev);

 

I can't figure out what to use for struct _spi_m_sync_dev *dev.  I tried using SPI0 but that's the wrong kind of pointer.  The message says:

Message        expected 'struct _spi_sync_dev *' but argument is of type 'Spi * {aka struct <anonymous> *}'  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nafai wrote:
Could you answer this one specific question to get me going ...
No (I'm not an ASF operator)

Nafai wrote:
I can't figure out what to use for ...
No answer

A few or several reasons for that; your source code snippet may be correct though "something" is missing outside the snippet.

More than one way to code (multiple solutions to a problem)

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't you have a generated driver_init.c and examples/driver_examples.c to look at?

/Lars

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lajon wrote:

Don't you have a generated driver_init.c and examples/driver_examples.c to look at?

/Lars

 

 

That was very helpful.  Thank you.  I do have the examples.c to look at and found the spi example code there.

     struct io_descriptor *io;
    spi_m_sync_get_io_descriptor(&SPI_0, &io);

    spi_m_sync_enable(&SPI_0);
    io_write(io, example_SPI_0, 12);

 

I was able to get these lines to compile now, but am still baffled about how to learn this.  For example, it calls get_io_descriptor.  How am I suppose to know to call that?  The sync_enable prototype says this:

int32_t _spi_m_sync_enable(struct _spi_m_sync_dev *dev); 

 

How do I interpret that to mean I need to call this function get_io_descriptor to get the sync_dev?  Fortunately in this example it shows me, but what about down the road when I need to get other peripherals running?   

 

I'm used to just writing to registers and getting on with life.  For example, I just need to do this on a hardware level:

Enable the clock to the SPI peripheral

Assign the SPI peripheral to the portio

set the baudrate, word length, mode registers

write to the transmit buffer.

 

Very simple stuff, but it seems I do a lot of right click "Go to Implementation" just to try and figure out what #define to use as a parameter.

 

Since I just got turned on to the Atmel START user guide, I'll read through that and hopefully learn how to just do simple things without having to go through layer after layer after layer of type defs and defines to figure out how to use the correct parameters in a function.

 

Sorry, I'm so bad at this, but I come from the 8052 world where setting up a peripheral is a very simple matter of just writing data to the peripheral registers using basically the same line of code using the address and the data period!  No defines or cryptic typedefs necessary!  The good 'ol days (long gone) where I could write 10 lines of code in an hour instead of 1 line of code in a day. (yes I know I'm being a little cynical, just frustrated)

 

 

 

 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How do I interpret that to mean I need to call this function get_io_descriptor to get the sync_dev

You don't, you call get_io_descriptor to get a io descriptor,  spi_m_sync_init is the function called to setup SPI_0.

I'm used to just writing to registers and getting on with life.

This is still perfectly possible, you are not forced to use Atmel Start and ASF.

 /Lars