- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi to everyone,
i'm facing a lot of problems during the implementation of a SPI Slave Controller handled by a NIOS II Processor. I'm implementing it on my Altera DE1-Soc Board. Once i've generated my Qsys file with the NIOS II gen2, SPI controller (Frequency 127551Hz, Clock Phase =1 , Clock Polarity =1, Data widths = 8bits and Shift Direction=LSB first), JTAG UART (to monitor which data are obtained from the Microcontroller) and On-Chip Memory, i've assigned the pin on the Expansion Header GPIO_0. Pins selected are : SPI_MISO=PIN_Y18, SPI_MOSI=PIN_Y17, SPI_SCLK=PIN_AK18, SPI_SS_n=PIN_AF20 and for all of them I/O standard = 3.3V LVTTL, current strenght= 16mA. The code that i'm running on the board is the following:# include "io.h"# include "alt_types.h"# include "sys/alt_irq.h"# include "sys/alt_stdio.h"# include <system.h># include <stdio.h># include <unistd.h># include <altera_avalon_pio_regs.h># include "altera_avalon_spi.h"# include "altera_avalon_spi_regs.h"# include <string.h> int main(void) { alt_u32 rddata=0x0; alt_u32 status; IOWR_ALTERA_AVALON_SPI_STATUS(SPI_0_BASE,0x0000); IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_0_BASE,0x1001); alt_printf("TXDATA Initially =%x\n",(IORD(SPI_0_BASE,ALTERA_AVALON_SPI_TXDATA_REG ))); IORD_ALTERA_AVALON_SPI_RXDATA(SPI_0_BASE); alt_printf("RXDATA Initially =%x\n",(IORD(SPI_0_BASE,ALTERA_AVALON_SPI_RXDATA_REG ))); while(1){ alt_printf("inside while 1\n\r"); alt_printf("STATUS =%x\n",(IORD(SPI_0_BASE,ALTERA_AVALON_SPI_STATUS_REG ))); do { status = IORD_ALTERA_AVALON_SPI_STATUS(SPI_0_BASE); } while((status & ALTERA_AVALON_SPI_STATUS_TRDY_MSK)==0 &&(status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0); IOWR_ALTERA_AVALON_SPI_TXDATA(SPI_0_BASE,0xFFFF); rddata= IORD_ALTERA_AVALON_SPI_RXDATA(SPI_0_BASE); alt_printf("read_data =%x\n",rddata); } return 0; } It should receive what is sent from the Microcontroller and store it in the RXDATA, that is accessed and printed, but the RXDATA value doesn't change. Every time that i put the SS_n signal from the microcontroller data is sent and the do-while condition is satisfied by the value in the RXDATA doesn't change. Another weird thing is the value of Status register that remains stuck at 0x310. Following what is printed on the NIOS II Console: TXDATA Initially =0 RXDATA Initially =0 inside while 1 STATUS =310 read_data =0 inside while 1 STATUS =310 read_data =0 inside while 1 STATUS =310 read_data =0 I cannot understand why is behaving like this, i don't know if is a problem of Pin Assignment or C code for Slave. I'm sure that i've set the same clock polarity, phase and frequency also on the Microcontroller (Master). Can anyone help me ? Any ideas or solutions? ThanksLink Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page