1

I am stuck on what I think is quite easy task for anyone with experience and good understanding of low-level programming and/or interfaces. The problem is - I can't quite get the communication with my LIS3DH accelerometer done.

The setup I'm working on is:

  • CYC1000 with Cyclone 10 FPGA (Cyclone 10 LP)

  • LIS3DH 3-axis sensor connected with FPGA through SPI and 2 INT lines

As I seem to understand general concept of how SPI works, I can't get grasp on how to actually do pratical stuff on my FPGA board.

I'm using Quartus II Lite, I've setup the system using Platform Designer which .qsys file you can lookup on the google drive link right here: mcu.qsys and top.sv While I'm almost sure the stuff there is fine, I would appreciate any hints you would have for me.

Now, based on my knowledge I've got from Embedded Peripherals IP User Guide - Intel there is an access routine provided by single function called

alt_u32 base, alt_u32 slave, alt_u32 write_length, const alt_u8* wdata,
                       alt_u32 read_length,
                       alt_u8* read_data,
                       alt_u32 flags

the problem is - I don't quite get which values should I put in there. Starting of with first - base - is it my SPI_BASE (base address of spi slave) When I've run the code that was something like this:

int x = alt_avalon_spi_command(SPI_BASE, 0, 16, data_in, 16, data_out, 0);

the program was stuck somewhere during my infinite loop in altera_avalon_spi.c code file

do
{
status = IORD_ALTERA_AVALON_SPI_STATUS(base);
}
while (((status & ALTERA_AVALON_SPI_STATUS_TRDY_MSK) == 0 || credits == 0) &&
        (status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0);

the status in debug window would get values either 512 or 0 depending on start or end of the do/while, then it just terminates with exit value 0 (while normal Run doesn't pop up any errors).

Also, as I would expect, that to actually run the accelerometer you should first tell it how it should work - set some registers and stuff set up like shown eg. here The question is - how do I actually do that? Am I doing it all bad from the beggining, missing some important piece of a puzzle in the system project (.qsys and .sv files)?

I would greatly appreciate ANY hint, material or tutorial to study about the topic or basics that I should know - please don't trash me too hard :)

Edit : Ok so basically as I expected, setting up the sensor happens in write_data parameter of alt_avalon_spi_command. Other mistake I've made, at least in my case, was to set SPI as a slave - switching it to Master got me solution as I'm no longer stuck in do/while loop. It doesn't pay off being stubborn and not looking on example provided by manufacturer - given some time I've understood my mistakes and the process, question closed!

Kacper S.
  • 11
  • 2
  • the link is to a .xml file and a .sv file. What is a .sv file? What do you expect us to do with the .xml file? – user3629249 Aug 25 '19 at 22:26
  • Please post the `altera_avalon_spi.c` file and indicate exactly where in that file the code is 'stuck' – user3629249 Aug 25 '19 at 22:28
  • Well, opening .qsys as a text file is a .xml. It is quartus platform designer file as I've mentioned in my question. .sv file is a system verilog format, it contains the initialization of the design from Platform Designer. I've of course set the pins accordingly to the documentation of the CYC1000 module. I will post .c file asap – Kacper S. Aug 26 '19 at 07:06
  • [here](https://github.com/osafune/peridot/blob/master/fpga/peridot_lcdunit/software/lcdunit_ckplay_bsp/drivers/src/altera_avalon_spi.c) is source code from some repository I found on google, they are the same since it's generated file. It stucks (keeps repeating forever) on 82 line's do/while. I'm quite sure I'm missing something in the design, due to my lack of knowledge, yet I can't figure what is it. – Kacper S. Aug 26 '19 at 07:23

0 Answers0