Forum Discussion
Altera_Forum
Honored Contributor
14 years agoSPI Problems
Hi, I'm trying to get handle with the SPI on a Nios II Core but I don't get it. I have a SPI master and a SPI Slave that I can try to transmit some data from the master to the slave. I connecte...
Altera_Forum
Honored Contributor
14 years agoThanks again!
I just tried your code and it is compileable but it doesen't work complitly correct. The Code looks like: --- Quote Start --- int status=0; int countTMT; // select slave (not required in single slave system) IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(SPI_MASTER_BASE, SPI_SLAVE_BASE); // assert CS IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_MASTER_BASE, ALTERA_AVALON_SPI_CONTROL_SSO_MSK); // wait tx channel ready do { status = IORD_ALTERA_AVALON_SPI_STATUS(SPI_MASTER_BASE); } while (((status & ALTERA_AVALON_SPI_STATUS_TRDY_MSK) == 0) && (status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0); // (optional) data possibly to be transmitted back from slave to master upon request IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_SLAVE_BASE, 0x01); // tx data IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_MASTER_BASE, 0x10); // this will initiate the transfer; in the same time the slave sends out on miso pin // the data ready in its tx register // Wait until the interface has finished transmitting do{ status = IORD_ALTERA_AVALON_SPI_STATUS(SPI_MASTER_BASE); IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,countTMT & 0x01); usleep(50000); countTMT++; } while((status & ALTERA_AVALON_SPI_STATUS_TMT_MSK) == 0); // release CS IOWR_ALTERA_AVALON_SPI_CONTROL(SPI_MASTER_BASE, 0); // read received data from slave int data_rx = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_SLAVE_BASE); // data_rx must match data_tx printf("Daten aus dem Slave:%d\n",data_rx); // (optional) read answer from master int recvd_answer = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_MASTER_BASE); // recvd_answer must match data_answer printf("Daten aus dem Master:%d\n",recvd_answer); --- Quote End --- The result is: --- Quote Start --- Daten aus dem Slave:0 Daten aus dem Master:0 --- Quote End --- I don't understand why it doesn't work because it should. Maybe you can help me one more time. Thanks for your helt! Regards