Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20704 Discussions

How to test a SPI module.

Altera_Forum
Honored Contributor II
1,086 Views

hello, i trying to test an spi module that i add in a system that im using, i used this code but i dont know why there is an error: 

 

/* * principal.c 

* Created on: 11/04/2012 

* Author: RONALD 

*/ 

 

 

 

 

 

# include <stdio.h># include "system.h" 

 

# define ALT_MODULE_CLASS_SPI_1 altera_avalon_spi# define SPI_1_NAME "/dev/SPI_1" 

 

 

int main() 

FILE *fp; 

 

 

printf("Hello from Nios II!\n"); // 

 

 

fp = fopen("/dev/SPI_1","r+"); //opens module spi 

 

 

if(fp==0)//if doesnt exist the module do this 

printf("\nError Opening %s\n\n",SPI_1_BASE); 

else//do this if the module exists 

printf( ""spi comunication success \n"); 

 

 

return 0; 

 

when i run this code for to test the spi module the program shows me ""Error Opening", could you help me with these please
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
248 Views

You can't use the file API to use a SPI master, it uses its own API. Have a look at this document (http://www.altera.com/literature/ug/ug_embedded_ip.pdf), pages 8-8 and over, for more details about the SPI controller API.

0 Kudos
Altera_Forum
Honored Contributor II
248 Views

Hello Daixiwen, thanks for your help, but my SPI module is configurated as slave, how can i test my SPI module if it is a slave??, Could you send me some example code?? thanks in advance, sorry if i am not clear, im an ecuadorian student, i speak spanish but i know some english :-), im doing a SPI analyzer, it is my graduation proyect, and until know i have my machine in qsys, now i want to test my modules created, i´m going to need a uart module, and with a code similar to the code that i told you in the post, i tested it and it worked, but with my spi slave dont :-(, im new in altera forums, help me wwith this pease. thanks again

0 Kudos
Altera_Forum
Honored Contributor II
248 Views

AFAIK altera_avalon_spi can only be a master and can't be configured as a slave. 

Did you read the document I suggested you? It describes the alt_avalon_spi_command() function that you can call to send SPI commands.
0 Kudos
Reply