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!