Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

How to test a SPI module.

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

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    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.