Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

SPI Problems

Altera_Forum
Honored Contributor II
4,430 Views

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 connected them with the "loopback board". 

My Code is: 

 

//Write some data to the Slave IOWR_ALTERA_AVALON_SPI_SLAVE_SEL(SPI_SLAVE_BASE,0x04); //Check the TRDY bit if data is written(TRDY=0 means it is writing and //TRDY=1 again means the data was written) trdyNumber=(IORD_ALTERA_AVALON_SPI_STATUS(SPI_SLAVE_BASE)& ALTERA_AVALON_SPI_STATUS_TRDY_MSK)>>6; //Read from the register int data=(IORD_ALTERA_AVALON_SPI_RXDATA(SPI_SLAVE_BASE)&0xFF); printf("%d",data); 

 

I also read the manuel for the SPI Core but it doesn't work. Can somebody help my with an exsample or give me an advice? 

 

Regards
0 Kudos
22 Replies
Altera_Forum
Honored Contributor II
553 Views

 

--- Quote Start ---  

I changed the waiting completion loop like you told me and it doesn't work. I also tried instead to wait on the TRDY-Flag to wait on the RRDY-Flag because how far I understand if the RRDY-Flag is "1" it is possible to read the register. But it also doesn't work.  

I`m also checked the setup in QSYS of the both SPI Cores and till the difference that one is a master and the other one is a slave they have the same setting in relation to the clock polarity and phase. So may I change the setting for the slave or the master? Or what can I do farther? 

 

Thanks in advance for your help! 

--- Quote End ---  

 

Did You find the solution to Your problem?
0 Kudos
Altera_Forum
Honored Contributor II
553 Views

Hi siedler2011, 

I'm facing the same problems that you've already faced. I'm implementing an SPI Slave Controller on my DE1-SOC Altera Board. My master is represented by a Microcontroller that should send data to DE1-SOC board. i'm obtaining the same values that you've obtained for the status register. "Statusregister of the Slave: 0x310".  

I'm using this code to implement the slave SPI Controller on my board: 

int main(void) 

alt_u32 rddata=0x0; 

alt_u32 status; 

IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE,0x0000); 

IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_BASE,0x1001); 

IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE); 

while(1) 

do 

status = IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE); 

while((status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK)==0 && 

(status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0); 

rddata= IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE); 

 

IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_BASE, rddata); 

 

Do you think it could work? I think i ve the same problems that you had with the SS_n signal. Could you help me ? Could you provide me code that you've used on your board set as SLAVE in the communication ?  

 

Thanks
0 Kudos
Reply